PDF-to-Word header and footer extraction method and device and computer readable storage medium

By pre-processing and judging the header and footer type of PDF files, the problem of extracting header and footer content in PDF files is solved, and the effect of correctly rendering header and footer in Word files is achieved.

CN119272716AActive Publication Date: 2025-01-07SICHUAN LAN-BRIDGE INFORMATION TECHNOLOGY CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411450003.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-17
Publication Date
2025-01-07
Estimated Expiration
2044-10-17

AI Technical Summary

Technical Problem

In the process of converting PDF files to Word files, how to effectively identify and extract the header and footer content in PDF format is an urgent problem that needs to be solved because the concept of header and footer settings in Word files is lacking in PDF format.

Method used

By pre-processing the PDF file, splitting the page, identifying the valid areas of the header and footer, and determining the header and footer types based on the index comparison of common elements, including type A (same per page) and type C ( Parity pages are different), thus achieving efficient extraction of headers and footers.

Benefits of technology

It realizes accurate identification and extraction of headers and footers in PDF files, ensures the correct presentation of headers and footers in converted Word files, and improves the efficiency and accuracy of file conversion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119272716A_ABST
    Figure CN119272716A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of PDF file analysis, and provides a PDF-to-Word header and footer extraction method and device and a computer readable storage medium, and the method comprises the following steps: S1, carrying out pre-processing on a PDF file, completing nesting of characters and graphs, layout processing and element sorting, and obtaining a PDF pre-processing file with ordered contents on each page; s2, page splitting: splitting the PDF preprocessing file into odd-number page files and even-number page files; s3, identifying and delimiting effective areas of page headers and page footers of each page of file; s4, in the effective area, matching the public elements of each page from the second page, and judging the header and footer types of the PDF page; s5, judging header and footer types of all the pages; and S6, generating header and footer information of each page according to the header and footer types of all the pages, and realizing header and footer extraction. According to the method, the page header and the page footer can be identified efficiently.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of PDF file parsing, and in particular, relates to a PDF to Word header and footer extraction method, device and computer-readable storage medium. Background Art

[0002] In the translation industry, parsing and restoring files in various formats is a crucial link. PDF files cannot be directly parsed and restored due to the special format of the files, so during the file parsing process, PDF files need to be converted into Word files.

[0003] Since the concept of setting headers and footers in Word files does not exist in PDF format files, how to identify and extract the actual header and footer content in PDF format files during the process of converting PDF to Word files so that they can be presented as headers and footers in the converted Word files has become a technical problem that urgently needs to be solved in this field. Summary of the invention

[0004] The purpose of the present invention is to provide a method for extracting headers and footers from PDF to Word to solve the technical problems existing in the prior art.

[0005] In order to achieve the above object, the technical solution adopted by the present invention is as follows: A method for extracting headers and footers from PDF to Word, comprising the following steps: Step S1: pre-processing the PDF file to complete the nesting of characters and graphics, layout processing and element sorting, and obtain a PDF pre-processing file with orderly content on each page; Step S2: Page splitting: splitting the PDF pre-processed file into odd-numbered page files and even-numbered page files; Step S3: Identify and delimit the valid area of ​​the header and footer of each page of the document; Step S4: In the valid area, match the common elements of each page starting from the second page, and determine the header and footer types of the PDF page. The header and footer types include type A and type C, where type A means that the header and footer of each page are the same, and type C means that the header and footer of the odd and even pages are different; wherein, the method for determining the header and footer type is as follows: (41) During the matching process, if the indexes of the common elements between each page are the same, it is determined that the header and footer type in the current PDF file is type A, that is, the header and footer of each page are the same; (42) During the matching process, if the common elements of a certain page are different from the previous matching results, the matching is terminated. Then, the odd pages are used alone for matching, and the even pages are used alone for matching. If the indexes of the common elements of all odd pages are the same, and the indexes of the common elements of the even pages are also the same, then it is determined that the header and footer type in the current PDF file is type C, that is, the headers and footers of odd and even pages are different; (43) If (41) or (42) is not satisfied, it is determined that there is no header or footer in the current PDF file; Step S5: Determine the header and footer types of all pages: (51) If it is determined according to step S4 that the header and footer types of the current PDF page are type A, then determine whether the common elements of the first page and the second page of the PDF file are the same. If they are the same, then determine that the header and footer types of all pages of the PDF file are type A. If they are not the same, then determine that the header and footer types of all pages of the PDF file are type A and type B, where type B means that the header and footer of the first page are different. (52) If it is determined according to step S4 that the header and footer types of the current PDF page are type C, then determine whether the common elements of the first page and the third page of the PDF file are the same. If they are the same, then determine that the header and footer types of all pages of the PDF file are type C. If they are not the same, then determine that the header and footer types of all pages of the PDF file are type C and type B, where type B means that the header and footer of the first page are different.

