PDF text extraction method and system based on large language model

Through a PDF text extraction method based on a large language model, using PyMuPDF and a multi-dimensional recognition strategy, we identify and eliminate noise interference in PDF documents, formulate a multi-level text logic reconstruction strategy, solve the semantic reconstruction problem of mixed text and image PDF documents, and achieve high-quality structured data output.

CN120599643AActive Publication Date: 2025-09-05NANJING WEISHIDE SOFTWARE CO LTD

Patent Information

Application Number
CN202511115421.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-11
Publication Date
2025-09-05
Estimated Expiration
2045-08-11

AI Technical Summary

Technical Problem

When processing PDF documents containing mixed text and images, existing technologies have difficulty in accurately understanding and reconstructing the original semantic order, resulting in confusing text extraction results and unable to meet the high-quality corpus input requirements of large language models.

Method used

A PDF text extraction method based on a large language model is adopted. PyMuPDF is used to parse PDF documents, identify image and text areas, apply a multi-dimensional recognition strategy to eliminate noise interference features, formulate a multi-level text logic reconstruction strategy, and combine the large language model to perform semantic structure correction, and finally output in a structured format.

Benefits of technology

It effectively solves the problems of image and text misalignment, structural chaos, and noise interference, restores the logical order and semantic integrity of the document, provides high-quality structured data, and supports subsequent knowledge extraction and intelligent question-and-answer applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120599643A_ABST
    Figure CN120599643A_ABST
Patent Text Reader

Abstract

The invention relates to the field of document processing and data extraction, and particularly discloses a PDF text extraction method and system based on a large language model.The method includes the steps that content of all pages of a target PDF document is positioned and marked to obtain a first to-be-recognized area and a second to-be-recognized area, and noise interference features of the to-be-recognized areas are removed; formulating a multi-level text logic reconstruction strategy to complete reconstruction of a logic sequence of the target PDF document, preliminarily outputting a first-level PDF document, and performing primary image-text association degree analysis to output first association strength; performing intelligent anomaly recognition and correction on the content of the first-level PDF document on a semantic structure through a large language model to obtain a second-level PDF document, and outputting second association strength; judging whether the secondary PDF document is qualified or not based on the first association strength and the second association strength; according to the method, the logic sequence and the semantic integrity of the document can be recovered, and the text purity and the structural integrity are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of document processing and data extraction, and more particularly, to a PDF text extraction method and system based on a large language model. Background Art

[0002] With the widespread application of large language models (such as ChatGPT and DeepSeek) in the field of natural language processing, they have demonstrated powerful capabilities in tasks such as document understanding, automatic question answering, and summary generation. However, in practical applications, PDF documents, as one of the most common information carriers, with their complex mixed text and image structure, pose significant challenges to the accurate understanding and reasoning of large language models. This is especially true for PDF documents containing a large number of interleaved illustrations and text. These documents are not written in natural, continuous paragraphs, but rather use multi-column, multi-layered layouts, making it difficult for purely linear text extraction tools to restore the original semantics and layout order when processing them.

[0003] Currently, when processing PDF files containing mixed text and images, large language models often encounter text parsing errors due to embedded images, which impacts the accuracy of question and answering. Traditional PDF parsing techniques, such as direct OCR or plain text extraction, struggle to effectively distinguish between images and text, often disrupting the original reading order and resulting in a chaotic order of extracted text, failing to meet the high-quality corpus input requirements of large language models. Furthermore, the extracted results lack structured information such as title hierarchy, paragraph divisions, and image and text alignment, making them unable to provide complete contextual support for large language models.

[0004] Therefore, it is necessary to provide a PDF text extraction method and system based on a large language model to solve the above technical problems. In order to solve the above problems, a technical solution is now provided. Summary of the Invention

[0005] In order to overcome the above-mentioned defects of the prior art, the present invention provides a PDF text extraction method and system based on a large language model, which is used to solve the problem that the text extracted by the existing PDF parsing technology has a disordered order and cannot meet the requirements of the large model for high-quality corpus input.

[0006] To achieve the above object, the present invention provides the following technical solutions: A PDF text extraction method based on a large language model includes the following steps: Obtain the target PDF document, use PyMuPDF to parse the content of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified; Identify noise interference features of the first area to be identified and the second area to be identified based on a multi-dimensional recognition strategy, remove the noise interference features to obtain the first area to be processed and the second area to be processed, and update spatial position information of the first area to be processed and the second area to be processed; Based on the spatial positioning information of the first and second areas to be processed, a multi-level text logic reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document, and a first-level PDF document is initially output. An image-text correlation analysis is performed on the first-level PDF document to output a first correlation strength. The large language model is used to intelligently identify and correct semantic structural anomalies on each page of the first-level PDF document to obtain a second-level PDF document. A second-level image-text correlation analysis is performed on the second-level PDF document to output a second correlation strength. A document reconstruction detection evaluation value is generated based on the first association strength and the second association strength, whether the secondary PDF document is qualified is determined according to the document reconstruction detection evaluation value, and the qualified secondary PDF document is output in a structured format.

[0007] As a further solution of the present invention, PyMuPDF is used to parse the contents of each page of the target PDF document, identify the image area and the text area, and perform positioning marking to obtain the first area to be identified and the second area to be identified. The specific process is as follows: Use PyMuPDF to parse the contents of each page of the target PDF document and extract multiple categories of object elements in the document page, including text blocks, images, and drawing elements; Marking multiple categories of object elements with rectangular boxes to obtain element text boxes, and recording the spatial position information of the element text boxes in the document page, the spatial position information including coordinate position, size and page number; Based on the OCR algorithm, the images and drawing elements in the element text box of each page are identified as the initial text content of the image area, the initial text content is associated with the spatial position information of the document page and marked as the first area to be identified, and the text block in the element text box is associated with the spatial position information of the document page and marked as the second area to be identified.

[0008] As a further solution of the present invention, noise interference features of the first area to be identified and the second area to be identified are identified based on a multi-dimensional recognition strategy, which includes a position recognition strategy, a text recognition strategy, a style recognition strategy, and a frequency recognition strategy.

