PDF text extraction method and system based on row density

Through the PDF text extraction method based on line density, complex layout PDF documents are chunked and integrated, and the DOM tree is constructed for text extraction, solving the problems of low accuracy and high computing resources in the existing technology, and achieving efficient and accurate PDF text extraction.

CN119693966APending Publication Date: 2025-03-25中孚安全技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411673927.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-21
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

When processing PDF documents with complex layouts, the accuracy of the position coordinates and rules is low, and the deep learning method requires a large amount of training data and computing resources. The hybrid method and user interaction method have poor adaptability and require manual participation.

Method used

The PDF text extraction method based on line density is adopted. By chunking the PDF document page, the text in adjacent chunks is integrated based on text line density and font features, and a DOM tree is constructed for text extraction.

Benefits of technology

It improves the accuracy of PDF layout information extraction, simulates human visual effects, has small calculation volume, is suitable for large-scale data processing, is simple to operate, and is suitable for fast and accurate extraction of complex layout PDF text under low computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119693966A_ABST
    Figure CN119693966A_ABST
Patent Text Reader

Abstract

The invention provides a PDF (Portable Document Format) text extraction method and system based on row density, and the scheme comprises the following steps: traversing rectangular block regions in a PDF document according to a page sequence, and obtaining coordinates and included character information of each rectangular block region; on the basis of the character information in the rectangular block region, integrating characters in the same row to obtain row information, and performing density calculation on the basis of the row information; based on the row information in the same page, constructing a text basic feature of the current page; determining current page information based on the text basic features; based on the current page information, merging the rectangular block areas of the current page, and constructing a tree structure by taking the merged rectangular block areas as nodes; and performing text extraction on the rectangular block region corresponding to each node in sequence by traversing the tree structure in advance to obtain a PDF text extraction result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of content extraction, and in particular relates to a PDF text extraction method and system based on line density. Background Art

