跪拜 Guibai
← Back to the summary

OXR Turns Any PDF into Agent-Ready Markdown, and Its Layout Model Is Swappable

01 Introduction

OCR recognition is widely known, usually referring to general text recognition. OXR is different: OCR is just one subtask inside the OXR pipeline.

Recently I came across an OXR product: a SOTA document parsing model open-sourced by the SoMark team, with 1.3B parameters. It parses PDFs and document images into Agent-Friendly data (Markdown / JSON) and also provides layout analysis results.

02 Overview

OXR stands for Optical Everything Recognition. It is a document parsing model open-sourced by the SoMark team.

OXR was pretrained from scratch, and in the post-training phase it introduced, for the first time, a recursive self-improvement (RSI) training paradigm aimed at document parsing. In global benchmarks across OmniDocBench, olmOCR-Bench, and DocParsingBench, OXR ranks first in all three, while its parsing speed also leads the industry.

In architecture design, OXR is the first to make the layout analysis module independent and pluggable. While improving parsing efficiency, it also makes business adaptation more flexible. Users can replace the built-in layout analysis model with their own model according to their business requirements for document structure, achieving multi-scenario adaptation at minimal cost.

Core advantages:

GitHub address: https://github.com/SoMarkAI/OXR

Online demo: https://free-oxr.somark.ai

China mirror: https://free-oxr.somark.cn

Documentation: https://docs.somark.cn/documentation

03 Installation and Deployment

3.1 Free API

OXR provides a free API — no registration or API key required — to test the parsing effect with your own documents. The official statement says the free API service will be continuously provided until the server can no longer handle the load.

Addresses:

API endpoint: https://free-oxr.somark.ai/api/v1

Integration docs: https://docs.somark.ai/api-reference

China mirror:

API endpoint: https://free-oxr.somark.cn/api/v1

Integration docs: https://docs.somark.cn/api-reference

3.2 Local Deployment

Environment requirements:

See the reference docs: https://github.com/SoMarkAI/OXR/blob/main/README_CN.md

04 Quick Test

You can try it by using the official example and the free API.

4.1 Online Demo

Demo address: https://free-oxr.somark.cn/

Just upload a file.

Let's parse a PDF with a table. Source file:

Result from ordinary OCR:

OXR's result:

The results are different — OXR preserves the original structure and can also export a markdown file.

4.2 Calling the Free API via HTTP

class OxrTest {

    /** Path to the file to parse */
    private static final String FILE_PATH = "C:\\Users\\user.name\\Desktop\\加班申请单(修正版).pdf";

    /** OXR synchronous parse endpoint */
    private static final String PARSE_SYNC_URL = "https://free-oxr.somark.cn/api/v1/parse/sync";

    @Test
    void test01() throws Exception {
        File file = new File(FILE_PATH);
        if (!file.exists()) {
            throw new IllegalStateException("File not found: " + FILE_PATH);
        }

        // multipart form body: file + output_formats (markdown and json)
        MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
        form.add("file", new FileSystemResource(file));
        form.add("output_formats", "markdown");
        form.add("output_formats", "json");

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);

        RestTemplate restTemplate = new RestTemplate();
        String responseBody = restTemplate.postForObject(
                PARSE_SYNC_URL,
                new HttpEntity<>(form, headers),
                String.class
        );

        ObjectMapper mapper = new ObjectMapper();
        JsonNode root = mapper.readTree(responseBody);

        // Even with HTTP 200, must check whether business code is 0
        int code = root.path("code").asInt(-1);
        if (code != 0) {
            throw new IllegalStateException("Parse failed, code=" + code
                    + ", message=" + root.path("message").asText());
        }

        JsonNode data = root.path("data");
        JsonNode result = data.path("result");
        if (result.isMissingNode() || result.isNull()) {
            throw new IllegalStateException("Parse returned error: " + data.path("error").asText());
        }

        System.out.println("========== Metadata ==========");
        System.out.println("File name: " + result.path("file_name").asText());
        System.out.println("Page count: " + data.path("metadata").path("page_num").asInt());
        System.out.println("Processing time (ms): " + data.path("metadata").path("processing_time_ms").asLong());

        // Read the Markdown result
        String markdown = result.path("outputs").path("markdown").asText();
        System.out.println("========== Markdown result ==========");
        System.out.println(markdown);

        // Read the JSON result (per-page block information)
        System.out.println("========== JSON result ==========");
        JsonNode jsonOutput = result.path("outputs").path("json");
        System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonOutput));

        // Save the Markdown result locally
        Path output = Paths.get("oxr-parse-result.md");
        Files.write(output, markdown.getBytes(StandardCharsets.UTF_8));
        System.out.println("Markdown result saved to: " + output.toAbsolutePath());
    }
}

Metadata:

Markdown result:

JSON result:

Generated markdown:

05 Summary

OXR is not ordinary text recognition; it preserves a certain amount of formatting. It could be the next-generation OCR. This is quite beneficial for structured recognition. If you have the resources, you can deploy your own instance and try it out!

Comments

Top 2 of 3 from juejin.cn, machine-translated. The original thread is authoritative.

Percy_kk

What's the difference between the MinerU project and the OXR mentioned in the article?

SimonKing

They're about the same in effect, but MinerU has more powerful functionality.

赶时间理解下

OCR also stands for Open Code Review 😛