[0009] As a further solution of the present invention, the position recognition strategy is used to identify and locate specific elements that appear repeatedly on the edge of the document page, and judge them as signal interference features; the text recognition strategy is used to match specific keywords using regular expressions, and judge them as signal interference features; the style recognition strategy is used to identify specific text with abnormal font color transparency, tilt angle or font size, and judge them as signal interference features; the frequency recognition strategy is used to identify and count non-text information that appears repeatedly in all document pages, and judge them as signal interference features.

[0010] As a further solution of the present invention, based on the spatial positioning information of the first area to be processed and the second area to be processed, a multi-level text logic reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document, and a first-level PDF document is initially output. A graphic-text correlation analysis is performed on the first-level PDF document to output a first correlation strength. The specific process is as follows: Extracting spatial positioning information of the first area to be processed and the second area to be processed, and preliminarily sorting the first area to be processed and the second area to be processed on the same document page in a manner that prioritizes vertical position on the document page and takes a lower order of horizontal position; Formulate a multi-level text logic reconstruction strategy to reconstruct the logical order of the target PDF document. The multi-level text logic reconstruction strategy includes paragraph attribution reconstruction strategy, title level reconstruction strategy, list structure reconstruction strategy, and image-text relationship reconstruction strategy. The reconstructed target PDF document is sorted and reconstructed to output a first-level PDF document, and a graphic-text correlation analysis is performed on the first-level PDF document to output a first correlation strength.

[0011] As a further solution of the present invention, during the preliminary sorting, the vertical positions follow the order from top to bottom, and the horizontal positions follow the order from left to right.

[0012] As a further solution of the present invention, a graphic-text correlation analysis is performed on the first-level PDF document to output a first correlation strength. The specific process is as follows: Extracting a first to-be-processed area and a second to-be-processed area in a first-level PDF document, constructing a graphic-text association degree analysis model, obtaining a first graphic-text semantic association feature of the second to-be-processed area vertically adjacent to the upper portion of the first to-be-processed area, and a second graphic-text semantic association feature of the second to-be-processed area vertically adjacent to the lower portion of the first to-be-processed area; the first graphic-text semantic association feature includes a first keyword matching feature and a first semantic similarity matching feature; the second graphic-text semantic association feature includes a second keyword matching feature and a second semantic similarity matching feature; Then analyze the logical correlation of the text content between the two second areas to be processed that are vertically adjacent to the first area to be processed, and calculate the weighted result of the first image-text semantic correlation feature, the second image-text semantic correlation feature and the logical correlation as the first correlation strength.

[0013] As a further solution of the present invention, the paragraph attribution reconstruction strategy determines whether two text blocks belong to the same paragraph by analyzing the left starting position of the text blocks and the distance between the upper and lower lines in the vertically adjacent second area to be processed; if the two text blocks belong to the same paragraph, paragraph reconstruction is not required; otherwise, paragraph reconstruction is required; The title level reconstruction strategy extracts the specific style information of each text block in the second to-be-processed area, combines it with the position to identify the title features, and divides the title features into first-level, second-level, and third-level titles; The list structure reconstruction strategy identifies numbers and bullet points, analyzes the list hierarchy and nesting relationship to determine whether reconstruction is necessary; The image-text relationship reconstruction strategy extracts images and drawing elements from the first area to be processed and forms separate paragraphs.

[0014] As a further solution of the present invention, a large language model is used to perform intelligent semantic structure anomaly recognition and correction on each page of the first-level PDF document to obtain a second-level PDF document. A second image-text correlation analysis is performed on the second-level PDF document to output a second correlation strength. The specific process is as follows: Construct a PDF document training dataset containing various noise samples and manually annotate the signal interference features; Fine-tune the pre-trained language model based on the PDF document training dataset, and enable it to distinguish noise through supervised learning or instruction fine-tuning. Input the original PDF document sequence with noise interference and output the reconstructed PDF document sequence. By analyzing the first-level PDF document section by section, the signal interference features are automatically identified and eliminated. The pre-trained language model is used to remove residual noise, correct the text sequence, and restore the semantic coherence of the first-level PDF document to obtain the second-level PDF document.

[0015] As a further solution of the present invention, a document reconstruction detection evaluation value is generated based on the first correlation strength and the second correlation strength, and whether the secondary PDF document is qualified is determined according to the document reconstruction detection evaluation value. The specific process includes: The difference between the first association strength and the second association strength is obtained as a document reconstruction detection evaluation value, and the document detection evaluation value is compared with a preset evaluation threshold. If the document detection evaluation value is greater than or equal to the preset evaluation threshold, the secondary PDF document is unqualified; if the document detection evaluation value is less than the preset evaluation threshold, the secondary PDF document is qualified.

[0016] As a further solution of the present invention, the secondary PDF document is output in a structured format, and the structured format includes JSON, XML, Markdown or plain text format.

[0017] A PDF text extraction system based on a large language model, comprising an image region and text detection module, a noise information identification and removal module, a text logical sequence rearrangement module, a text anomaly intelligent identification module, and a document reconstruction detection and evaluation module; The image region and text detection module is used to identify the noise interference features of the first area to be identified and the second area to be identified based on a multi-dimensional recognition strategy, eliminate the noise interference features to obtain the first area to be processed and the second area to be processed, and update the spatial position information of the first area to be processed and the second area to be processed; The noise information identification and elimination module is used to obtain the target PDF document, use PyMuPDF to parse the content of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified; The text logical order rearrangement module is used to formulate a multi-level text logic reconstruction strategy based on the spatial positioning information of the first and second areas to be processed to complete the reconstruction of the logical order of the target PDF document, initially output a first-level PDF document, and perform a text-image correlation analysis on the first-level PDF document to output a first correlation strength; The text anomaly intelligent recognition module is used to use a large language model to perform intelligent semantic structural anomaly recognition and correction on each page of the first-level PDF document to obtain a second-level PDF document. Based on the second-level PDF document, a secondary image-text correlation analysis is performed to output a second correlation strength. The document reconstruction detection and evaluation module is used to generate a document reconstruction detection evaluation value based on the first association strength and the second association strength, determine whether the secondary PDF document is qualified according to the document reconstruction detection evaluation value, and output the qualified secondary PDF document in a structured format.