[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.

[0003] PDF (Portable Document Format) is a widely used file format that maintains the original appearance of a document, regardless of the operating system, software, or hardware. PDF files can contain various components, such as images, text, links, tables, etc., which can provide rich information and functionality. PDF does not represent text as lines or words, but as individual characters drawn at specific locations on the page. The end effect is to create words, lines, and paragraphs that are easy for the human eye to understand. The PDF format is not designed to directly provide information about the order and structure of the text. Therefore, text order and paragraph recovery after PDF text recognition and extraction is a challenging task.

[0004] At present, the solutions for restoring the order and paragraph structure of PDF text mainly include: methods based on position coordinates and rules, which are suitable for documents with simple structures but have low accuracy for documents with complex layouts; deep learning and NLP technology, which are suitable for processing documents with complex layouts but require a large amount of annotated data and computing resources; hybrid methods and user interaction provide flexible solutions, but require higher implementation complexity, computing resources and manual participation, and are not suitable for large-scale processing. Among them, hybrid methods need to comprehensively consider the advantages and disadvantages of different methods, and the implementation and debugging process is relatively complicated; user interaction methods require user participation and are not suitable for large-scale processing. Summary of the invention

[0005] The embodiments of the present invention provide a PDF text extraction method and system based on line density to solve the problems that the location coordinate and rule-based methods have low accuracy for complex layout documents, the deep learning-based methods require a large amount of training data and high computing resource requirements, and the hybrid method and user interaction method have poor adaptability and require manual participation.

[0006] In order to achieve the above object, the present invention is implemented through the following technical solutions:

[0007] In a first aspect, the present invention provides a PDF text extraction method based on line density, comprising:

[0008] Traverse the rectangular block areas in the PDF document in page order to obtain the coordinates of each rectangular block area and the character information included;

[0009] Based on the character information in the rectangular block area, integrating characters in the same row to obtain row information, and performing density calculation based on the row information;

[0010] Based on the line information in the same page, construct the basic features of the text of the current page;

[0011] Based on the basic features of the text, determine the current page information;

[0012] Based on the current page information, the rectangular block areas of the current page are merged, and the merged rectangular block areas are used as nodes to construct a tree structure;

[0013] By traversing the tree structure in pre-order, text extraction is performed on the rectangular block area corresponding to each node in sequence to obtain the PDF text extraction result.

[0014] Furthermore, based on the character information in the rectangular block area, the characters in the same row are integrated to obtain the row information. Specifically, according to the coordinates, character width and height information of the characters in the rectangular block area, for all the characters in the rectangular block area, the characters with the same vertical coordinates and adjacent horizontal coordinates are integrated into a row, and the rectangular coordinates of the current row are calculated.

[0015] Furthermore, the density calculation based on the row information is specifically: based on the rectangular coordinates of each row, the coordinates of the current rectangular block area, the total number of characters in each row and the total number of characters in the current rectangular block area, the average row density, block density and row spacing are calculated respectively.

[0016] Furthermore, based on the line information in the same page, the basic features of the text of the current page are constructed; based on the basic features of the text, the current page information is determined; specifically: based on the line information of each rectangular block area in the same page, the font, size and line height features of the line with the largest number are used as the basic features of the text; all lines that meet the basic features of the text in the current page are traversed to obtain the average character width and total number of characters of the text, and, based on the vertical coordinates and horizontal coordinates of all lines that meet the basic features of the text in the current page, the page boundary is determined.

[0017] Furthermore, the merging of rectangular block areas of the current page based on the current page information is specifically as follows: sorting is performed based on the coordinates of the rectangular block areas in the current page, and the vertically adjacent rectangular block areas are preliminarily vertically merged according to a first merging condition to obtain a preliminarily vertically merged rectangular block area; based on the obtained preliminarily merged rectangular block area, the vertically adjacent rectangular block areas are secondarily vertically merged according to a second merging condition to obtain a rectangular block area after the second vertical merger; based on the rectangular block area after the second merger, the horizontally adjacent rectangular block areas are horizontally merged according to a third merging condition to obtain a merged rectangular block area.

[0018] Furthermore, the tree structure is constructed using the merged rectangular block areas as nodes, specifically by sorting the merged rectangular block areas and constructing a DOM tree based on the coordinate relationship of the rectangular block areas.

[0019] In a second aspect, the present invention provides a PDF text extraction system based on line density, comprising:

[0020] A data acquisition unit, which is used to traverse the rectangular block areas in the PDF document in page order and obtain the coordinates of each rectangular block area and the character information included;

[0021] A row information acquisition and density calculation unit integrates characters in the same row to obtain row information based on character information in the rectangular block area, and performs density calculation based on the row information;

[0022] A basic feature acquisition unit, which is used to construct the basic features of the text of the current page based on the line information in the same page;

[0023] A page information acquisition unit, which is used to determine the current page information based on the basic features of the text;

[0024] A block merging and tree building unit, which is used to merge the rectangular block areas of the current page based on the current page information, and use the merged rectangular block areas as nodes to build a tree structure;

[0025] The PDF text extraction unit is used to extract text from the rectangular block area corresponding to each node in sequence by traversing the tree structure in pre-order to obtain the PDF text extraction result.

[0026] In a third aspect, the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored and running on the memory, wherein the processor implements the PDF text extraction method based on line density when executing the program.

[0027] In a fourth aspect, the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the PDF text extraction method based on line density.

[0028] In a fifth aspect, the present invention provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the PDF text extraction method based on line density.

[0029] Compared with the prior art, the present invention has the following beneficial effects:

[0030] (1) The present invention provides a PDF text extraction method and system based on line density. The scheme divides the PDF document page into blocks, and integrates the texts of adjacent blocks based on text line density, font, font size and coordinate features. By introducing text line density, adjacent texts (including up and down, left and right directions) can be effectively associated, thereby improving the accuracy of PDF layout information extraction. At the same time, a DOM tree is constructed with the integrated blocks as nodes, and text extraction is performed based on the sequence of nodes in the DOM tree. This can simulate human visual effects to a certain extent, has a small amount of calculation, and effectively improves the efficiency of text extraction.

[0031] (2) The solution described in the present invention adopts an unsupervised approach, does not require human intervention, and is suitable for large-scale data processing.

[0032] (3) The scheme of the present invention is simple to operate, has low requirements on computing resources, and can realize fast and accurate extraction of PDF with complex layout under low computing resource conditions.

[0033] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0035] Figure 1 The present invention is a flowchart of a PDF text extraction method based on line density described in an embodiment of the present invention. DETAILED DESCRIPTION