[0006] Step S6: Generate header and footer information for each page according to the header and footer types of all pages to achieve header and footer extraction.

[0007] In one embodiment, the effective area in step S3 is no more than 1 / 3 of the page height.

[0008] In one embodiment, in step S4, the common element refers to: under the same index, if the elements have the same type and the same value, they are common elements.

[0009] In one embodiment, the different matching results in (42) refer to different common elements between any three pages.

[0010] In one embodiment, in step S4, the matching method is as follows: after sorting the elements, traverse from the beginning to the end, compare the data with the same index based on the index to see if they are the same, and extract the index positions of all pages with the same elements.

[0011] In order to achieve the above-mentioned object, the present invention also provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement the PDF to Word header and footer extraction method.

[0012] In order to achieve the above-mentioned purpose, the present invention also provides a PDF to Word header and footer extraction device, comprising: a processor and a memory; the memory is used to store a computer program; the processor is connected to the memory, and is used to execute the computer program stored in the memory, so that the PDF to Word header and footer extraction device executes the PDF to Word header and footer extraction method.

[0013] Compared with the prior art, the present invention has the following beneficial effects: The present invention extracts the common elements of each page by judging whether the elements at the same index position are the same, and determines the types of headers and footers by distinguishing the common elements of the home page, odd pages and even pages, thereby realizing efficient recognition of headers and footers. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 This is a schematic diagram of the process of Example 1 of the present invention.

[0015] Figure 2 This is a principle block diagram of Example 3 of the present invention. DETAILED DESCRIPTION

[0016] In order to enable those skilled in the art to have a clearer understanding and knowledge of the present invention, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described below are only used to explain the present invention, and are convenient for understanding. The technical solutions provided by the present invention are not limited to the technical solutions provided by the following embodiments, and the technical solutions provided by the embodiments should not limit the protection scope of the present invention.

[0017] It should be noted that the illustrations provided in the following embodiments are only used to illustrate the basic concept of the present invention in a schematic manner. Therefore, the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the form, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0018] Example 1 like Figure 1 As shown, this embodiment provides a method for extracting headers and footers from PDF to Word, the principle of which is as follows: by judging whether the elements at the same index position are the same, the common elements of each page are extracted, and the types of headers and footers are determined by distinguishing the common elements of the first page, odd pages, and even pages, thereby achieving efficient recognition of headers and footers.

[0019] The specific steps of the method provided in this embodiment are as follows: 1. Step S1: Pre-process the PDF file Through a series of pre-processing, the nesting, layout processing and element sorting of characters and graphics are completed. After the nesting, layout processing and element sorting of characters and graphics are completed, a PDF pre-processing file with orderly content on each page is obtained; the pre-processing is to determine the relationship between characters and graphics based on the operator information of PDF, so as to determine the overall layout and nesting relationship.

[0020] 2. Step S2: Page Splitting The PDF pre-processed file is split into odd-numbered page files and even-numbered page files; the splitting method is a conventional technical method, so it will not be described in detail here.

[0021] Step S3: Identify and define the valid area of ​​the header and footer of each page of the document The effective area recognition of the header and footer lays the foundation for subsequent processing. As a preferred embodiment, the effective area is no more than 1 / 3 of the page height. The technical feature of this limitation is based on the premise that the technical solution of this application needs to complete the header and footer recognition. The inventor of this application has concluded through a large number of document tests that the range of no more than 1 / 3 of the page height is the most appropriate range.