[0018] The present invention provides a PDF text extraction method and system based on a large language model, which has the following technical effects and advantages: the present invention utilizes PyMuPDF to parse the content of each page of a target PDF document, and locates and marks the first area to be identified and the second area to be identified; based on a multi-dimensional recognition strategy, noise interference features of the first area to be identified and the second area to be identified are identified, and the noise interference features are eliminated to obtain the first area to be processed and the second area to be processed; a multi-level text logic reconstruction strategy is formulated to complete the reconstruction of the logical sequence of the target PDF document, and a first-level PDF document is preliminarily output; a graphic-text association degree analysis is performed on the first-level PDF document to output a first association strength; the large language model is used to perform intelligent anomaly recognition and correction on the semantic structure of each page of the first-level PDF document, and a second graphic-text association degree analysis is performed on the second-level PDF document to output a second association strength; a document reconstruction detection evaluation value is generated based on the first association strength and the second association strength, and whether the second-level PDF document is qualified is determined according to the document reconstruction detection evaluation value, and the qualified second-level PDF document is output in a structured format.

[0019] The present invention can integrate key technologies such as image-text positioning, noise recognition, multi-level structure reconstruction and semantic intelligent correction, and effectively solve the problems of image-text dislocation, structural chaos, noise interference and semantic fracture in traditional PDF text parsing; by constructing an image-text correlation model, combining features such as keyword matching and semantic similarity, the semantic correlation degree between the image and the context paragraph is evaluated, providing a basis for realizing advanced tasks such as image annotation, chart attribution determination, and content aggregation; through two rounds of image-text correlation analysis, combined with the first correlation strength, the second correlation strength and the document reconstruction detection evaluation value, the quality assessment and qualification judgment mechanism of the extraction results are realized, ensuring that the structured output data is reliable and complete; the present invention not only significantly improves the accuracy and purity of text extraction, but also restores the logical order and semantic integrity of the document, and finally outputs it in a structured format, providing a high-quality data foundation for subsequent knowledge extraction, search analysis and intelligent question-answering applications, and has wide applicability and practical value. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 A flowchart of a PDF text extraction method based on a large language model provided by an embodiment of the present invention; Figure 2 A system block diagram of a PDF text extraction system based on a large language model provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0021] The following will clearly and completely describe the technical solutions of the present invention in conjunction with the accompanying drawings. Obviously, the technical solutions described are only part of the present invention, not the entire invention. Based on the technical solutions of the present invention, all other technical solutions obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.

[0022] like Figure 1 FIG. 1 is a flowchart of a PDF text extraction method based on a large language model provided by an embodiment of the present invention. Figure 1 The execution subject of the method shown may be a software and / or hardware device. The execution subject of the present application may include but is not limited to at least one of the following: user equipment, network equipment, etc. Among them, user equipment may include but is not limited to computers, smart phones, personal digital assistants (PDAs) and the electronic devices mentioned above. Network equipment may include but is not limited to a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of computers or network servers, wherein cloud computing is a type of distributed computing, a super virtual computer composed of a group of loosely coupled computers. This embodiment does not limit this. It includes steps S1 to S5, as follows: S1, obtain the target PDF document, use PyMuPDF (PDF document parsing tool) to parse the content of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified; First, the target PDF document specified by the user is received, and the target PDF document is parsed page by page through PyMuPDF. For each page in the target PDF document, the document content is loaded and the text information on the page is extracted. The image embedded in the page is extracted and visualized, and its spatial distribution in the page can be determined by information such as image size, pixel density, and embedding position. Based on the above operations, the system divides the page content into two main areas: The first area to be identified: refers to the area where the image and drawing elements are located in the page identified through the image extraction interface, usually non-text content such as charts, illustrations, and scanned images. The second area to be identified: refers to the text block area identified through the text extraction interface, which contains content such as text, title, page number, etc. The above two areas are spatially positioned and annotated respectively, and their position coordinates on the page are recorded and output in a structured form.

[0023] Finally, the recognition and positioning of image areas and text areas in the entire PDF document are completed, providing structured input for the next step of noise removal and text semantic rearrangement based on multi-dimensional strategies, effectively improving the processing accuracy of mixed-text and image documents, and is particularly suitable for PDF files of complex structures such as academic papers, report materials, scanned archives, etc.

[0024] S2, identifying noise interference features of the first area to be identified and the second area to be identified based on a multi-dimensional recognition strategy, removing the noise interference features to obtain the first area to be processed and the second area to be processed, and updating spatial position information of the first area to be processed and the second area to be processed; By loading the image and text area information obtained in the previous stage and relying on a pre-set multi-dimensional recognition strategy, a fine-grained analysis of the content within each area to be identified is performed. Guided by this multi-dimensional recognition strategy, the image and drawing elements in the first area to be identified are located and noisy pixel areas are eliminated, for example, removing the recurring "DRAFT" watermark layer in the corner of a chart. For text blocks in the second area to be identified, prompt information such as "Company Internal Information" and "Printing Time: December 2023" is eliminated based on their content and style characteristics.

[0025] After noise interference removal is completed, the boundary area of ​​the retained content will be automatically reconstructed, the corresponding first and second areas to be processed will be updated, and the spatial position coordinates of the content in the page will be recalculated. For example, if the original text area shrinks upward after the top header content is removed, its position coordinates will be updated to accurately reflect the position of the processed content. It achieves precise noise removal and spatial positioning updates for image and text areas in PDF documents, ensuring the accuracy and high purity of the content processed in the subsequent semantic structure recognition and logical sequence rearrangement stages. It is widely applicable to cleaning and pre-processing scenarios of complex structure documents, scanned archives, and multi-image and text fusion reports.