[0036] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0037] It should be noted that the following detailed descriptions are all illustrative and intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0038] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0039] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.

[0040] like Figure 1 As shown, the purpose of this embodiment is to provide a PDF text extraction method based on line density, which specifically includes the following processing procedures:

[0041] Step 1: Traverse the rectangular block areas in the PDF document in page order to obtain the coordinates of each rectangular block area and the character information included;

[0042] Specifically, using PDF general tools, all rectangular block areas (denoted as: R) in the PDF document page are traversed in page order, and the coordinates of the rectangular block areas are extracted. And extract all character Unicode, X coordinate, Y coordinate, height, width, x scale value, y scale value, font size and other information, and store them by page and rectangular block number. The character coordinates are marked as: Line height H c , width W c , font F c , font size Fs c .

[0043] It should be noted here that when a PDF document is constructed, it is composed of rectangular blocks. The information of all rectangular blocks, including the coordinates of the rectangular blocks and the internal character information, can be obtained through general tools. Among them, the general tools that can be used include pdfbox, pypdf2, pdfminer, etc.

[0044] Step 2: Based on the character information in the rectangular block area, integrate the characters in the same row to obtain row information, and perform density calculation based on the row information;

[0045] In a specific implementation, based on the character information in the rectangular block area, the characters in the same row are integrated to obtain the row information. Specifically, according to the coordinates, character width and height information of the characters in the rectangular block area, for all the characters in the rectangular block area, the characters with the same vertical coordinates and adjacent horizontal coordinates are integrated into a row, and the rectangular coordinates of the current row are calculated.

[0046] In a specific implementation, the density calculation based on row information is specifically: based on the rectangular coordinates of each row, the coordinates of the current rectangular block area, the total number of characters in each row and the total number of characters in the current rectangular block area, the average row density, block density and row spacing are calculated respectively.

[0047] Specifically, step 2 specifically includes the following processing steps:

[0048] According to the page and R numbering sequence, and based on the character coordinates, character width, and height information, all characters in R are restored to a row, and characters with the same Y coordinate and adjacent X coordinates are integrated into a row, and the rectangular coordinates of the row are calculated. At the same time, the total number of characters in the statistics line Line height H L , main font F L , main font size Fl R , and the main row height H of block R R , main font F R , main font size Fs R ,Total number of characters Number of rows num , row spacing L gap .

[0049] At the same time, the average row density, block density, and row spacing are calculated:

[0050]

[0051] Step 3: Based on the row information in the same page, construct the basic features of the text of the current page; based on the basic features of the text, determine the current page information;

[0052] In a specific implementation, based on the line information in the same page, the basic features of the text of the current page are constructed; based on the basic features of the text, the current page information is determined; specifically: based on the line information of each rectangular block area in the same page, the font, size and line height features of the largest number of lines are used as the basic features of the text; all lines that meet the basic features of the text in the current page are traversed to obtain the average character width and total number of characters of the text, and, based on the vertical coordinates and horizontal coordinates of all lines that meet the basic features of the text in the current page, the page boundary is determined.

[0053] Specifically, step 3 includes the following processing steps:

[0054] First, based on the line information (font, size, line height, rectangle coordinates) in step 2, count and aggregate the number of lines with the same font, size, and line height features, and use the font, size, and line height features of the largest number of lines as the basic features of the text content. Second, traverse all lines that meet the basic features of the text, and count the average character width and the total number of characters in the text. Third, calculate the Y values ​​of all lines that meet the basic features of the text on each page in page order. 0 Coordinate, after aggregation Y 0 The number of max = count(Y 0 ) is the maximum number of rows in a single column that can exist vertically on the page, and the maximum number of rows in a single column in the document: Then, count and aggregate the left and right horizontal coordinates X of the lines that meet the text characteristics 0 , X 1 , and traverse them in ascending and descending order respectively. The left and right boundaries of the page are:

