output_file_en_us.md 13.6 KB
Newer Older
sfk's avatar
sfk committed
1
## Overview
2

sfk's avatar
sfk committed
3
4
After executing the `magic-pdf` command, in addition to outputting files related to markdown, several other files unrelated to markdown will also be generated. These files will be introduced one by one.

5
### some_pdf_layout.pdf
sfk's avatar
sfk committed
6
7
8
9
10

Each page layout consists of one or more boxes. The number at the top left of each box indicates its sequence number. Additionally, in `layout.pdf`, different content blocks are highlighted with different background colors.

![layout example](images/layout_example.png)

11
### some_pdf_spans.pdf
sfk's avatar
sfk committed
12
13
14
15
16

All spans on the page are drawn with different colored line frames according to the span type. This file can be used for quality control, allowing for quick identification of issues such as missing text or unrecognized inline formulas.

![spans example](images/spans_example.png)

17
### some_pdf_model.json
sfk's avatar
sfk committed
18
19

#### Structure Definition
20

sfk's avatar
sfk committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
```python
from pydantic import BaseModel, Field
from enum import IntEnum

class CategoryType(IntEnum):
     title = 0               # Title
     plain_text = 1          # Text
     abandon = 2             # Includes headers, footers, page numbers, and page annotations
     figure = 3              # Image
     figure_caption = 4      # Image description
     table = 5               # Table
     table_caption = 6       # Table description
     table_footnote = 7      # Table footnote
     isolate_formula = 8     # Block formula
     formula_caption = 9     # Formula label
36

sfk's avatar
sfk committed
37
38
39
     embedding = 13          # Inline formula
     isolated = 14           # Block formula
     text = 15               # OCR recognition result
40
41


sfk's avatar
sfk committed
42
43
44
45
46
47
48
49
50
51
52
class PageInfo(BaseModel):
    page_no: int = Field(description="Page number, the first page is 0", ge=0)
    height: int = Field(description="Page height", gt=0)
    width: int = Field(description="Page width", ge=0)

class ObjectInferenceResult(BaseModel):
    category_id: CategoryType = Field(description="Category", ge=0)
    poly: list[float] = Field(description="Quadrilateral coordinates, representing the coordinates of the top-left, top-right, bottom-right, and bottom-left points respectively")
    score: float = Field(description="Confidence of the inference result")
    latex: str | None = Field(description="LaTeX parsing result", default=None)
    html: str | None = Field(description="HTML parsing result", default=None)
53

sfk's avatar
sfk committed
54
55
56
class PageInferenceResults(BaseModel):
     layout_dets: list[ObjectInferenceResult] = Field(description="Page recognition results", ge=0)
     page_info: PageInfo = Field(description="Page metadata")
57
58


sfk's avatar
sfk committed
59
60
61
62
63
# The inference results of all pages, ordered by page number, are stored in a list as the inference results of MinerU
inference_result: list[PageInferenceResults] = []

```

64
The format of the poly coordinates is \[x0, y0, x1, y1, x2, y2, x3, y3\], representing the coordinates of the top-left, top-right, bottom-right, and bottom-left points respectively.
sfk's avatar
sfk committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
![Poly Coordinate Diagram](images/poly.png)

#### example

```json
[
    {
        "layout_dets": [
            {
                "category_id": 2,
                "poly": [
                    99.1906967163086,
                    100.3119125366211,
                    730.3707885742188,
                    100.3119125366211,
                    730.3707885742188,
                    245.81326293945312,
                    99.1906967163086,
                    245.81326293945312
                ],
                "score": 0.9999997615814209
            }
        ],
        "page_info": {
            "page_no": 0,
            "height": 2339,
            "width": 1654
        }
    },
    {
        "layout_dets": [
            {
                "category_id": 5,
                "poly": [
                    99.13092803955078,
                    2210.680419921875,
                    497.3183898925781,
                    2210.680419921875,
                    497.3183898925781,
                    2264.78076171875,
                    99.13092803955078,
                    2264.78076171875
                ],
                "score": 0.9999997019767761
            }
        ],
        "page_info": {
            "page_no": 1,
            "height": 2339,
            "width": 1654
        }
    }
]
```

120
### some_pdf_middle.json
sfk's avatar
sfk committed
121

122
123
124
125
126
| Field Name     | Description                                                                                                    |
| :------------- | :------------------------------------------------------------------------------------------------------------- |
| pdf_info       | list, each element is a dict representing the parsing result of each PDF page, see the table below for details |
| \_parse_type   | ocr \| txt, used to indicate the mode used in this intermediate parsing state                                  |
| \_version_name | string, indicates the version of magic-pdf used in this parsing                                                |
sfk's avatar
sfk committed
127
128
129
130
131
132
133

<br>

**pdf_info**

Field structure description

134
135
136
137
138
139
140
141
142
143
144
145
| Field Name          | Description                                                                                                        |
| :------------------ | :----------------------------------------------------------------------------------------------------------------- |
| preproc_blocks      | Intermediate result after PDF preprocessing, not yet segmented                                                     |
| layout_bboxes       | Layout segmentation results, containing layout direction (vertical, horizontal), and bbox, sorted by reading order |
| page_idx            | Page number, starting from 0                                                                                       |
| page_size           | Page width and height                                                                                              |
| \_layout_tree       | Layout tree structure                                                                                              |
| images              | list, each element is a dict representing an img_block                                                             |
| tables              | list, each element is a dict representing a table_block                                                            |
| interline_equations | list, each element is a dict representing an interline_equation_block                                              |
| discarded_blocks    | List, block information returned by the model that needs to be dropped                                             |
| para_blocks         | Result after segmenting preproc_blocks                                                                             |
sfk's avatar
sfk committed
146
147
148
149
150
151
152
153
154