[0026] S3, based on the spatial positioning information of the first and second regions to be processed, formulating a multi-level text logic reconstruction strategy to reconstruct the logical order of the target PDF document, initially outputting a first-level PDF document, and performing an image-text correlation analysis on the first-level PDF document to output a first correlation strength; The remaining text blocks, images, and drawing elements on each document page are scanned to extract their spatial position parameters, including top-left and bottom-right corner coordinates, relative position within the page, and page number. Basic style features of each text block, such as font size, bold, indentation, and alignment, are also identified for subsequent structural hierarchy inference. Following this strategy, the entire document content is rearranged and reorganized according to its logical hierarchy and semantic flow, creating a unified logical paragraph sequence. Structural tags, such as chapter numbers, paragraph levels, and image / text block identifiers, are then annotated. This generates a preliminarily structured, first-level PDF document that eliminates content noise and maintains a clear hierarchy of headings, paragraph divisions, and image-text correspondences. The spatial positioning information of each paragraph is preserved, facilitating further semantic understanding, knowledge extraction, or formatting. Finally, a text-image relevance model is constructed, combining features such as keyword matching and semantic similarity to assess the semantic relevance between images and contextual paragraphs. This provides a basis for advanced tasks such as image annotation, chart attribution determination, and content aggregation.

[0027] S4: Using a large language model, intelligently identify and correct semantic structural anomalies on each page of the first-level PDF document to obtain a second-level PDF document. A second image-text correlation analysis is performed on the second-level PDF document to output a second correlation strength. Load the constructed first-level PDF document and divide the document content by page. The text content of each page and its structural labels are passed as input to the large language model. The model has been pre-trained or fine-tuned with instructions using a large amount of document corpus, and has good paragraph attribution judgment, context understanding, text reorganization and logical correction capabilities. The document content is coherent and structurally complete, with each paragraph having semantic continuity and natural transitions; the title hierarchy is accurate and the logical structure is clear; the text and graphics are complete, without content jumps or misalignments; there is no redundant residual noise content, and the text is pure. Performing another text-graphic association analysis on the second-level PDF text can identify image paragraphs that were previously misattributed, merge incorrectly split text and graphics content, and determine whether the image is a core component of the context, thereby providing stronger support for applications such as text-graphic pair extraction and image annotation generation.

[0028] S5 , generating a document reconstruction detection evaluation value based on the first correlation strength and the second correlation strength, determining whether the secondary PDF document is qualified according to the document reconstruction detection evaluation value, and outputting the qualified secondary PDF document in a structured format.

[0029] By establishing a document reconstruction detection evaluation value centered on the strength of image-text association, we achieve quality control of the entire process from structural reconstruction, semantic correction to structured output, so that the output PDF results have verifiable guarantees in terms of logical integrity, image-text consistency, and data structure accuracy, providing stable and reliable technical support for intelligent parsing and understanding of documents in multiple fields.

[0030] Preferably, PyMuPDF is used to parse the contents of each page of the target PDF document, identify the image area and the text area, and perform positioning marking to obtain the first area to be identified and the second area to be identified. The specific process is as follows: Use PyMuPDF to parse the contents of each page of the target PDF document and extract multiple categories of object elements in the document page, including text blocks, images, and drawing elements; Drawing elements include paths, shading (which controls how a surface interacts with light) objects, and vector graphics; paths are composed of geometric shapes such as straight lines, Bezier curves, rectangles, and can be filled or stroked; shading objects are color gradient or texture filled areas that rely on mathematical functions to describe the relationship between color and position; vector graphics are pixel-independent graphics, such as chart outlines and line art, and are complex graphics composed of a combination of paths or defined by special instructions.

[0031] Marking multiple categories of object elements with rectangular boxes to obtain element text boxes, and recording the spatial position information of the element text boxes in the document page, the spatial position information including coordinate position, size and page number; It should be noted that the method for determining the coordinate position of spatial position information specifically includes: first, adjusting the document page to a fixed size, dividing it into M×M cells, taking the upper left corner of the document page as the origin, and establishing a two-dimensional rectangular coordinate system based on the width direction of the document page as the x-axis and the height direction as the y-axis, to determine the predicted position coordinates and number of cells in each element text box. Each element text box contains 4 predicted values: x, y, w, h, where x is the horizontal coordinate of the midpoint of the element text box, y is the vertical coordinate of the midpoint of the element text box, w is the width of the document page, and h is the height of the document page; respectively calculate the offset values ​​of x and y relative to the current cell so that x and y belong to ∈ [0, 1]; then normalize w and h, that is, divide them by the width and height of the image respectively so that w and h belong to ∈ [0, 1]. Based on the above, the predicted position coordinates of each cell in the document page are obtained. , based on the predicted position coordinates, the regional position coordinates of the element text box are obtained, and the predicted position coordinates of the upper left corner cell of each element text box are used as the coordinate position of the element text box.

[0032] Based on the OCR algorithm, the images and drawing elements in the element text box of each page are identified as the initial text content of the image area, the initial text content is associated with the spatial position information of the document page and marked as the first area to be identified, and the text block in the element text box is associated with the spatial position information of the document page and marked as the second area to be identified.

[0033] Preferably, the noise interference features of the first area to be identified and the second area to be identified are identified based on a multi-dimensional identification strategy, which includes a position identification strategy, a text identification strategy, a style identification strategy, and a frequency identification strategy.

[0034] Preferably, the position recognition strategy is used to identify and locate specific elements that appear repeatedly on the edge of a document page, and judge them as signal interference features; the text recognition strategy is used to match specific keywords using regular expressions, and judge them as signal interference features; the style recognition strategy is used to identify specific text with abnormal font color transparency, tilt angle or font size, and judge them as signal interference features; the frequency recognition strategy is used to identify and count non-text information that appears repeatedly in all document pages, and judge them as signal interference features.

[0035] It should be noted that the specific elements that appear repeatedly along the edges of document pages in the location recognition strategy include page numbers, headers, footers, and scan numbers. Examples include "Company training materials, for internal use only" located in the center of the top of the page; the page number "Page 3 of 25" located in the lower right corner of the page; and the scan barcode or scan timestamp located in a fixed position in the lower left corner. Specific keywords in the text recognition strategy include non-text prompts, advertising logos, or copyright notices. Examples include copyright-related terms such as "Copyright," "Confidential," and "Scanned from XXX website"; web links such as "https: / / ..." or "www.xxx.com"; and prompts such as "Advertising Hotline," "For Reference Only," and "Printed on: 20XX." The specific text mentioned in the style identification strategy includes image background watermarks, annotations, or layer residues. Specifically, it can be specific text with extremely low font transparency, almost unrecognizable to the naked eye; specific text with abnormal font tilt angle (such as rotation of more than 30 degrees), such as specific text with an oblique watermark of "DRAFT"; specific text with extremely small font size (such as font height <6px) and almost unreadable footer. The non-text information mentioned in the frequency identification strategy includes template headers, footers, or fixed explanatory statements. For example, the same text "Report automatically generated by XX system" appears at the bottom of each page; "Report number: AB-2023-XYZ" appears at the beginning of each page, with exactly the same text; and each page has a fixed phrase "Scanned from XXX Library.