[0055]

[0056] Step 4: Based on the current page information, the rectangular block areas of the current page are merged, and the merged rectangular block areas are used as nodes to construct a tree structure;

[0057] In a specific implementation, the merging of the rectangular block areas of the current page based on the current page information is specifically as follows: sorting is performed based on the coordinates of the rectangular block areas in the current page, and the vertically adjacent rectangular block areas are preliminarily vertically merged according to a first merging condition to obtain a preliminarily vertically merged rectangular block area; based on the obtained preliminarily merged rectangular block area, the vertically adjacent rectangular block areas are secondarily vertically merged according to a second merging condition to obtain a rectangular block area after the second vertical merger; based on the rectangular block area after the second merger, the horizontally adjacent rectangular block areas are horizontally merged according to a third merging condition to obtain a merged rectangular block area.

[0058] In a specific implementation, the tree structure is constructed using the merged rectangular block areas as nodes, specifically by sorting the merged rectangular block areas and constructing a DOM tree based on the coordinate relationship of the rectangular block areas.

[0059] Specifically, step 4 includes the following processing steps:

[0060] First, the border interval [border l , border r ] basic blocks outside are culled.

[0061] Next, block merging is performed. The specific steps are as follows:

[0062] Using coordinates Press R for all blocks Sort in double ascending order, that is, first sort by Sorting, if same, The smaller one comes first, generating an ordered list

[0063] (1) Sequential traversal of the list The vertically adjacent blocks are preliminarily merged to form a new block.

[0064] The merging conditions are:

[0065] 1) Adjacent block R i ,R i+1 The average row density of is within a small range, that is,

[0066] 2) If R i ,R i+1 If they are all multiple lines, their line spacing should be within a small difference range, that is,

[0067] 3) If R i ,R i+1 If there is a single line between them, they should have the same main font, font size, and line height.

[0068] 4) R i ,R i+1 The interval of the horizontal axis is aligned, that is, or,

[0069] 5) R i ,R i+1 The vertical spacing satisfies:

[0070] After merging, a new block is generated And calculate its principal mean density d R 、Main row height H R , main font F R , main font size Fs R ,Total number of characters Number of rows num , row spacing L gap , sub-block spacing R gap ,, Maximum sub-block density At the same time, the blocks that have been merged are removed from the list Move to a list Add to list middle.

[0071] according to Perform a double ascending sort and merge into In, clear

[0072] (2) Further vertical block alignment, sequentially traversing the list Merge the vertically adjacent blocks to form a new block. The merging conditions are:

[0073] 1) R i ,R i+1 The interval of the horizontal axis is aligned, that is, and,

[0074] 2) R i ,R i+1 The vertical spacing satisfies:

[0075] After merging, a new block is generated And calculate its principal mean density d R 、Main row height H R , main font F R , main font size Fs R ,Total number of characters Number of rows num , row spacing L gap , sub-block spacing R gap ,, Maximum sub-block density Maximum sub-block average row density At the same time, the blocks that have been merged are removed from the list Move to a list Add to list middle.

[0076] according to Perform a double ascending sort and merge into In, clear

[0077] At this point, the basic column alignment is completed.

[0078] (3) Sequential traversal of the list Merge horizontally adjacent blocks to form a new block. The merging conditions are:

[0079] 1) Adjacent block R i ,R i+1The average row density of is within a small range, that is, Note that the composite block uses the maximum sub-block row density Perform calculations;

[0080] 2) If R i ,R i+1 If they are all multiple lines, their line spacing should be within a small difference range, that is,

[0081] 3) If R i ,R i+1 If there are non-composite blocks, they must have the same main font, main font size, and main line height.

[0082] 4) If R i ,R i+1 are all synthetic blocks, then their block spacing should be within a small difference range, that is,

