A method and system for extracting annotated content from a PDF document
By developing an automated method and system for extracting annotated content from PDF documents, the problems of inconsistent display of annotated content and distorted layout have been solved. This achieves efficient and accurate information extraction and layout restoration, and is suitable for scenarios such as OA, education, and knowledge management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 赛博爱思(上海)软件科技有限公司
- Filing Date
- 2026-03-23
- Publication Date
- 2026-06-05
AI Technical Summary
Existing technologies for extracting content from annotated PDF documents suffer from inconsistent content display, distorted layout, and low efficiency due to manual processing.
This paper provides a method and system for extracting annotation content from PDF documents, including initializing extraction parameters, traversing document pages to obtain annotation data, classifying and preprocessing, automatically generating new PDF pages, arranging them according to preset rules, and performing multilingual translation output to ensure the accuracy of annotation content and the authenticity of layout.
It enables one-click automated extraction of annotation content from different PDF documents, improving information extraction efficiency, ensuring the accuracy and authenticity of annotation content, and supporting document archiving and information summarization needs.
Smart Images

Figure CN122154646A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of PDF document annotation content extraction technology, specifically referring to a method and system for extracting PDF document annotation content. Background Technology
[0002] With the widespread use of PDFs in daily office work and academic communication, users often add various annotations to PDF document pages, such as highlighting, underlining, wavy lines, annotations, and illustrations, to express key points, note important opinions, or facilitate collaboration. When archiving, summarizing, or compiling documents, how to efficiently and accurately extract and restore these PDF annotations has become an important step in achieving knowledge accumulation and reuse. Existing technologies often suffer from inconsistent content display, format distortion, and low efficiency of manual processing when extracting and generating annotations. Therefore, this paper proposes a method and system for extracting annotations from PDF documents. Summary of the Invention
[0003] The purpose of this invention is to provide a method and system for extracting annotated content from PDF documents, so as to solve the problems mentioned in the background art.
[0004] To achieve the above objectives, the present invention provides the following technical solution: a method for extracting annotated content from a PDF document, comprising the following steps:
[0005] S1. Start the PDF document annotation content extraction process and initialize the extraction parameters and target document configuration;
[0006] S2. Traverse all pages of the target PDF document and obtain various annotation data contained in the pages;
[0007] S3. Classify and preprocess the acquired annotation data according to the annotation type;
[0008] S4. Write all the preprocessed comments into the preset area of the target document as corresponding page elements;
[0009] S5. Automatically generate a new PDF page based on the preprocessed annotation data. The size of the new PDF page is adapted to the display requirements of the annotation content.
[0010] S6. Automatically arrange multiple new PDF pages according to preset rules and calculate the display position of each page. Supports summarizing and merging the annotation content of multiple pages into the same target document.
[0011] S7. Translate the summary titles of the target document into multiple languages, adaptively adjust the display format of the translated titles according to the page size of the target document, and output them in multiple languages.
[0012] Preferably, in step S1, when starting the extraction process, the path information of the target PDF document is first loaded and the document integrity is verified. After confirming that the document is undamaged and can be parsed normally, the extraction parameters are initialized, including the annotation extraction range, data storage format, and temporary file save path. At the same time, the target document parameters are configured, including the default format of the target document, initial page size, margin settings, default font style, and default language for multilingual output. The parameter configuration supports user customization and modification, and the modified parameters are synchronized to the extraction process in real time.
[0013] Preferably, in step S2, when traversing all pages of the target PDF document, a page-by-page scanning method is adopted. First, the total number of pages in the PDF document, the size parameters of each page, and the page encoding format are identified. Then, by calling the annotation extraction function of the PDF parsing interface, the original data corresponding to various annotations on each page are accurately obtained. The original data includes the unique identifier ID of the annotation, the page number to which it belongs, the coordinate range in the page, the style attributes, the vertex coordinate set or path description information of the graphic annotation, the text paragraph index and character offset associated with the text mark annotation, the trajectory point sequence of pencil or handwritten annotation, the text content of the text box annotation, and the image data stream of the signature annotation. The obtained original data is verified for integrity, invalid data is removed, and the valid data is stored in a temporary database and a data index is established.
[0014] Preferably, in step S3, during the classification preprocessing, the annotation data is first filtered and classified according to type; different processing logic is adopted for the characteristics of different types of annotations to ensure that the preprocessed data meets the display and printing requirements of the target document, and retains the core features and relationships of the original annotations without changing the original semantics and key attributes of the annotations.
[0015] Preferably, in step S3, data preprocessing is divided into:
[0016] The preprocessing of graphic annotations includes: identifying the specific type of graphic annotation and extracting the original size parameters, comparing the target document with the original PDF page size to calculate the scaling ratio, adjusting according to the original size or scaling, writing it into the target document page in the form of a path, with the path style attributes consistent with the original annotation, and recording the hierarchical information.
[0017] The preprocessing of text markup annotations includes: locating related text segments by position coordinate range, extracting text content and format attributes and recording segment position information, splitting the text according to the original text's natural segmentation form and adding markup type identifiers, and finally writing it into the target document page according to the relative position relationship, automatically wrapping when it exceeds the width;
[0018] Preprocessing of pencil or handwritten annotations includes: dividing the original PDF page into rectangular areas, analyzing the trajectory point sequence to determine continuous annotations, generating continuous trajectory curves by merging trajectories while preserving the original shape, and adding them to the target document page in the form of paths.
[0019] Preferably, in step S4, writing the annotation content in the form of page elements specifically includes: writing graphic annotations and handwritten annotations in the form of path elements, with the path elements stored as PDF standard path objects; writing the text content of text mark annotations and text box annotations in the form of text elements, and associating them with corresponding font files, character encoding formats, and style parameters; writing image-type annotations such as signature annotations in the form of image elements; during the writing process, page coordinate calibration is used to ensure that the actual print size of the annotation elements is consistent with the screen display size, and boundary detection is used to determine whether the annotation elements exceed the page print boundary, and annotation elements that exceed the boundary are adjusted.
[0020] Preferably, in step S5, when automatically generating a new PDF page, the minimum size required for the page is calculated by dynamically generating the page size, statistically analyzing the total area occupied by the annotation content on a single page, the number of annotation elements, and their distribution density.
[0021] Preferably, in step S6, the automatic arrangement according to preset rules includes two optional methods:
[0022] S61. Before the extraction process starts, the user selects or defaults to grouping and arranging by annotation type; when automatically calculating the page display position, a greedy algorithm is used to optimize the page layout, arranging the annotation elements in descending order of area, and prioritizing the display of important annotations in the visual center area of the page.
[0023] S62. When multiple pages are summarized and merged into the same target document, a document table of contents is automatically generated, supporting navigation through table of contents entries. Page numbers, document names, and extraction timestamps are added to the footer of each annotated page.
[0024] Preferably, in step S7, a pre-built multilingual translation dictionary and a professional terminology translation library are constructed, covering commonly used languages and professional terms related to PDF annotations; the summary title is translated by combining machine translation with human proofreading rules; when the page display is adjusted adaptively, the font size, line spacing, and arrangement of the title are adjusted according to the character length and font characteristics of the target language.
[0025] Preferably, a system for extracting annotation content from PDF documents includes an annotation content extraction flow module, a PDF page annotation data acquisition module, an annotation data classification and preprocessing module, an annotation content page element writing module, a new PDF page dynamic generation module, a multi-page layout summary and archiving module, and a multi-language title adaptation output module.
[0026] Compared with the prior art, the beneficial effects of the present invention are:
[0027] 1. This invention can achieve one-click automated extraction of annotation content from different PDF documents, is applicable to multiple annotation types, and improves information extraction efficiency;
[0028] 2. This invention effectively ensures the accuracy of the restored annotation content and the true reproduction of the layout, supporting document archiving and information summarization needs;
[0029] 3. The present invention has a clear structure, flexible processing, and high scalability, and can be easily applied to various scenarios such as OA, education, and knowledge management. Attached Figure Description
[0030] Figure 1 The following is the operational flow of a method for extracting annotated content from a PDF document according to the present invention. Figure 1 ;
[0031] Figure 2 The following is the operational flow of a method for extracting annotated content from a PDF document according to the present invention. Figure 2 ;
[0032] Figure 3 This is a schematic diagram of the structure of a system for extracting annotated content from PDF documents according to the present invention. Detailed Implementation
[0033] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0034] Example
[0035] Please see Figures 1-3 As shown, the present invention provides a technical solution comprising the following steps:
[0036] S1. Start the PDF document annotation content extraction process and initialize the extraction parameters and target document configuration;
[0037] S2. Traverse all pages of the target PDF document and obtain various annotation data contained in the pages;
[0038] S3. Classify and preprocess the acquired annotation data according to the annotation type;
[0039] S4. Write all the preprocessed comments into the preset area of the target document as corresponding page elements;
[0040] S5. Automatically generate a new PDF page based on the preprocessed annotation data. The size of the new PDF page is adapted to the display requirements of the annotation content.
[0041] S6. Automatically arrange multiple new PDF pages according to preset rules and calculate the display position of each page. Supports summarizing and merging the annotation content of multiple pages into the same target document.
[0042] S7. Translate the summary titles of the target document into multiple languages, adaptively adjust the display format of the translated titles according to the page size of the target document, and output them in multiple languages.
[0043] In this embodiment, in step S1, when starting the extraction process, the path information of the target PDF document is first loaded and the document integrity is verified. After confirming that the document is not damaged and can be parsed normally, the extraction parameters are initialized, including the annotation extraction range, data storage format, and temporary file save path.
[0044] Specifically, the target document parameters are configured, including the default format of the target document, initial page size, margin settings, default font style, and default language for multilingual output. The parameter configuration supports user customization and modification, and the modified parameters are synchronized to the extraction process in real time.
[0045] In this embodiment, in step S2, when traversing all pages of the target PDF document, a page-by-page scanning method is adopted. First, the total number of pages in the PDF document, the size parameters of each page, and the page encoding format are identified. Then, by calling the annotation extraction function of the PDF parsing interface, the original data corresponding to various annotations on each page are accurately obtained.
[0046] Specifically, the raw data includes the unique identifier ID of the annotation, the page number to which it belongs, the coordinate range in the page, style attributes, the vertex coordinate set or path description information of the graphic annotation, the text paragraph index and character offset associated with the text mark annotation, the trajectory point sequence of pencil or handwritten annotation, the text content of the text box annotation and the image data stream of the signature annotation; the obtained raw data is verified for integrity, invalid data is removed, and the valid data is stored in a temporary database and a data index is established.
[0047] In this embodiment, during the classification preprocessing in step S3, the annotation data is first filtered and classified by type to ensure that annotation data of the same type are processed centrally; different processing logic is adopted for the characteristics of different types of annotations to ensure that the preprocessed data meets the display and printing requirements of the target document, and retains the core features and relationships of the original annotations without changing the original semantics and key attributes of the annotations.
[0048] In this embodiment, the data preprocessing in step S3 is divided into:
[0049] The preprocessing of graphic annotations includes: identifying the specific type of graphic annotation and extracting the original size parameters, comparing the target document with the original PDF page size to calculate the scaling ratio, adjusting according to the original size or scaling, and writing it into the target document page in the form of a path. The path style attributes are consistent with the original annotation, and the hierarchical information is recorded to avoid overlapping and occlusion.
[0050] The preprocessing of text markup annotations includes: locating related text segments by position coordinate range, extracting text content and format attributes and recording segment position information, splitting the text according to the original text's natural segmentation form and adding markup type identifiers, and finally writing it into the target document page according to the relative position relationship, automatically wrapping when it exceeds the width;
[0051] Preprocessing of pencil or handwritten annotations includes: dividing the original PDF page into rectangular areas, analyzing the trajectory point sequence to determine continuous annotations, generating continuous trajectory curves by merging trajectories while preserving the original shape, and adding them to the target document page in the form of paths, ensuring that the position is consistent with the original page.
[0052] In this embodiment, step S4, writing the annotation content in the form of page elements, specifically includes: writing graphic annotations and pencil or handwritten annotations in the form of path elements, with the path elements stored as PDF standard path objects; writing the text content of text mark annotations and text box annotations in the form of text elements, and associating them with the corresponding font files, character encoding formats, and style parameters.
[0053] Specifically, image-based annotations such as signatures and notes are written as image elements, supporting alpha channels and standard encoding. During the writing process, page coordinate calibration is used to ensure that the actual print size of the annotation element is consistent with the screen display size. Boundary detection is used to determine whether the annotation element exceeds the page print boundary, and annotation elements that exceed the boundary are adjusted.
[0054] In this embodiment, during step S5, when automatically generating a new PDF page, the total area occupied by the annotation content on a single page, the number of annotation elements, and their distribution density are statistically analyzed to calculate the minimum size required for the page, ensuring the printability and versatility of the page.
[0055] In this embodiment, step S6, which involves automatically arranging elements according to preset rules, includes two optional methods:
[0056] S61. Before the extraction process starts, the user selects or defaults to grouping and arranging by annotation type; when automatically calculating the page display position, a greedy algorithm is used to optimize the page layout, arranging the annotation elements in descending order of area, and prioritizing the display of important annotations in the visual center area of the page.
[0057] S62. When multiple pages are summarized and merged into the same target document, a document table of contents is automatically generated, supporting navigation through table of contents entries. Page numbers, document names, and extraction timestamps are added to the footer of each annotated page.
[0058] In this embodiment, in step S7, a pre-built multilingual translation dictionary and a professional terminology translation library are constructed, covering commonly used languages and related professional terms annotated in PDFs; the summary titles are translated by combining machine translation with human proofreading rules to ensure the accuracy and consistency of terminology translation.
[0059] Specifically, when adjusting the adaptive page display, the font size, line spacing, and arrangement of the title are adjusted according to the character length and font characteristics of the target language; it supports users to customize the target language, and can also automatically recognize the user's system language and output the corresponding multilingual title by default.
[0060] In this embodiment, a system for extracting annotation content from PDF documents includes an annotation content extraction flow module, a PDF page annotation data acquisition module, an annotation data classification and preprocessing module, an annotation content page element writing module, a new PDF page dynamic generation module, a multi-page layout summary and archiving module, and a multi-language title adaptation output module.
[0061] Working principle: After starting the PDF annotation extraction process, the path information of the target PDF document is loaded first to verify the integrity of the document and confirm that the document is not damaged and can be parsed normally, so as to avoid the extraction being interrupted due to document abnormalities. Then, the extraction parameters such as the annotation extraction range and data storage format are initialized. At the same time, the default format, page size, margins and other core parameters of the target document are configured. Users can customize and modify the parameters according to their actual needs, and the modified parameters are synchronized to the entire extraction process in real time.
[0062] The target PDF document is traversed page by page. First, basic information such as the total number of pages, page size, and encoding format are identified to clarify the document structure. Then, by calling the annotation extraction function of the PDF parsing interface, the original data of various annotations on each page is accurately captured, covering key information such as annotation identifiers, locations, attributes, and core content. Next, the original data undergoes integrity verification, invalid data is removed, and valid data is stored in a temporary database and indexed. Valid annotation data is first filtered and categorized according to annotation type to achieve centralized processing of similar annotations, improving processing efficiency. Differentiated processing logic is developed for the characteristics of different annotation types, strictly preserving the core features, relationships, and original semantics of the original annotations during processing, without changing key attributes. For graphic annotations, the specific type is first identified and the original size parameters are extracted. The scaling ratio is calculated by comparing the target document with the original PDF page size. The original size is preserved or adjusted proportionally as needed. The annotation is then written to the target page in path form, and hierarchical information is recorded to avoid element overlap. For text annotations, related text segments are located by position coordinates. After extracting content and format attributes, the segments are divided according to their original segmentation and labeled. The annotations are written to the target page in relative position, with automatic line breaks when the width is exceeded. For pencil or handwritten annotations, the original PDF page is first divided into rectangular areas. The trajectory point sequence is analyzed to determine continuous annotations. Continuous curves are generated by merging trajectories while preserving the original shape. These curves are then added to the target page in path form. The appropriate page element format is selected based on the annotation type. The writing process involves storing graphic and handwritten annotations as path elements in the standard PDF path object format, text annotations as text elements with associated font, encoding, and style parameters, and image annotations as image elements supporting alpha channels, stored according to standard encoding. During the writing process, page coordinate calibration technology ensures that the actual print size of the annotation elements matches the screen display size. Boundary detection is used to determine if annotations exceed the print boundaries, and adjustments are made for any excess portions. Key data such as the total area occupied by annotation content on a single page, the number of annotation elements, and their distribution density are statistically analyzed, and the minimum page size is dynamically calculated based on this data. Two optional layout methods are provided: grouped by annotation type and default layout, which users can choose in advance. The page display is automatically calculated. The layout is optimized using a greedy algorithm, arranging annotation elements from largest to smallest area to ensure uniform spacing and no overlap, while prioritizing important annotations in the visual center of the page. When multiple pages of annotations are compiled and merged into the same target document, a jumpable table of contents containing page titles, page numbers, and other information is automatically generated, and page numbers, document names, and extraction timestamps are added to the footer of each annotation page. A pre-built multilingual translation dictionary and PDF annotation terminology translation library are used, employing a combination of machine translation and human proofreading rules to translate the compiled titles, ensuring the accuracy and consistency of terminology translation. The font size, line spacing, and arrangement of the titles are adjusted according to the character length and font characteristics of the target language to achieve adaptive adaptation between the titles and the page size.It supports user-defined target language selection and can also automatically recognize the user's system language and output the corresponding language title by default.
[0063] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their likenesses.
[0064] The present invention and its embodiments have been described above. This description is not restrictive, and the accompanying drawings are only one embodiment of the present invention; the actual structure is not limited thereto. In conclusion, if those skilled in the art are inspired by this description and design similar structures and embodiments without departing from the spirit of the invention, such designs should fall within the protection scope of the present invention.
Claims
1. A method for extracting annotated content from a PDF document, characterized in that, Includes the following steps: S1. Start the PDF document annotation content extraction process and initialize the extraction parameters and target document configuration; S2. Traverse all pages of the target PDF document and obtain various annotation data contained in the pages; S3. Classify and preprocess the acquired annotation data according to the annotation type; S4. Write all the preprocessed comments into the preset area of the target document as corresponding page elements; S5. Automatically generate a new PDF page based on the preprocessed annotation data. The size of the new PDF page is adapted to the display requirements of the annotation content. S6. Automatically arrange multiple new PDF pages according to preset rules and calculate the display position of each page. Supports summarizing and merging the annotation content of multiple pages into the same target document. S7. Translate the summary titles of the target document into multiple languages, adaptively adjust the display format of the translated titles according to the page size of the target document, and output them in multiple languages.
2. The method for extracting annotated content from a PDF document according to claim 1, characterized in that: In step S1, when starting the extraction process, the path information of the target PDF document is first loaded and the document integrity is verified. After confirming that the document is not damaged and can be parsed normally, the extraction parameters are initialized, including the annotation extraction range, data storage format, and temporary file save path. At the same time, the target document parameters are configured, including the default format of the target document, initial page size, margin settings, default font style, and default language for multilingual output. The parameter configuration supports user customization and modification, and the modified parameters are synchronized to the extraction process in real time.
3. The method for extracting annotated content from a PDF document according to claim 2, characterized in that: In step S2, a page-by-page scanning method is used when traversing all pages of the target PDF document. First, the total number of pages in the PDF document, the size parameters of each page, and the page encoding format are identified. Then, the annotation extraction function of the PDF parsing interface is called to accurately obtain the original data corresponding to various annotations on each page. The original data includes the unique identifier ID of the annotation, the page number to which it belongs, the coordinate range in the page, the style attributes, the vertex coordinate set of the graphic annotation, the text paragraph index and character offset associated with the text mark annotation, the trajectory point sequence of the handwritten annotation, the text content of the text box annotation, and the image data stream of the signature annotation. The obtained original data is verified for integrity, invalid data is removed, and the valid data is stored in a temporary database and a data index is established.
4. The method for extracting annotated content from a PDF document according to claim 3, characterized in that: In S3, during the classification preprocessing, the annotation data is first filtered and classified according to type; different processing logic is adopted for the characteristics of different types of annotations to ensure that the preprocessed data meets the display and printing requirements of the target document, and retains the core features and relationships of the original annotations without changing the original semantics and key attributes of the annotations.
5. The method for extracting annotated content from a PDF document according to claim 4, characterized in that: In step S3, data preprocessing is divided into: The preprocessing of graphic annotations includes: identifying the specific type of graphic annotation and extracting the original size parameters, comparing the target document with the original PDF page size to calculate the scaling ratio, adjusting according to the original size or scaling, writing it into the target document page in the form of a path, with the path style attributes consistent with the original annotation, and recording the hierarchical information. The preprocessing of text markup annotations includes: locating related text fragments by position coordinate range, extracting text content and format attributes and recording segment position information, splitting the text according to the original text's natural segmentation form and adding markup type identifiers, and finally writing it into the target document page according to the relative position relationship, automatically wrapping when it exceeds the width; Preprocessing of pencil or handwritten annotations includes: dividing the original PDF page into rectangular areas, analyzing the trajectory point sequence to determine continuous annotations, generating continuous trajectory curves by merging trajectories while preserving the original shape, and adding them to the target document page in the form of paths.
6. The method for extracting annotated content from a PDF document according to claim 5, characterized in that: In step S4, writing the annotation content in the form of page elements specifically includes: writing graphic annotations and handwritten annotations in the form of path elements, which are stored as PDF standard path objects; writing the text content of text mark annotations and text box annotations in the form of text elements, and associating them with corresponding font files, character encoding formats, and style parameters; writing image-type annotations such as signature annotations in the form of image elements; during the writing process, page coordinate calibration is used to ensure that the actual print size of the annotation elements is consistent with the screen display size, and boundary detection is used to determine whether the annotation elements exceed the page print boundary, and annotation elements that exceed the boundary are adjusted.
7. The method for extracting annotated content from a PDF document according to claim 6, characterized in that: In step S5, when automatically generating a new PDF page, the minimum size required for the page is calculated by dynamically generating the page size, calculating the total area occupied by the annotation content on a single page, the number of annotation elements, and their distribution density.
8. The method for extracting annotated content from a PDF document according to claim 7, characterized in that: In step S6, the automatic arrangement according to preset rules includes two optional methods: S61. Before the extraction process starts, the user selects to group and arrange the annotations by type. When automatically calculating the page display position, the page layout is optimized, and the annotation elements are arranged in descending order of area, giving priority to displaying important annotations in the visual center area of the page. S62. When multiple pages are summarized and merged into the same target document, a document table of contents is automatically generated, supporting navigation through table of contents entries. Page numbers, document names, and extraction timestamps are added to the footer of each annotated page.
9. The method for extracting annotated content from a PDF document according to claim 8, characterized in that: In S7, a pre-built multilingual translation dictionary and a professional terminology translation library are constructed, covering commonly used languages and related professional terms annotated in PDFs. The summary titles are translated using a combination of machine translation and human proofreading rules; when adjusting the page display to adapt to the target language, the font size, line spacing, and arrangement of the titles are adjusted according to the character length and font characteristics of the target language.
10. A system for extracting annotated content from a PDF document according to the method of claim 9, characterized in that: It includes modules for extracting annotation content, acquiring PDF page annotation data, classifying and preprocessing annotation data, writing annotation content page elements, dynamically generating new PDF pages, summarizing and archiving multi-page layouts, and adapting and outputting multilingual titles.