[0036] By synergistically applying these four recognition strategies, the present invention can identify and precisely remove non-textual content from documents based on multiple dimensions, including spatial distribution, semantic rules, style characteristics, and global document frequency. This allows the preservation of semantically coherent and clearly structured textual content, providing high-quality corpus support for subsequent document analysis, information extraction, and knowledge reconstruction.

[0037] Preferably, based on the spatial positioning information of the first area to be processed and the second area to be processed, a multi-level text logic reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document, and a first-level PDF document is preliminarily output. A graphic-text correlation analysis is performed on the first-level PDF document to output a first correlation strength. The specific process is as follows: Extracting spatial positioning information of the first area to be processed and the second area to be processed, and preliminarily sorting the first area to be processed and the second area to be processed on the same document page in a manner that prioritizes vertical position on the document page and takes a lower order of horizontal position; It should be noted that the preliminary sorting is performed with the vertical position in the document page taking priority and the horizontal position taking second place, where the vertical position refers to the first area to be processed and the second area to be processed: if the vertical coordinate positions of the first area to be processed and the second area to be processed in the same document page are the same, then the preliminary sorting is determined based on the horizontal coordinate positions; if the vertical coordinate positions of the first area to be processed and the second area to be processed in the same document page are different, then the preliminary sorting is determined based on the vertical coordinate positions.

[0038] Formulate a multi-level text logic reconstruction strategy to reconstruct the logical order of the target PDF document. The multi-level text logic reconstruction strategy includes paragraph attribution reconstruction strategy, title level reconstruction strategy, list structure reconstruction strategy, and image-text relationship reconstruction strategy. The reconstructed target PDF document is sorted and reconstructed to output a first-level PDF document, and a graphic-text correlation analysis is performed on the first-level PDF document to output a first correlation strength.

[0039] Preferably, when performing preliminary sorting, the vertical positions follow an order from top to bottom, and the horizontal positions follow an order from left to right.

[0040] Perform an image-text correlation analysis on the first-level PDF document to output the first correlation strength. The specific process is as follows: Extracting a first to-be-processed area and a second to-be-processed area in a first-level PDF document, constructing a graphic-text association degree analysis model, obtaining a first graphic-text semantic association feature of the second to-be-processed area vertically adjacent to the upper portion of the first to-be-processed area, and a second graphic-text semantic association feature of the second to-be-processed area vertically adjacent to the lower portion of the first to-be-processed area; the first graphic-text semantic association feature includes a first keyword matching feature and a first semantic similarity matching feature; the second graphic-text semantic association feature includes a second keyword matching feature and a second semantic similarity matching feature; It should be noted that the calculation steps for the first keyword matching feature and the second keyword matching feature are: Obtaining the first text content of the first to-be-processed area and the second text content of the second to-be-processed area adjacent thereto, obtaining a first keyword based on the first text content, and then obtaining a second keyword based on the second text content, verifying whether the first keyword appears in the second keyword one by one, and counting the number of first repeated keywords. Calculating the ratio of the number of first repeated keywords to the first keyword to obtain a first keyword matching feature; Obtain the first text content of the first area to be processed and the third text content of the second area to be processed below. Obtain the first keyword based on the first text content, and then obtain the third keyword based on the third text content. Verify whether the first keyword appears in the third keyword one by one, and count the number of second repeated keywords. Use the ratio of the number of second repeated keywords to the first keyword to obtain the second keyword matching feature. The first keyword is obtained by extracting nouns, technical terms, and verb phrases from the first text content using a word segmentation tool. The second and third keywords are obtained in the same way and will not be repeated here.

[0041] The calculation steps of the first semantic similarity matching feature and the second semantic similarity matching feature are as follows: Obtaining first text content of a first area to be processed and second text content of a second area to be processed adjacent thereto, performing text cleaning on the first and second text contents, including removing redundant symbols, spaces, and formatting marks, encoding the first and second text contents into fixed-dimensional semantic vectors using a pre-trained model, and calculating cosine similarity based on the obtained semantic vectors as a first semantic similarity matching feature; Obtain the first text content of the first area to be processed and the third text content of the second area to be processed below, perform text cleaning on the first text content and the third text content, including removing redundant symbols, spaces and formatting marks, and encode the first text content and the third text content into semantic vectors of fixed dimensions through a pre-trained model. Calculate the cosine similarity based on the obtained semantic vectors as the second semantic similarity matching feature.

[0042] Then analyze the logical correlation of the text content between the two second areas to be processed that are vertically adjacent to the first area to be processed, and calculate the weighted result of the first image-text semantic correlation feature, the second image-text semantic correlation feature and the logical correlation as the first correlation strength.

[0043] It should be noted that the calculation process of the logical correlation between the text contents of the two second to-be-processed regions is as follows: Obtain the second text content of the second area to be processed above the first area to be processed, and the third text content of the second area to be processed below the first area to be processed, perform text cleaning on the second text content and the third text content, including removing redundant symbols, spaces and formatting marks, and encode the second text content and the third text content into semantic vectors of fixed dimensions through a pre-trained model, and calculate cosine similarity as logical association based on the obtained semantic vectors.

[0044] Based on the above, the first image-text semantic association feature, the second image-text semantic association feature and the logical association degree are weighted to obtain the first association strength, which is calculated as follows: Where, is the first correlation strength, is the weight coefficient of the first image-text semantic association feature, is the first image-text semantic association feature, is the weight coefficient of the second image-text semantic association feature, is the second image-text semantic association feature, is the weight coefficient of logical association, is the logical association, is the impact factor.