[0083] a) R i ,R i+1 The horizontal spacing satisfies,

[0084] b) R i ,R i+1 The vertical coordinates of all rows in The overlap is greater than 0.5;

[0085] c) R i ,R i+1 The interval of the horizontal axis is aligned, that is,

[0086] After merging, a new block is generated And calculate its principal average density d R 、Main row height H R , main font F R , main font size Fs R ,Total number of characters Number of rows num , row spacing L gap , sub-block spacing R gap ,, Maximum sub-block density Maximum sub-block average row density At the same time, the blocks that have been merged are removed from the list Move to a list Add to list and will Move the composite block in

[0087] (4) The synthesis block in Double ascending sorting with priority Sorting, building the DOM tree according to the coordinate relationship, node construction, and insertion rules:

[0088] 1) Build a node

[0089] First, you need to build an empty node DOM tree node (node), and then write the coordinate information and index of the "block" into the node.

[0090] 2) If the node to be inserted has no overlap with the current node's ordinate, and the abscissa interval contains and is contained as a child node, start from the current node and modify the node abscissa interval upwards in sequence to ensure that the parent node's abscissa interval covers all child nodes' abscissa intervals.

[0091] 3) If the node to be inserted has an overlapped ordinate with the current node, and the abscissa interval is not covered by the abscissa interval of the current node, it is inserted as a sibling node of the current node. Similarly, the abscissa intervals of the nodes are modified in sequence starting from the parent node of the current node to ensure that the abscissa interval of the parent node covers the abscissa intervals of all child nodes.

[0092] 4) If the vertical coordinates of the node to be inserted overlap with the current node, and the horizontal coordinate interval is covered by the horizontal coordinate interval of the current node, merge the blocks of the current node and the inserted node to generate a new block

[0093] (5) The basic block for block merging is inserted into the DOM tree according to the coordinate relationship and the above node construction and insertion rules.

[0094] At this point, the block layout DOM tree is constructed.

[0095] Step 5: By traversing the tree structure in pre-order, text is extracted from the rectangular block area corresponding to each node in sequence to obtain the PDF text extraction result.

[0096] In one or more implementations, corresponding to the above-mentioned PDF text extraction method based on line density, this embodiment provides a PDF text extraction system based on line density, including:

[0097] A data acquisition unit, which is used to traverse the rectangular block areas in the PDF document in page order and obtain the coordinates of each rectangular block area and the character information included;

[0098] A row information acquisition and density calculation unit integrates characters in the same row to obtain row information based on character information in the rectangular block area, and performs density calculation based on the row information;

[0099] A basic feature acquisition unit, which is used to construct the basic features of the text of the current page based on the line information in the same page;

[0100] A page information acquisition unit, which is used to determine the current page information based on the basic features of the text;

[0101] A block merging and tree building unit, which is used to merge the rectangular block areas of the current page based on the current page information, and use the merged rectangular block areas as nodes to build a tree structure;

[0102] The PDF text extraction unit is used to extract text from the rectangular block area corresponding to each node in sequence by traversing the tree structure in pre-order to obtain the PDF text extraction result.

[0103] Furthermore, the system described in this embodiment corresponds to the method described in Example 1, and its technical details are described in detail in Example 1, so they are not repeated here.

[0104] In further embodiments, there is also provided:

[0105] An electronic device includes a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method described in Embodiment 1 is performed. For the sake of brevity, no further description is given here.

[0106] It should be understood that in this embodiment, the processor may be a central processing unit CPU, and the processor may also be other general-purpose processors, digital signal processors DSP, application-specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0107] The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.

[0108] A computer-readable storage medium is used to store computer instructions. When the computer instructions are executed by a processor, the method described in embodiment 1 is completed.

[0109] The method in the first embodiment can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware. To avoid repetition, it is not described in detail here.