In the above table, `para_blocks` is an array of dicts, each dict representing a block structure. A block can support up to one level of nesting.

<br>

**block**

The outer block is referred to as a first-level block, and the fields in the first-level block include:

155
156
157
158
159
| Field Name | Description                                                    |
| :--------- | :------------------------------------------------------------- |
| type       | Block type (table\|image)                                      |
| bbox       | Block bounding box coordinates                                 |
| blocks     | list, each element is a dict representing a second-level block |
sfk's avatar
sfk committed
160
161
162
163
164
165

<br>
There are only two types of first-level blocks: "table" and "image". All other blocks are second-level blocks.

The fields in a second-level block include:

166
167
168
169
170
| Field Name | Description                                                                                                 |
| :--------- | :---------------------------------------------------------------------------------------------------------- |
| type       | Block type                                                                                                  |
| bbox       | Block bounding box coordinates                                                                              |
| lines      | list, each element is a dict representing a line, used to describe the composition of a line of information |
sfk's avatar
sfk committed
171
172
173

Detailed explanation of second-level block types

174
175
| type               | Description            |
| :----------------- | :--------------------- |
sfk's avatar
sfk committed
176
177
| image_body         | Main body of the image |
| image_caption      | Image description text |
178
| image_footnote     | Image footnote         |
sfk's avatar
sfk committed
179
180
| table_body         | Main body of the table |
| table_caption      | Table description text |
181
182
183
| table_footnote     | Table footnote         |
| text               | Text block             |
| title              | Title block            |
184
185
| index              | Index block            |
| list               | List block             |
186
| interline_equation | Block formula          |
sfk's avatar
sfk committed
187
188
189
190
191
192
193

<br>

**line**

The field format of a line is as follows:

194
195
196
197
| Field Name | Description                                                                                             |
| :--------- | :------------------------------------------------------------------------------------------------------ |
| bbox       | Bounding box coordinates of the line                                                                    |
| spans      | list, each element is a dict representing a span, used to describe the composition of the smallest unit |
sfk's avatar
sfk committed
198
199
200
201
202

<br>

**span**

203
204
205
206
| Field Name          | Description                                                                                              |
| :------------------ | :------------------------------------------------------------------------------------------------------- |
| bbox                | Bounding box coordinates of the span                                                                     |
| type                | Type of the span                                                                                         |
sfk's avatar
sfk committed
207
208
209
210
| content \| img_path | Text spans use content, chart spans use img_path to store the actual text or screenshot path information |

The types of spans are as follows:

211
212
213
214
215
216
217
| type               | Description    |
| :----------------- | :------------- |
| image              | Image          |
| table              | Table          |
| text               | Text           |
| inline_equation    | Inline formula |
| interline_equation | Block formula  |
sfk's avatar
sfk committed
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

**Summary**

A span is the smallest storage unit for all elements.

The elements stored within para_blocks are block information.

The block structure is as follows:

First-level block (if any) -> Second-level block -> Line -> Span

#### example

```json
{
    "pdf_info": [
        {
            "preproc_blocks": [
                {
                    "type": "text",
                    "bbox": [
                        52,
                        61.956024169921875,
                        294,
                        82.99800872802734
                    ],
                    "lines": [
                        {
                            "bbox": [
                                52,
                                61.956024169921875,
                                294,
                                72.0000228881836
                            ],
                            "spans": [
                                {
                                    "bbox": [
                                        54.0,
                                        61.956024169921875,
                                        296.2261657714844,
                                        72.0000228881836
                                    ],
                                    "content": "dependent on the service headway and the reliability of the departure ",
                                    "type": "text",
                                    "score": 1.0
                                }
                            ]
                        }
                    ]
                }
            ],
            "layout_bboxes": [
                {
                    "layout_bbox": [
                        52,
                        61,
                        294,
                        731
                    ],
                    "layout_label": "V",
                    "sub_layout": []
                }
            ],
            "page_idx": 0,
            "page_size": [
                612.0,
                792.0
            ],
            "_layout_tree": [],
            "images": [],
            "tables": [],
            "interline_equations": [],
            "discarded_blocks": [],
            "para_blocks": [
                {
                    "type": "text",
                    "bbox": [
                        52,
                        61.956024169921875,
                        294,
                        82.99800872802734
                    ],
                    "lines": [
                        {
                            "bbox": [
                                52,
                                61.956024169921875,
                                294,
                                72.0000228881836
                            ],
                            "spans": [
                                {
                                    "bbox": [
                                        54.0,
                                        61.956024169921875,
                                        296.2261657714844,
                                        72.0000228881836
                                    ],
                                    "content": "dependent on the service headway and the reliability of the departure ",
                                    "type": "text",
                                    "score": 1.0
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    "_parse_type": "txt",
    "_version_name": "0.6.1"
}
```