[0045] Preferably, the paragraph attribution reconstruction strategy determines whether two text blocks belong to the same paragraph by analyzing the left starting position of the text blocks and the distance between the upper and lower lines in the vertically adjacent second area to be processed; if the two text blocks belong to the same paragraph, then paragraph reconstruction is not required; otherwise, paragraph reconstruction is required; It should be noted that if the left starting position coordinates of the two text blocks are basically aligned and the line spacing is within a reasonable range, the two text blocks are classified as the same paragraph; if the left starting position (indent value) of the two text blocks is obviously indented or the line spacing is obviously greater than the average intra-paragraph spacing, it is judged as the start of a new paragraph; for situations such as hanging indents and alignment errors, a certain range of tolerance is allowed for merging judgment.

[0046] The title level reconstruction strategy extracts the specific style information of each text block in the second to-be-processed area, combines it with the position to identify the title features, and divides the title features into first-level, second-level, and third-level titles; It should be noted that a text block with a significantly larger, bold, and center-aligned font is considered a first-level title; a text block with a relatively smaller font, still bold but left-aligned is considered a second-level title; and a text block with an even smaller font or no bold but numbered, such as 3.1 or 3.1.1, is considered a third-level title.

[0047] The list structure reconstruction strategy identifies numbers and bullet points, analyzes the list hierarchy and nesting relationship to determine whether reconstruction is necessary; It should be noted that the numbering format (numbers, letters, mixed) and indentation level are analyzed to identify the nesting level of lists. If adjacent text blocks have a unified numbering format and a progressive relationship in indentation, they are classified into the same multi-level list structure and do not require reconstruction. Otherwise, reconstruction is required. However, for items with broken or abnormal numbering sequences, fault tolerance is allowed within a certain range and the numbering is repaired, so reconstruction is not required.

[0048] The image-text relationship reconstruction strategy extracts images and drawing elements from the first area to be processed and forms separate paragraphs.

[0049] It should be noted that, for the adjacent first and second areas to be processed, the vertically adjacent second areas to be processed are first merged and sorted, and then the text in the first area to be processed is attached to the second area to be processed as an independent paragraph.

[0050] Preferably, a large language model is used to perform intelligent semantic structure anomaly recognition and correction on each page of the first-level PDF document to obtain a second-level PDF document. A second image-text correlation analysis is performed on the second-level PDF document to output a second correlation strength. The specific process is as follows: Construct a PDF document training dataset containing various noise samples and manually annotate the signal interference features; The pre-trained language model is fine-tuned based on the PDF document training dataset. Through supervised learning or instruction fine-tuning, it is given the ability to distinguish noise. The original PDF document sequence with noise interference is input and the reconstructed PDF document sequence is output. The pre-trained language model can identify the logical structure of paragraphs based on contextual information, and judge and correct abnormal paragraph order or semantic jump problems.

[0051] It should be noted that each page or each paragraph of OCR recognized text is input into the pre-trained language model as the original PDF document sequence, and the reconstructed PDF document sequence is obtained by calling the fine-tuned pre-trained language model to perform further semantic discrimination and structural rearrangement on the original PDF document sequence.

[0052] By analyzing the first-level PDF document section by section, the signal interference features are automatically identified and eliminated. The pre-trained language model is used to remove residual noise, correct the paragraph order, and restore the semantic coherence of the first-level PDF document to obtain the second-level PDF document. A secondary image-text correlation analysis is performed on the second-level PDF document to output the second correlation strength.

[0053] It should be noted that residual noise removal uses a pre-trained language model to analyze the first-level PDF document section by section, automatically identifying remaining watermark characters, repeated page numbers, invalid phrases and other non-text content, and removing them.

[0054] It should be noted that the process of obtaining the second association strength is the same as the process of obtaining the first association strength, which will not be described in detail here.

[0055] Paragraph order correction uses the contextual understanding ability of the pre-trained language model to sort and correct the identified paragraphs. If it is found that the order of paragraphs does not match the logical structure, such as "Conclusion" appears before "Method", the pre-trained language model will automatically adjust their order.

[0056] Semantic coherence restoration is used to correct semantic breaks caused by layout confusion or misplaced segmentation. The pre-trained language model can intelligently complete text, merge sentences, or rewrite the beginning / ending phrases to enhance semantic fluency.

[0057] A document reconstruction detection evaluation value is generated based on the first association strength and the second association strength, whether the secondary PDF document is qualified is determined according to the document reconstruction detection evaluation value, and the qualified secondary PDF document is output in a structured format.

[0058] A document reconstruction detection evaluation value is generated based on the first correlation strength and the second correlation strength, and whether the secondary PDF document is qualified is determined based on the document reconstruction detection evaluation value. The specific process includes: The difference between the first association strength and the second association strength is obtained as a document reconstruction detection evaluation value, and the document detection evaluation value is compared with a preset evaluation threshold. If the document detection evaluation value is greater than or equal to the preset evaluation threshold, the secondary PDF document is unqualified; if the document detection evaluation value is less than the preset evaluation threshold, the secondary PDF document is qualified.

[0059] Output secondary PDF documents in structured formats, including JSON, XML, Markdown, or plain text. Structured formats can be directly used for document summarization, content retrieval, structured database storage, or other information processing systems.

[0060] A PDF text extraction system based on a large language model, comprising an image region and text detection module, a noise information identification and removal module, a text logical sequence rearrangement module, a text anomaly intelligent identification module, and a document reconstruction detection and evaluation module; The image region and text detection module is used to identify the noise interference features of the first area to be identified and the second area to be identified based on a multi-dimensional recognition strategy, eliminate the noise interference features to obtain the first area to be processed and the second area to be processed, and update the spatial position information of the first area to be processed and the second area to be processed; The noise information identification and elimination module is used to obtain the target PDF document, use PyMuPDF to parse the content of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified; The text logical order rearrangement module is used to formulate a multi-level text logic reconstruction strategy based on the spatial positioning information of the first and second areas to be processed to complete the reconstruction of the logical order of the target PDF document, initially output a first-level PDF document, and perform a text-image correlation analysis on the first-level PDF document to output a first correlation strength; The text anomaly intelligent recognition module is used to use a large language model to perform intelligent semantic structural anomaly recognition and correction on each page of the first-level PDF document to obtain a second-level PDF document. Based on the second-level PDF document, a secondary image-text correlation analysis is performed to output a second correlation strength. The document reconstruction detection and evaluation module is used to generate a document reconstruction detection evaluation value based on the first association strength and the second association strength, determine whether the secondary PDF document is qualified according to the document reconstruction detection evaluation value, and output the qualified secondary PDF document in a structured format.