[0110] Those skilled in the art will appreciate that the units, i.e., algorithm steps, of the various examples described in the present embodiment can be implemented in electronic hardware or in a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0111] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A PDF text extraction method based on line density, characterized in that: include: Traverse the rectangular block areas in the PDF document in page order to obtain the coordinates of each rectangular block area and the character information included; Based on the character information in the rectangular block area, integrating characters in the same row to obtain row information, and performing density calculation based on the row information; Based on the line information in the same page, construct the basic features of the text of the current page; Based on the basic features of the text, determine the current page information; Based on the current page information, the rectangular block areas of the current page are merged, and the merged rectangular block areas are used as nodes to construct a tree structure; By traversing the tree structure in pre-order, text extraction is performed on the rectangular block area corresponding to each node in sequence to obtain the PDF text extraction result.

2. A PDF text extraction method based on line density as claimed in claim 1, characterized in that: Based on the character information in the rectangular block area, the characters in the same row are integrated to obtain the row information. Specifically, according to the coordinates, character width and height information of the characters in the rectangular block area, for all the characters in the rectangular block area, the characters with the same vertical coordinates and adjacent horizontal coordinates are integrated into a row, and the rectangular coordinates of the current row are calculated.

3. A PDF text extraction method based on line density as claimed in claim 1, characterized in that: The density calculation based on the row information is specifically: based on the rectangular coordinates of each row, the coordinates of the current rectangular block area, the total number of characters in each row and the total number of characters in the current rectangular block area, the average row density, block density and row spacing are calculated respectively.

4. The PDF text extraction method based on line density as claimed in claim 1, characterized in that: The basic features of the text of the current page are constructed based on the row information in the same page; Based on the basic features of the text, determine the current page information; Specifically: based on the line information of each rectangular block area in the same page, the font, size and line height features of the line with the largest number are used as the basic features of the text; all lines that meet the basic features of the text in the current page are traversed to obtain the average character width and total number of characters of the text, and based on the vertical and horizontal coordinates of all lines that meet the basic features of the text in the current page, the page boundary is determined.

5. The PDF text extraction method based on line density as claimed in claim 1, characterized in that: The merging of the rectangular block areas of the current page based on the current page information is specifically: sorting based on the coordinates of the rectangular block areas in the current page, and preliminarily merging the vertically adjacent rectangular block areas according to the first merging condition to obtain preliminarily vertically merged rectangular block areas; Based on the obtained initially merged rectangular block area, vertically adjacent rectangular block areas are vertically merged for a second time according to a second merging condition to obtain a rectangular block area after the second vertical merger; Based on the rectangular block area after the secondary merger, according to the third merger condition, the horizontally adjacent rectangular block areas are horizontally merged to obtain a merged rectangular block area.

6. A PDF text extraction method based on line density as claimed in claim 1, characterized in that: The tree structure is constructed by taking the merged rectangular block areas as nodes, specifically, the merged rectangular block areas are sorted, and the DOM tree is constructed based on the coordinate relationship of the rectangular block areas.

7. A PDF text extraction system based on line density, characterized in that: include: A data acquisition unit, which is used to traverse the rectangular block areas in the PDF document in page order and obtain the coordinates of each rectangular block area and the character information included; A row information acquisition and density calculation unit integrates characters in the same row to obtain row information based on character information in the rectangular block area, and performs density calculation based on the row information; A basic feature acquisition unit, which is used to construct the basic features of the text of the current page based on the line information in the same page; A page information acquisition unit, which is used to determine the current page information based on the basic features of the text; A block merging and tree building unit, which is used to merge the rectangular block areas of the current page based on the current page information, and use the merged rectangular block areas as nodes to build a tree structure; The PDF text extraction unit is used to extract text from the rectangular block area corresponding to each node in sequence by traversing the tree structure in pre-order to obtain the PDF text extraction result.

8. An electronic device comprising a memory, a processor and a computer program stored and running on the memory, characterized in that: When the processor executes the program, a PDF text extraction method based on line density as described in any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, a PDF text extraction method based on line density as described in any one of claims 1 to 6 is implemented.

10. A computer program product, comprising a computer program, characterized in that: When the computer program is executed by a processor, the method for extracting PDF text based on line density according to any one of claims 1 to 6 is implemented.