[0022] Step S4: Extract common elements of the page and determine the header and footer types Common elements refer to: under the same index, if the element type and value are the same, they are common elements. Headers and footers are usually basically present on every page and are roughly the same (except for the page number), so the common elements here are the same parts on every page and can be considered as part of the header and footer; In the valid area, match the common elements of each page starting from the second page, and determine the header and footer types of the PDF page (PDF pages other than the first page); the matching method is as follows: sort the elements, traverse from the beginning to the end, compare the data with the same index based on the index to see if they are the same, and extract the index positions of all pages with the same elements; the header and footer types include type A and type C, where type A means that the header and footer of each page are the same, and type C means that the header and footer of the odd and even pages are different; This step determines the type of header and footer mainly for PDF pages other than the home page. The method is as follows: (41) During the matching process, if the index of the common elements between each page is the same, the header and footer type in the current PDF file is judged to be type A, that is, the header and footer of each page are the same; for example; if the first 0 to 3 elements of the first page are the same as the first 0 to 3 elements of each subsequent page, then it proves that these elements can be extracted into the header, because in docx, the data in the header can be displayed on each page, so if they are common elements that exist on each page, then they can be considered to belong to the header or footer; (42) During the matching process, if the common elements of a page are different from the previous matching results, the matching is terminated, and then the odd pages are used alone for matching, and the even pages are used alone for matching. If the indexes of the common elements of all odd pages are the same, and the indexes of the common elements of the even pages are the same, then the indexes of the common elements of the even pages are the same. If the header and footer of the second and third pages are the same, then the header and footer type in the current PDF file is determined to be type C, that is, the header and footer of the odd and even pages are different; wherein, different matching results refer to that the common elements between any three pages are different, for example: if the first three elements of the second and third pages are the same, but when comparing the second and fourth pages, it is found that only the first two elements are the same, then the third element that is the same between the second and third pages will not be the header, because it does not exist in the fourth page, so the matching needs to be terminated at this time; (43) If (41) or (42) is not satisfied, then it is determined that there is no header and footer in the current PDF file; Step S5: Determine the header and footer types of all pages This step is based on the judgment result of step S4 to judge the header and footer of the PDF homepage, thereby judging the header and footer of all PDF pages, which includes the following two situations: (51) If it is determined according to step S4 that the header and footer type of the current PDF page (the current page is any one of the first page and the second page) is type A, then it is determined whether the common elements of the first page and the second page of the PDF file are the same. If they are the same, then it is determined that the header and footer types of all pages of the PDF file are type A. If they are not the same, then it is determined that the header and footer types of all pages of the PDF file are type A and type B, where type B means that the header and footer of the first page are different, that is, the header and footer of the first page are different, and the headers and footers of the other pages are the same; (53) If it is determined according to step S4 that the header and footer types of the current PDF page are type C, then determine whether the common elements of the first page and the third page of the PDF file are the same. If they are the same, then determine that the header and footer types of all pages of the PDF file are type C. If they are not the same, then determine that the header and footer types of all pages of the PDF file are type C and type B, where type B means that the header and footer of the first page are different, that is, the header and footer of the first page are different, and the headers and footers of the odd and even pages of the remaining pages are different.

[0023] Step S6: Generate header and footer information for each page to extract header and footer According to the header and footer types of all pages, the header and footer information of each page is generated to realize the header and footer extraction; specifically, after determining the header and footer type and header and footer elements, the header and footer information of each page is generated through the Java open source framework POI according to the OOXML specification.

[0024] Example 2 This embodiment provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the PDF to Word header and footer extraction method provided in Embodiment 1. A person skilled in the art can understand that all or part of the steps of implementing the method provided in Embodiment 1 can be completed by hardware related to the computer program, and the above-mentioned computer program can be stored in a computer-readable storage medium, and when the program is executed, the steps of the method provided in Embodiment 1 are executed; and the above-mentioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.