[0061] like Figure 2 FIG. 1 is a system block diagram of a PDF text extraction system based on a large language model according to an embodiment of the present invention, which can be used to perform Figure 1 The implementation principles and technical effects of the steps in the method embodiment shown are similar and will not be repeated here.

[0062] Through the introduction of the above embodiments, the present invention uses PyMuPDF to parse the content of each page of the target PDF document, and locates the mark to obtain the first area to be identified and the second area to be identified; based on the multi-dimensional recognition strategy, the noise interference features of the first area to be identified and the second area to be identified are identified, and the noise interference features are eliminated to obtain the first area to be processed and the second area to be processed; a multi-level text logic reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document, and a first-level PDF document is preliminarily output. A graphic-text association degree analysis is performed on the first-level PDF document to output a first association strength; through a large language model, each page of the first-level PDF document is subjected to intelligent anomaly recognition and correction on the semantic structure to obtain a second-level PDF document, and a second graphic-text association degree analysis is performed on the second-level PDF document to output a second association strength; a document reconstruction detection evaluation value is generated based on the first association strength and the second association strength, and whether the second-level PDF document is qualified is determined according to the document reconstruction detection evaluation value, and the qualified second-level PDF document is output in a structured format.

[0063] The present invention can integrate key technologies such as image-text positioning, noise recognition, multi-level structure reconstruction and semantic intelligent correction, and effectively solve the problems of image-text dislocation, structural chaos, noise interference and semantic fracture in traditional PDF text parsing; by constructing an image-text correlation model, combining features such as keyword matching and semantic similarity, the semantic correlation degree between the image and the context paragraph is evaluated, providing a basis for realizing advanced tasks such as image annotation, chart attribution determination, and content aggregation; through two rounds of image-text correlation analysis, combined with the first correlation strength, the second correlation strength and the document reconstruction detection evaluation value, the quality assessment and qualification judgment mechanism of the extraction results are realized, ensuring that the structured output data is reliable and complete; the present invention not only significantly improves the accuracy and purity of text extraction, but also restores the logical order and semantic integrity of the document, and finally outputs it in a structured format, providing a high-quality data foundation for subsequent knowledge extraction, search analysis and intelligent question-answering applications, and has wide applicability and practical value.

[0064] The above is only a specific implementation method of the present application, but the scope of protection of the present application is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed in this application, which should be covered by the scope of protection of the present application.

[0065] Finally: The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A PDF text extraction method based on a large language model, characterized in that: The following steps are involved: Obtain the target PDF document, use PyMuPDF to parse the content of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified; Identify noise interference features of the first area to be identified and the second area to be identified based on a multi-dimensional recognition strategy, remove the noise interference features to obtain the first area to be processed and the second area to be processed, and update spatial position information of the first area to be processed and the second area to be processed; Based on the spatial positioning information of the first and second areas to be processed, a multi-level text logic reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document, and a first-level PDF document is initially output. An image-text correlation analysis is performed on the first-level PDF document to output a first correlation strength. The large language model is used to intelligently identify and correct semantic structural anomalies on each page of the first-level PDF document to obtain a second-level PDF document. A second-level image-text correlation analysis is performed on the second-level PDF document to output a second correlation strength. A document reconstruction detection evaluation value is generated based on the first association strength and the second association strength, whether the secondary PDF document is qualified is determined according to the document reconstruction detection evaluation value, and the qualified secondary PDF document is output in a structured format.

2. A PDF text extraction method based on a large language model according to claim 1, characterized in that: Use PyMuPDF to parse the contents of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified. The specific process is as follows: Use PyMuPDF to parse the contents of each page of the target PDF document and extract multiple categories of object elements in the document page, including text blocks, images, and drawing elements; Marking multiple categories of object elements with rectangular boxes to obtain element text boxes, and recording the spatial position information of the element text boxes in the document page, the spatial position information including coordinate position, size and page number; Based on the OCR algorithm, the images and drawing elements in the element text box of each page are identified as the initial text content of the image area, the initial text content is associated with the spatial position information of the document page and marked as the first area to be identified, and the text block in the element text box is associated with the spatial position information of the document page and marked as the second area to be identified.

3. The PDF text extraction method based on a large language model according to claim 1, characterized in that: The noise interference features of the first area to be identified and the second area to be identified are identified based on a multi-dimensional recognition strategy, where the multi-dimensional recognition strategy includes a position recognition strategy, a text recognition strategy, a style recognition strategy, and a frequency recognition strategy.

4. The PDF text extraction method based on a large language model according to claim 3 is characterized in that: The position recognition strategy is used to identify and locate specific elements that appear repeatedly on the edges of document pages and determine them as signal interference features; the text recognition strategy is used to match specific keywords using regular expressions and determine them as signal interference features; the style recognition strategy is used to identify specific text with abnormal font color transparency, tilt angle or font size and determine them as signal interference features; the frequency recognition strategy is used to identify and count non-text information that appears repeatedly on all document pages and determine it as a signal interference feature.

5. The PDF text extraction method based on a large language model according to claim 1, characterized in that: Based on the spatial positioning information of the first and second areas to be processed, a multi-level text logic reconstruction strategy is formulated to complete the reconstruction of the logical order of the target PDF document. A first-level PDF document is initially output. A graphic-text correlation analysis is performed on the first-level PDF document to output the first correlation strength. The specific process is as follows: Extracting spatial positioning information of the first area to be processed and the second area to be processed, and preliminarily sorting the first area to be processed and the second area to be processed on the same document page in a manner that prioritizes vertical position on the document page and takes a lower order of horizontal position; Formulate a multi-level text logic reconstruction strategy to reconstruct the logical order of the target PDF document. The multi-level text logic reconstruction strategy includes paragraph attribution reconstruction strategy, title level reconstruction strategy, list structure reconstruction strategy, and image-text relationship reconstruction strategy. The reconstructed target PDF document is sorted and reconstructed to output a first-level PDF document, and a graphic-text correlation analysis is performed on the first-level PDF document to output a first correlation strength.

6. The PDF text extraction method based on a large language model according to claim 5, characterized in that: Perform an image-text correlation analysis on the first-level PDF document to output the first correlation strength. The specific process is as follows: Extracting a first to-be-processed region and a second to-be-processed region from a first-level PDF document, constructing a graphic-text association degree analysis model, and obtaining a first graphic-text semantic association feature of the second to-be-processed region vertically adjacent to the upper portion of the first to-be-processed region, and a second graphic-text semantic association feature of the second to-be-processed region vertically adjacent to the lower portion of the first to-be-processed region; Then analyze the logical correlation of the text content between the two second areas to be processed that are vertically adjacent to the first area to be processed, and calculate the weighted result of the first image-text semantic correlation feature, the second image-text semantic correlation feature and the logical correlation as the first correlation strength.

7. The PDF text extraction method based on a large language model according to claim 5, characterized in that: The paragraph attribution reconstruction strategy determines whether two text blocks belong to the same paragraph by analyzing the left starting position of the text blocks and the distance between the upper and lower lines in the vertically adjacent second processing area. If the two text blocks belong to the same paragraph, paragraph reconstruction is not required; otherwise, paragraph reconstruction is required. The title level reconstruction strategy extracts the specific style information of each text block in the second to-be-processed area, combines it with the position to identify the title features, and divides the title features into first-level, second-level, and third-level titles; The list structure reconstruction strategy identifies numbers and bullet points, analyzes the list hierarchy and nesting relationship to determine whether reconstruction is necessary; The image-text relationship reconstruction strategy extracts images and drawing elements from the first area to be processed and forms separate paragraphs.

8. The PDF text extraction method based on a large language model according to claim 1, characterized in that: The large language model is used to intelligently identify and correct semantic structural anomalies on each page of the first-level PDF document to obtain a second-level PDF document. A second-level image-text correlation analysis is performed on the second-level PDF document to output the second correlation strength. The specific process is as follows: Construct a PDF document training dataset containing various noise samples and manually annotate the signal interference features; Fine-tune the pre-trained language model based on the PDF document training dataset, and enable it to distinguish noise through supervised learning or instruction fine-tuning. Input the original PDF document sequence with noise interference and output the reconstructed PDF document sequence. By analyzing the first-level PDF document section by section, the signal interference features are automatically identified and eliminated. The pre-trained language model is used to remove residual noise, correct the paragraph order, and restore the semantic coherence of the first-level PDF document to obtain the second-level PDF document. A secondary image-text correlation analysis is performed on the second-level PDF document to output the second correlation strength.

9. The PDF text extraction method based on a large language model according to claim 1, characterized in that: A document reconstruction detection evaluation value is generated based on the first correlation strength and the second correlation strength, and whether the secondary PDF document is qualified is determined based on the document reconstruction detection evaluation value. The specific process includes: The difference between the first association strength and the second association strength is obtained as a document reconstruction detection evaluation value, and the document detection evaluation value is compared with a preset evaluation threshold. If the document detection evaluation value is greater than or equal to the preset evaluation threshold, the secondary PDF document is unqualified; if the document detection evaluation value is less than the preset evaluation threshold, the secondary PDF document is qualified.

10. A PDF text extraction system based on a large language model, applied to a PDF text extraction method based on a large language model as claimed in any one of claims 1 to 9, characterized in that: The system includes an image area and text detection module, a noise information identification and elimination module, a text logical sequence rearrangement module, a text anomaly intelligent identification module, and a document reconstruction detection and evaluation module; The image region and text detection module is used to identify the noise interference features of the first area to be identified and the second area to be identified based on a multi-dimensional recognition strategy, eliminate the noise interference features to obtain the first area to be processed and the second area to be processed, and update the spatial position information of the first area to be processed and the second area to be processed; The noise information identification and elimination module is used to obtain the target PDF document, use PyMuPDF to parse the content of each page of the target PDF document, identify the image area and text area, and perform positioning marks to obtain the first area to be identified and the second area to be identified; The text logical order rearrangement module is used to formulate a multi-level text logic reconstruction strategy based on the spatial positioning information of the first and second areas to be processed to complete the reconstruction of the logical order of the target PDF document, initially output a first-level PDF document, and perform a text-image correlation analysis on the first-level PDF document to output a first correlation strength; The text anomaly intelligent recognition module is used to use a large language model to perform intelligent semantic structural anomaly recognition and correction on each page of the first-level PDF document to obtain a second-level PDF document. Based on the second-level PDF document, a secondary image-text correlation analysis is performed to output a second correlation strength. The document reconstruction detection and evaluation module is used to generate a document reconstruction detection evaluation value based on the first association strength and the second association strength, determine whether the secondary PDF document is qualified according to the document reconstruction detection evaluation value, and output the qualified secondary PDF document in a structured format.

Citation Information

Patent Citations

  • Method for structuring PDF file based on OCR and large model

    CN119003465A

  • Method for creating structured document based on deep learning model

    CN119558307A

  • PDF extraction method and system based on deep learning and layout analysis

    CN119598971A

  • Format conversion method of PDF (Portable Document Format) document, storage medium and computer equipment

    CN120146000A

  • Document segmentation method based on multi-modal large model

    CN120218018A

Cited By

  • Method and system for retrieving DOCX document content based on keywords

    CN121029978A

  • Intelligent contract vulnerability detection and auditing method and system based on large language model

    CN121302379A

  • Information extraction method and device, electronic equipment and storage medium

    CN121482812A

  • Information extraction method and device, electronic equipment and storage medium

    CN121482812B

  • Lossless extraction method and equipment for graph vector diagram in PDF (Portable Document Format) and computer readable medium

    CN121562554A