[0025] Example 3 like Figure 2 As shown, this embodiment provides a PDF to Word header and footer extraction device, including: a processor and a memory; the memory is used to store a computer program; the processor is connected to the memory, and is used to execute the computer program stored in the memory, so that the PDF to Word header and footer extraction device executes the PDF to Word header and footer extraction method provided in Example 1.

[0026] Specifically, the memory includes: ROM, RAM, disk, USB flash drive, memory card or CD and other media that can store program codes.

[0027] Preferably, the processor can be a general-purpose processor, including a central processing unit, a network processor, etc.; it can also be a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component.

[0028] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.

Claims

1. A method for extracting headers and footers from PDF to Word, characterized in that: The following steps are involved: Step S1: pre-processing the PDF file to complete the nesting of characters and graphics, layout processing and element sorting, and obtain a PDF pre-processing file with orderly content on each page; Step S2: Page splitting: splitting the PDF pre-processed file into odd-numbered page files and even-numbered page files; Step S3: Identify and delimit the valid area of ​​the header and footer of each page of the document; Step S4: In the valid area, match the common elements of each page starting from the second page, and determine the header and footer types of the PDF page. The header and footer types include type A and type C, where type A means that the header and footer of each page are the same, and type C means that the header and footer of the odd and even pages are different; wherein, the method for determining the header and footer type is as follows: (41) During the matching process, if the indexes of the common elements between each page are the same, it is determined that the header and footer type in the current PDF file is type A, that is, the header and footer of each page are the same; (42) During the matching process, if the common elements of a certain page are different from the previous matching results, the matching is terminated. Then, the odd pages are used alone for matching, and the even pages are used alone for matching. If the indexes of the common elements of all odd pages are the same, and the indexes of the common elements of the even pages are also the same, then it is determined that the header and footer type in the current PDF file is type C, that is, the headers and footers of odd and even pages are different; (43) If (41) or (42) is not satisfied, it is determined that there is no header or footer in the current PDF file; Step S5: Determine the header and footer types of all pages: (51) If it is determined according to step S4 that the header and footer types of the current PDF page are type A, then determine whether the common elements of the first page and the second page of the PDF file are the same. If they are the same, then determine that the header and footer types of all pages of the PDF file are type A. If they are not the same, then determine that the header and footer types of all pages of the PDF file are type A and type B, where type B means that the header and footer of the first page are different. (52) If it is determined according to step S4 that the header and footer types of the current PDF page are type C, then determine whether the common elements of the first page and the third page of the PDF file are the same. If they are the same, then determine that the header and footer types of all pages of the PDF file are type C. If they are not the same, then determine that the header and footer types of all pages of the PDF file are type C and type B, where type B means that the header and footer of the first page are different. Step S6: Generate header and footer information for each page according to the header and footer types of all pages to achieve header and footer extraction.

2. The PDF to Word header and footer extraction method according to claim 1 is characterized in that: The effective area in step S3 is no more than 1 / 3 of the page height.

3. The PDF to Word header and footer extraction method according to claim 2 is characterized in that: In step S4, the common element refers to: under the same index, if the elements have the same type and the same value, they are common elements.

4. The PDF to Word header and footer extraction method according to claim 3 is characterized in that: In step S4, the matching method is as follows: after sorting the elements, traverse from the beginning to the end, compare the data with the same index to see if they are the same, and extract the index positions of all pages with the same elements.

5. The PDF to Word header and footer extraction method according to claim 4 is characterized in that: The different matching results in (42) refer to that the common elements between any three pages are different.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program is executed by a processor to implement the PDF to Word header and footer extraction method according to any one of claims 1 to 5.

7. A PDF to Word header and footer extraction device, characterized in that: include: Processor and memory; The memory is used to store computer programs; The processor is connected to the memory and is used to execute a computer program stored in the memory, so that the PDF to Word header and footer extraction device performs the PDF to Word header and footer extraction method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method for automatically identifying digital document type page

    CN101017479A

  • Recognition method and device for page headers and page footers of format electronic document

    CN104951429A

  • Automatic academic dissertation format detecting method

    CN106886509A

  • Official document processing method and device, computer equipment and storage medium

    CN111680634A

  • Format document odd-even page display adjustment method, device and equipment and storage medium

    CN113253888A