Method and device for identifying page header and page footer of document

By identifying and assigning header footer attribute structural elements, the problem of slow header footer recognition speed in layout electronic documents is solved, and the recognition efficiency and editing and conversion effects of layout electronic documents are improved.

CN119106659APending Publication Date: 2024-12-10ZHUHAI KINGSOFT OFFICE SOFTWARE +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310681818.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-08
Publication Date
2024-12-10

AI Technical Summary

Technical Problem

In the prior art, the recognition speed of headers and footers in layout electronic documents is slow, resulting in inefficiency in scenarios such as conversion, editing and re-type layout of layout electronic documents.

Method used

Quick recognition is achieved by obtaining the page of the document to be identified in the electronic document, identifying and determining the characteristics of all text lines, traversing these features to identify text lines belonging to the header or footer, and assigning them corresponding attribute structure elements.

Benefits of technology

It improves the speed and efficiency of header and footer recognition, and improves the editability and conversion effect of layout electronic documents.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119106659A_ABST
    Figure CN119106659A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a document header and footer identification method and device, and the method comprises the steps: obtaining an electronic document, and determining a to-be-identified document page in the electronic document, the to-be-identified document page being any one document page in the electronic document; identifying all text lines in the to-be-identified document page, and determining respective text line features of all the text lines; traversing the text line features of all the text lines, and executing the following steps: identifying the text lines belonging to the page header, and endowing the text lines belonging to the page header with structural elements with page header attributes; and / or identifying the text line belonging to the footer, and endowing the text line belonging to the footer with the structural element of the footer attribute. Therefore, identification of the page header and the page footer can be realized based on the single document page, less time is consumed, and the identification speed is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a document header and footer recognition method and device. Background Art

[0002] At present, most electronic documents are layout electronic documents mainly in PDF format converted from typesetting tools and typesetting documents. Layout electronic documents have headers and footers. Headers and footers are located at the top and bottom of the page in layout electronic documents respectively, and are usually used to display additional information of layout electronic documents. For example, users can insert document titles, author names, and dates in headers, and can also add page numbers, company addresses, telephone numbers, fax numbers, and other information in footers.

[0003] In some scenarios, such as layout electronic document conversion, layout electronic document editing, layout electronic document rearrangement, etc., it is necessary to automatically identify headers and footers from layout electronic documents. Currently, the recognition of headers and footers in layout electronic documents is usually carried out by identifying whether there are text lines with similar feature values ​​at the top and bottom of multiple pages in the layout electronic document, which makes the recognition of headers and footers take a long time and the recognition speed is slow. Summary of the invention

[0004] In order to solve the above-mentioned technical problem that the current recognition of headers and footers in layout electronic documents usually adopts the method of identifying whether there are text lines with similar feature values ​​at the top and bottom of multiple pages in the layout electronic document, which causes the header and footer recognition to take a long time and the recognition speed is slow, the embodiment of the present invention provides a document header and footer recognition method, device, electronic device and storage medium. The specific technical solution is as follows:

[0005] In a first aspect of an embodiment of the present invention, a method for identifying a header and footer of a document is first provided, the method comprising:

[0006] Acquire an electronic document, and determine a document page to be identified in the electronic document, wherein the document page to be identified is any document page in the electronic document;

[0007] Identify all text lines in the document page to be identified, and determine text line features of all the text lines;

[0008] Traverse the text line features of all the text lines and perform the following steps:

[0009] Identify the text line belonging to the header, and assign the structural element of the header attribute to the text line belonging to the header;

[0010] and / or,

[0011] Identify the text lines that belong to the footer and assign footer attributes to the text lines that belong to the footer.

[0012] In an optional implementation, the determining the document page to be identified in the electronic document includes:

[0013] Parsing the electronic document to obtain all structural elements in the electronic document;

[0014] In the case that all the structural elements contain structural elements with header attributes, a document page to be identified in the electronic document is determined, and a footer identification task is performed for the document page to be identified.

[0015] In an optional implementation, the determining the document page to be identified in the electronic document includes:

[0016] Parsing the electronic document to obtain all structural elements in the electronic document;

[0017] In the case that all the structural elements contain structural elements with footer attributes, a document page to be identified in the electronic document is determined, and a header recognition task is performed on the document page to be identified.

[0018] In an optional implementation, the determining the document page to be identified in the electronic document includes:

[0019] Parsing the electronic document to obtain all structural elements in the electronic document;

[0020] In the case that all the structural elements do not include structural elements with header attributes and structural elements with footer attributes, a document page to be identified in the electronic document is determined, and a header and footer identification task is performed for the document page to be identified.

[0021] In an optional embodiment, the text line feature includes a Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame;

[0022] The identifying of the text line belonging to the header includes:

[0023] When the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame of the text line meets a preset first condition, storing the text line into a header line group;

[0024] From the text lines of the header line group, text lines belonging to a header are identified.

[0025] In an optional implementation, when the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame of the text line meets a preset first condition, storing the text line into the header line group includes:

[0026] Acquire a visible area in the document page to be identified, and determine a circumscribed rectangular frame of the visible area;

[0027] Obtaining the product of the height of the circumscribed rectangular frame of the visible area and a preset ratio to obtain a limiting threshold;

[0028] When the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame of the text line is less than the product of the limit threshold and a preset first value, the text line is stored in the header line group.

[0029] In an optional implementation, before identifying the text lines belonging to the header from the text lines of the header line group, the method further includes:

[0030] Traversing all line segments in the document page to be identified, and storing the line segments that meet the preset line segment conditions into a line segment group;

[0031] Sorting the line segments in the line segment group and determining the line segment ranked first in the line segment group;

[0032] Traversing the line segments in the line segment group, searching for straight lines in the line segment group, and processing the straight lines in the line segment group to obtain a table;

[0033] When the circumscribed rectangular frame of the line segment ranked first is located inside the circumscribed rectangular frame of the table, determining that no header line exists in the document page to be identified;

[0034] When the circumscribed rectangular frame of the line segment ranked first is not located inside the circumscribed rectangular frame of the table, it is determined that there is a header line in the document page to be identified.

[0035] In an optional implementation, identifying the text lines belonging to the header from the text lines of the header line group includes:

[0036] For any of the text lines in the header line group, if any one of the following determination conditions is met, the text line is determined to be a non-header text line; otherwise, the text line is determined to be a header text line:

[0037] There is no header line in the document page to be identified or the header line group is empty;

[0038] The Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the text line is less than an average value, and the average value is an average value between the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the line segment ranked first and the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the line segment ranked first;

[0039] The width of the circumscribed rectangular box of the text line is greater than the width of the circumscribed rectangular box of the line segment ranked first.

[0040] In an optional implementation, storing the line segments meeting the preset line segment conditions into the line segment group includes:

[0041] When the X-axis coordinate value corresponding to the left boundary of the circumscribed rectangular box of the line segment is less than the left boundary threshold, the X-axis coordinate value corresponding to the right boundary of the circumscribed rectangular box of the line segment is greater than the right boundary threshold, and the Y-axis coordinate value corresponding to the starting point of the line segment is consistent with the Y-axis coordinate value corresponding to the end point of the line segment, the line segment is stored in the line segment group;

[0042] Among them, the left boundary threshold is the product of a preset second value and the width of the circumscribed rectangular frame of the visible area in the document page to be identified, and the right boundary threshold is the product of a preset third value and the width of the circumscribed rectangular frame of the visible area in the document page to be identified.

[0043] In an optional implementation, the sorting of the line segments in the line segment group includes:

[0044] The line segments in the line segment group are sorted from small to large according to Y-axis coordinate values ​​corresponding to upper boundaries of circumscribed rectangular boxes of the line segments.

[0045] In an optional implementation, the processing of the straight lines in the line segment group to obtain a table includes:

[0046] Rendering the straight lines in the line segment group to obtain a picture, and searching for all connected domains in the picture;

[0047] From all the connected domains, the connected domain with the largest circumscribed rectangular frame is determined, and dilation and erosion operations are performed on the straight lines in the connected domain with the largest circumscribed rectangular frame to obtain a table.

[0048] In an optional implementation, the text line feature includes a Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame;

[0049] The identifying of the text line belonging to the footer includes:

[0050] When the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame of the text line meets a preset second condition, storing the text line into a footer line group;

[0051] From the text lines of the footer line group, text lines belonging to the footer are identified.

[0052] In an optional implementation, when the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame of the text line meets a preset second condition, storing the text line into the footer line group includes:

[0053] Acquire a visible area in the document page to be identified, and determine a circumscribed rectangular frame of the visible area;

[0054] Obtaining the product of the height of the circumscribed rectangular frame of the visible area and a preset ratio to obtain a limiting threshold;

[0055] Obtaining a coordinate difference between a Y-axis coordinate value corresponding to a lower boundary of a circumscribed rectangular frame of the visible area and a Y-axis coordinate value corresponding to a lower boundary of the circumscribed rectangular frame of the text line;

[0056] When the coordinate difference is smaller than the product of the limit threshold and a preset first value, the text line is stored in a footer line group.

[0057] In an optional implementation, before identifying the text lines belonging to the footer from the text lines of the footer line group, the method further includes:

[0058] Traversing all line segments in the document page to be identified, and storing the line segments that meet the preset line segment conditions into a line segment group;

[0059] Sorting the line segments in the line segment group and determining the line segment ranked last in the line segment group;

[0060] Traversing the line segments in the line segment group, searching for straight lines in the line segment group, and processing the straight lines in the line segment group to obtain a table;

[0061] When the circumscribed rectangular frame of the line segment ranked last is located inside the circumscribed rectangular frame of the table, determining that there is no footer line in the document page to be identified;

[0062] When the circumscribed rectangular frame of the line segment ranked last is not located inside the circumscribed rectangular frame of the table, it is determined that there is a footer line in the document page to be identified.

[0063] In an optional implementation, identifying the text lines belonging to the footer from the text lines of the footer line group includes:

[0064] For any text line in the footer line group, the text line is determined to be a text line belonging to the footer when all of the following conditions are met:

[0065] There is a footer line in the document page to be identified, and the footer line group is not empty;

[0066] The Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the line segment ranked last is smaller than the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the text line;

[0067] The width of the circumscribed rectangular box of the text line is greater than the width of the circumscribed rectangular box of the line segment ranked last.

[0068] In an optional implementation, identifying the text lines belonging to the footer from the text lines of the footer line group includes:

[0069] For any text line in the footer line group, the text line is determined to be a text line belonging to the footer when all of the following conditions are met:

[0070] The number of text lines is 1;

[0071] The number of elements in the text line is less than a preset element number threshold;

[0072] The elements in the text line are numbers.

[0073] In a second aspect of an embodiment of the present invention, a document header and footer recognition device is also provided, the device comprising:

[0074] A document acquisition module, used to acquire electronic documents;

[0075] A page determination module, used to determine a document page to be identified in the electronic document, wherein the document page to be identified is any document page in the electronic document;

[0076] A text line recognition module, used to recognize all text lines in the document page to be recognized;

[0077] A text line feature determination module, used to determine the text line features of all the text lines;

[0078] The text line traversal module is used to traverse the text line features of all the text lines and perform the following steps:

[0079] A header recognition module, used to recognize text lines belonging to the header and assign structural elements of header attributes to the text lines belonging to the header;

[0080] and / or,

[0081] The footer recognition module is used to recognize the text lines belonging to the footer and to assign structural elements of footer attributes to the text lines belonging to the footer.

[0082] In an optional implementation, the page determination module is specifically used to:

[0083] Parsing the electronic document to obtain all structural elements in the electronic document;

[0084] In the case that all the structural elements contain structural elements with header attributes, a document page to be identified in the electronic document is determined, and a footer identification task is performed for the document page to be identified.

[0085] In an optional implementation, the page determination module is specifically used to:

[0086] Parsing the electronic document to obtain all structural elements in the electronic document;

[0087] In the case that all the structural elements contain structural elements with footer attributes, a document page to be identified in the electronic document is determined, and a header recognition task is performed on the document page to be identified.

[0088] In an optional implementation, the page determination module is specifically used to:

[0089] Parsing the electronic document to obtain all structural elements in the electronic document;

[0090] In the case that all the structural elements do not include structural elements with header attributes and structural elements with footer attributes, a document page to be identified in the electronic document is determined, and a header and footer identification task is performed for the document page to be identified.

[0091] In an optional embodiment, the text line feature includes a Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame;

[0092] The header recognition module specifically includes:

[0093] A text line storage first submodule is used to store the text line into a header line group when the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame of the text line meets a preset first condition;

[0094] The header identification submodule is used to identify the text lines belonging to the header from the text lines in the header line group.

[0095] In an optional implementation manner, the text line is stored in the first submodule specifically for:

[0096] Acquire a visible area in the document page to be identified, and determine a circumscribed rectangular frame of the visible area;

[0097] Obtaining the product of the height of the circumscribed rectangular frame of the visible area and a preset ratio to obtain a limiting threshold;

[0098] When the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame of the text line is less than the product of the limit threshold and a preset first value, the text line is stored in the header line group.

[0099] In an optional embodiment, the device further comprises:

[0100] A line segment storage module, used for traversing all line segments in the document page to be identified, and storing the line segments meeting the preset line segment conditions into a line segment group;

[0101] A line segment sorting module, used for sorting the line segments in the line segment group and determining the line segment ranked first in the line segment group;

[0102] A straight line search module, used for traversing the line segments in the line segment group and searching for straight lines in the line segment group;

[0103] A straight line processing module, used for processing the straight lines in the line segment group to obtain a table;

[0104] A first module for determining a header line, configured to determine that no header line exists in the document page to be identified when the circumscribed rectangular frame of the line segment ranked first is located inside the circumscribed rectangular frame of the table;

[0105] The second module for determining a header line is used to determine that a header line exists in the document page to be identified when the circumscribed rectangular frame of the line segment ranked first is not located within the circumscribed rectangular frame of the table.

[0106] In an optional implementation, the header identification submodule is specifically used for:

[0107] For any of the text lines in the header line group, if any one of the following determination conditions is met, the text line is determined to be a non-header text line; otherwise, the text line is determined to be a header text line:

[0108] There is no header line in the document page to be identified or the header line group is empty;

[0109] The Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the text line is less than an average value, and the average value is an average value between the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the line segment ranked first and the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the line segment ranked first;

[0110] The width of the circumscribed rectangular box of the text line is greater than the width of the circumscribed rectangular box of the line segment ranked first.

[0111] In an optional implementation, the line segment storage module is specifically used for:

[0112] When the X-axis coordinate value corresponding to the left boundary of the circumscribed rectangular box of the line segment is less than the left boundary threshold, the X-axis coordinate value corresponding to the right boundary of the circumscribed rectangular box of the line segment is greater than the right boundary threshold, and the Y-axis coordinate value corresponding to the starting point of the line segment is consistent with the Y-axis coordinate value corresponding to the end point of the line segment, the line segment is stored in the line segment group;

[0113] Among them, the left boundary threshold is the product of a preset second value and the width of the circumscribed rectangular frame of the visible area in the document page to be identified, and the right boundary threshold is the product of a preset third value and the width of the circumscribed rectangular frame of the visible area in the document page to be identified.

[0114] In an optional implementation, the line segment sorting module is specifically used to:

[0115] The line segments in the line segment group are sorted from small to large according to Y-axis coordinate values ​​corresponding to upper boundaries of circumscribed rectangular boxes of the line segments.

[0116] In an optional implementation, the straight line processing module is specifically used to:

[0117] Rendering the straight lines in the line segment group to obtain a picture, and searching for all connected domains in the picture;

[0118] From all the connected domains, the connected domain with the largest circumscribed rectangular frame is determined, and dilation and erosion operations are performed on the straight lines in the connected domain with the largest circumscribed rectangular frame to obtain a table.

[0119] In an optional implementation, the text line feature includes a Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame;

[0120] The footer identification module includes:

[0121] A second submodule for storing text lines is used to store the text line into a footer line group when the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame of the text line meets a preset second condition;

[0122] The footer identification submodule is used to identify the text lines belonging to the footer from the text lines in the footer line group.

[0123] In an optional implementation manner, the text line is stored in the second submodule specifically for:

[0124] Acquire a visible area in the document page to be identified, and determine a circumscribed rectangular frame of the visible area;

[0125] Obtaining the product of the height of the circumscribed rectangular frame of the visible area and a preset ratio to obtain a limiting threshold;

[0126] Obtaining a coordinate difference between a Y-axis coordinate value corresponding to a lower boundary of a circumscribed rectangular frame of the visible area and a Y-axis coordinate value corresponding to a lower boundary of the circumscribed rectangular frame of the text line;

[0127] When the coordinate difference is smaller than the product of the limit threshold and a preset first value, the text line is stored in a footer line group.

[0128] In an optional embodiment, the device comprises:

[0129] A line segment storage module, used for traversing all line segments in the document page to be identified, and storing the line segments meeting the preset line segment conditions into a line segment group;

[0130] A line segment sorting module, used for sorting the line segments in the line segment group and determining the line segment ranked last in the line segment group;

[0131] A straight line search module, used for traversing the line segments in the line segment group and searching for straight lines in the line segment group;

[0132] A straight line processing module, used for processing the straight lines in the line segment group to obtain a table;

[0133] A first footer line determination module is used to determine that there is no footer line in the document page to be identified when the circumscribed rectangular frame of the line segment ranked last is inside the circumscribed rectangular frame of the table;

[0134] The second footer line determination module is used to determine that there is a footer line in the document page to be identified when the circumscribed rectangular frame of the line segment ranked last is not located within the circumscribed rectangular frame of the table.

[0135] In an optional implementation, the footer identification submodule is specifically used for:

[0136] For any text line in the footer line group, the text line is determined to be a text line belonging to the footer when all of the following conditions are met:

[0137] There is a footer line in the document page to be identified, and the footer line group is not empty;

[0138] The Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the line segment ranked last is smaller than the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the text line;

[0139] The width of the circumscribed rectangular box of the text line is greater than the width of the circumscribed rectangular box of the line segment ranked last.

[0140] In an optional implementation, the footer identification submodule is specifically used for:

[0141] For any text line in the footer line group, the text line is determined to be a text line belonging to the footer when all of the following conditions are met:

[0142] The number of text lines is 1;

[0143] The number of elements in the text line is less than a preset element number threshold;

[0144] The elements in the text line are numbers.

[0145] In a third aspect of an embodiment of the present invention, there is further provided an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0146] Memory, used to store computer programs;

[0147] The processor is used to implement the document header and footer recognition method described in any one of the first aspects above when executing the program stored in the memory.

[0148] In a fourth aspect of an embodiment of the present invention, a storage medium is further provided, wherein instructions are stored in the storage medium, and when the instructions are executed on a computer, the computer executes the document header and footer recognition method described in any one of the first aspects above.

[0149] In a fifth aspect of the embodiments of the present invention, a computer program product comprising instructions is also provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned methods for identifying headers and footers of documents.

[0150] The technical solution provided by the embodiment of the present invention obtains an electronic document and determines a document page to be identified in the electronic document, wherein the document page to be identified is any document page in the electronic document, identifies all text lines in the document page to be identified, and determines the text line features of all text lines, traverses the text line features of all text lines, and performs the following steps: identifies the text line belonging to the header, assigns the structural element of the header attribute to the text line belonging to the header, and / or identifies the text line belonging to the footer, and assigns the structural element of the footer attribute to the text line belonging to the footer. By identifying all text lines in a document page in the electronic document, traversing the text line features of all text lines, and performing the following steps: identifies the text line belonging to the header, assigns the structural element of the header attribute to the text line belonging to the header, and / or identifies the text line belonging to the footer, and assigns the structural element of the footer attribute to the text line belonging to the footer, the recognition of the header and footer can be realized based on a single document page, which takes less time and improves the recognition speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0151] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0152] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0153] Figure 1 It is a schematic diagram of an implementation flow of a document header and footer recognition method shown in an embodiment of the present invention;

[0154] Figure 2 It is a schematic diagram of the implementation process of another document header and footer recognition method shown in an embodiment of the present invention;

[0155] Figure 3 It is a schematic diagram of the implementation process of another document header and footer recognition method shown in an embodiment of the present invention;

[0156] Figure 4 It is a schematic diagram of an implementation process of a header line detection method shown in an embodiment of the present invention;

[0157] Figure 5 It is a schematic diagram of an implementation process of a footer line detection method shown in an embodiment of the present invention;

[0158] Figure 6 It is a structural schematic diagram of a document header and footer recognition device shown in an embodiment of the present invention;

[0159] Figure 7 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present invention. DETAILED DESCRIPTION

[0160] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0161] like Figure 1 FIG. 1 is a schematic diagram of an implementation flow of a document header and footer recognition method provided by an embodiment of the present invention. The method is applied to an electronic device and may specifically include the following steps:

[0162] S101, acquiring an electronic document, and determining a document page to be identified in the electronic document, wherein the document page to be identified is any document page in the electronic document.

[0163] In an embodiment of the present invention, an electronic document is obtained. The electronic document here can be a layout electronic document mainly in PDF format or OFD (Open Fixed-layout Document) format converted from a typesetting tool and a typesetting document. Of course, it can also be a streaming electronic document, which is not limited by the embodiment of the present invention.

[0164] For an electronic document, a document page to be identified in the electronic document may be determined, wherein the document page to be identified is any document page in the electronic document, which means that any document page in the electronic document may be used as a document page to be identified.

[0165] It should be noted that the document page to be identified can be determined randomly from the electronic document, or specified by the user, or the document page with fewer characters in the electronic document can be determined as the document page to be identified, which is not limited in the embodiment of the present invention.

[0166] S102, identifying all text lines in the document page to be identified, and determining text line features of all the text lines.

[0167] In the embodiment of the present invention, for a document page to be identified in an electronic document, all text lines in the document page to be identified can be identified, and the text line features of all text lines can be determined. Here, the text line features are slightly different due to the difference in header and footer identification.

[0168] It should be noted that, for the recognition of all text lines in the document page to be recognized, some line identifiers may be used to recognize all text lines in the document page to be recognized, which is not limited in the embodiment of the present invention.

[0169] In addition, in the subsequent process of identifying the header, the above-mentioned text line feature can be the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the text line, and in the subsequent process of identifying the footer, the above-mentioned text line feature can be the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the text line.

[0170] S103, traverse the text line features of all the text lines and execute the following steps.

[0171] S104, identifying the text line belonging to the header, and assigning a structural element of the header attribute to the text line belonging to the header.

[0172] and / or,

[0173] S105, identifying the text line belonging to the footer, and assigning a structural element of footer attributes to the text line belonging to the footer.

[0174] In an embodiment of the present invention, for all text lines in the document page to be identified, the text line features of all text lines can be traversed to perform the following steps: identifying the text lines belonging to the header, assigning structural elements of header attributes to the text lines belonging to the header, and / or identifying the text lines belonging to the footer, assigning structural elements of footer attributes to the text lines belonging to the footer.

[0175] From the above, it can be seen that by traversing the text line features of all text lines, it is possible to identify the text lines belonging to the header and assign structural elements of header attributes to the text lines belonging to the header, and / or identify the text lines belonging to the footer and assign structural elements of footer attributes to the text lines belonging to the footer, thereby completing the task of identifying the header and / or footer.

[0176] It should be noted that for the structural elements of the header attribute, for example, it can be the Artifact of the Header attribute (a graphic element that is not created by the author but added by the PDF generation application during paging, layout or other processes to enhance the visual experience), and for the structural elements of the footer attribute, for example, it can be the Artifact of the Footer attribute. It can be understood that Artifact is an invisible structural element similar to a PDF tag. This structural element does not affect the display of the PDF and the reader's understanding. The SubType attribute in them describes the modification of some elements, such as whether it is a header or footer, whether it is a watermark, etc.

[0177] Through the above description of the technical solution provided by the embodiment of the present invention, an electronic document is obtained, and a document page to be identified in the electronic document is determined, wherein the document page to be identified is any document page in the electronic document, all text lines in the document page to be identified are identified, and the text line features of all text lines are determined, the text line features of all text lines are traversed, and the following steps are performed: identifying text lines belonging to headers, assigning structural elements of header attributes to the text lines belonging to the header, and / or identifying text lines belonging to footers, assigning structural elements of footer attributes to the text lines belonging to the footer.

[0178] By identifying all text lines in a document page in an electronic document, traversing the text line features of all text lines, and performing the following steps: identifying text lines belonging to headers, assigning structural elements of header attributes to text lines belonging to headers, and / or, identifying text lines belonging to footers, assigning structural elements of footer attributes to text lines belonging to footers, the recognition of headers and footers can be realized based on a single document page, which takes less time and improves the recognition speed. Further, the effect of converting layout electronic documents to streaming electronic documents can be improved, the editability of layout electronic documents can be improved, and the readability of layout electronic documents when they are rearranged can be improved.

[0179] In an embodiment of the present invention, for electronic documents, especially layout electronic documents, if the structural elements in the layout electronic document already include structural elements with the attributes of Header and Footer, then the result can be directly used without the need to identify the header and footer. If it only includes one of the structural elements with the attributes of Header and Footer (for example, the structural element with the attribute of Header), then only the missing attributes (for example, the footer) are identified. If neither of them exists, then the header and footer need to be identified.

[0180] Based on this, in the embodiment of the present invention, before the header and footer are identified, it is determined whether the header and footer need to be identified. Figure 2 FIG. 1 is a schematic diagram of an implementation flow of another document header and footer recognition method provided by an embodiment of the present invention. The method is applied to an electronic device and may specifically include the following steps:

[0181] S201, obtaining an electronic document, parsing the electronic document, and obtaining all structural elements in the electronic document.

[0182] In the embodiment of the present invention, an electronic document, such as a layout electronic document, is obtained and parsed to obtain all structural elements in the electronic document. The structural elements here may be, for example, Artifacts.

[0183] S202, when all structural elements contain structural elements with header attributes, determine a document page to be identified in the electronic document, and perform a footer identification task for the document page to be identified, wherein the document page to be identified is any document page in the electronic document.

[0184] In an embodiment of the present invention, for all structural elements in an electronic document, when they contain structural elements with header attributes, it indicates that a footer needs to be identified. At this time, a document page to be identified in the electronic document can be determined, and a footer identification task for the document page to be identified can be performed, wherein the document page to be identified is any document page in the electronic document.

[0185] For example, for all artifacts in an electronic document, if the artifact contains a Header attribute, it means that only the footer needs to be identified at this time. This can determine the document page to be identified in the electronic document, and perform the footer identification task for the document page to be identified, which means that only the footer needs to be identified for the document page to be identified subsequently.

[0186] S203, when all structural elements contain structural elements with footer attributes, determine the document page to be identified in the electronic document, and perform a header recognition task for the document page to be identified.

[0187] In an embodiment of the present invention, for all structural elements in an electronic document, if they contain structural elements with footer attributes, it indicates that the header needs to be identified. At this time, the document page to be identified in the electronic document can be determined, and the header recognition task for the document page to be identified can be performed.

[0188] For example, for all artifacts in an electronic document, if there is an artifact with a Footer attribute, it means that only the header needs to be identified at this time. This can determine the document page to be identified in the electronic document, and perform the header recognition task for the document page to be identified, which means that only the header recognition needs to be performed for the document page to be identified subsequently.

[0189] S204, when all structural elements do not include structural elements with header attributes and structural elements with footer attributes, determine the document page to be identified in the electronic document, and perform a header and footer identification task for the document page to be identified.

[0190] In the embodiment of the present invention, for all structural elements in the electronic document, when they include structural elements with header attributes and structural elements with footer attributes, it is not necessary to identify the header and footer, and the results can be directly used.

[0191] When it does not contain structural elements of header attributes and structural elements of footer attributes, it means that header and footer recognition is required at this time, thereby determining the document page to be recognized in the electronic document and performing the header and footer recognition task for the document page to be recognized.

[0192] For example, for all artifacts in an electronic document, if they do not contain an artifact with a Header attribute and an artifact with a Footer attribute, it means that the header and footer need to be identified at this time. This can determine the document page to be identified in the electronic document, and perform the header and footer identification task for the document page to be identified, which means that the header and footer will be identified for the document page to be identified later.

[0193] S205, identifying all text lines in the document page to be identified, and determining text line features of all text lines.

[0194] In the embodiment of the present invention, this step is similar to the above step S102, and the embodiment of the present invention will not be described in detail here.

[0195] S206, traverse the text line features of all text lines and perform the following steps.

[0196] S207, identifying the text line belonging to the header, and assigning a structural element of the header attribute to the text line belonging to the header.

[0197] and / or,

[0198] S208, identifying the text line belonging to the footer, and assigning a structural element of footer attributes to the text line belonging to the footer.

[0199] In the embodiment of the present invention, the above steps are similar to steps S102 to S104, and the embodiment of the present invention will not be described one by one here.

[0200] By judging whether the header and footer need to be identified in the electronic document, and if the header and / or footer need to be identified, identifying all text lines in a document page in the electronic document, traversing the text line features of all text lines, and performing the following steps: identifying the text line belonging to the header, assigning the structural element of the header attribute to the text line belonging to the header, and / or, identifying the text line belonging to the footer, assigning the structural element of the footer attribute to the text line belonging to the footer, the recognition of the header and footer can be realized based on a single document page, which takes less time and improves the recognition speed. It can further improve the effect of converting the layout electronic document into the streaming electronic document, improve the editability of the layout electronic document, and improve the readability of the layout electronic document when it is rearranged.

[0201] like Figure 3 FIG. 1 is a schematic diagram of an implementation flow of another document header and footer recognition method provided by an embodiment of the present invention. The method is applied to an electronic device and may specifically include the following steps:

[0202] S301, obtaining an electronic document, parsing the electronic document, and obtaining all structural elements in the electronic document.

[0203] In the embodiment of the present invention, this step is similar to the above-mentioned step S201, and the embodiment of the present invention will not be described in detail here.

[0204] S302, when all structural elements contain structural elements with header attributes, determine a document page to be identified in the electronic document, and perform a footer identification task for the document page to be identified, wherein the document page to be identified is any document page in the electronic document.

[0205] In the embodiment of the present invention, this step is similar to the above step S202, and the embodiment of the present invention will not be described in detail here.

[0206] S303, when all structural elements contain structural elements with footer attributes, determine the document page to be identified in the electronic document, and perform a header recognition task for the document page to be identified.

[0207] In the embodiment of the present invention, this step is similar to the above step S203, and the embodiment of the present invention will not be described in detail here.

[0208] S304: when all structural elements do not include structural elements with header attributes and structural elements with footer attributes, determine the document page to be identified in the electronic document, and perform the header and footer identification task for the document page to be identified.

[0209] In the embodiment of the present invention, this step is similar to the above-mentioned step S204, and the embodiment of the present invention will not be described in detail here.

[0210] S305, identifying all text lines in the document page to be identified, and determining text line features of all text lines, the text line features including the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box and the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box.

[0211] In an embodiment of the present invention, all text lines in a document page to be identified are identified, and text line features of all text lines are determined, wherein the text line features include the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box and the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box.

[0212] For example, Line represents a bounding rectangle (BBox) of a text line, and the Y-axis coordinate value corresponding to the upper boundary of the bounding rectangle of the text line can be expressed as Line.Top, and the Y-axis coordinate value corresponding to the lower boundary of the bounding rectangle of the text line can be expressed as Line.Bottom.

[0213] It should be noted that, in the process of identifying the header, the Y-axis coordinate value corresponding to the upper boundary of the above-mentioned circumscribed rectangular frame is used, and in the process of identifying the footer, the Y-axis coordinate value corresponding to the lower boundary of the above-mentioned circumscribed rectangular frame is used.

[0214] S306, traverse the Y-axis coordinate values ​​corresponding to the upper boundaries of the circumscribed rectangular boxes of all text lines and the Y-axis coordinate values ​​corresponding to the lower boundaries of the circumscribed rectangular boxes, and perform the following steps.

[0215] In an embodiment of the present invention, the Y-axis coordinate values ​​corresponding to the upper boundaries of the circumscribed rectangular boxes of all text lines and the Y-axis coordinate values ​​corresponding to the lower boundaries of the circumscribed rectangular boxes are traversed, and the following steps are performed to complete the recognition of the header and / or footer.

[0216] S307, when the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangle of the text line satisfies a preset first condition, store the text line in the header line group.

[0217] In an embodiment of the present invention, for a text line, when the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangle of the text line satisfies a preset first condition, store the text line in the header line group.

[0218] For example, for a text line, when Line.Top of the text line satisfies a preset first condition, store the text line in the header line group, that is, HeaderLineGroup.

[0219] Specifically, obtain the visible area in the document page to be recognized, and determine the circumscribed rectangle of the visible area; obtain the product of the height of the circumscribed rectangle of the visible area and a preset ratio to obtain a limit threshold; when the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangle of the text line is less than the product of the limit threshold and a preset first value, store the text line in the header line group.

[0220] For example, for a document page, there is a visible area and a hidden area. The visible area is visible to the user, while the hidden area is invisible to the user. Thus, obtain the visible area in the document to be recognized, and determine the circumscribed rectangle of the visible area. For example, use Page to represent the circumscribed rectangle (BBox) of the visible area, obtain the product of the height (Page.Height) of the circumscribed rectangle of the visible area and a preset ratio to obtain a limit threshold (Limit). For example, Limit = Page.Height * 9% (empirical value). When Line.Top < Limit * 2, add the text line to HeaderLineGroup.

[0221] S308, from the text lines in the header line group, identify the text lines belonging to the header, and assign a structural element with a header attribute to the text lines belonging to the header.

[0222] In an embodiment of the present invention, for the header line group, from the text lines in the header line group, identify the text lines belonging to the header, and assign a structural element with a header attribute to the text lines belonging to the header.

[0223] Among them, before identifying the text lines belonging to the header from the text lines in the header line group, it is necessary to detect whether there is a header line in the document to be recognized, and the detection result of the header line affects the recognition of the header.

[0224] Based on this, as Figure 4 shown, it is a schematic flowchart of an implementation process of a header line detection method provided by an embodiment of the present invention. This method is applied to an electronic device and specifically may include the following steps:

[0225] S401, traverse all line segments in the document page to be identified, and store line segments that meet preset line segment conditions into a line segment group.

[0226] In an embodiment of the present invention, the document page to be identified can be parsed to obtain all the line segments (Path) therein, thereby traversing all the line segments in the document page to be identified and storing the line segments that meet the preset line segment conditions into a line segment group, for example, the line segment group is represented by PathGroup.

[0227] Specifically, all line segments in the document page to be identified are traversed, and when the X-axis coordinate value corresponding to the left boundary of the circumscribed rectangular box of the line segment is less than the left boundary threshold, the X-axis coordinate value corresponding to the right boundary of the circumscribed rectangular box of the line segment is greater than the right boundary threshold, and the Y-axis coordinate value corresponding to the starting point of the line segment is consistent with the Y-axis coordinate value corresponding to the end point of the line segment, the line segment is stored in the line segment group.

[0228] The left boundary threshold is the product of the preset second value and the width of the circumscribed rectangular frame of the visible area in the document page to be identified, and the right boundary threshold is the product of the preset third value and the width of the circumscribed rectangular frame of the visible area in the document page to be identified.

[0229] For example, traverse all the Paths in the document page to be identified, and when the X-axis coordinate value (PathBBox.Left) corresponding to the left boundary of the circumscribed rectangular box of the line segment is less than the left boundary threshold (Left), such as PathBBox.Left<Left; the X-axis coordinate value (PathBBox.Right) corresponding to the right boundary of the circumscribed rectangular box of the line segment is greater than the right boundary threshold (Right), such as PathBBox.Right>Right; the Y-axis coordinate value (Path.StartPoint.y) corresponding to the starting point of the line segment is consistent with the Y-axis coordinate value (Path.EndPoint.y) corresponding to the end point of the line segment, such as Path.StartPoint.y=Path.EndPoint.y, add the Path to the PathGroup.

[0230] Among them, for the left boundary threshold Left, it is the product of 0.25 (empirical value) and the width of the bounding rectangular box of the visible area in the document page to be identified (Page.Width), that is, Left = 0.25*Page.Width, and for the right boundary threshold Right, it is the product of 0.75 (empirical value) and the width of the bounding rectangular box of the visible area in the document page to be identified, that is, Right = 0.75*Page.Width.

[0231] It should be noted that the above PathBBox.Left<Left, PathBBox.Right>Right is to take into account that the Path is relatively long, at least from the 1 / 4 position on the left side of the page number to the 3 / 4 position on the right side, and Right=0.75*Page.Width, here to take into account the horizontal straight line and filter out the diagonal line.

[0232] S402, sorting the line segments in the line segment group, and determining the line segment ranked first in the line segment group.

[0233] In the embodiment of the present invention, the line segments in the line segment group are sorted, wherein the line segments in the line segment group may be sorted from small to large, and the line segment ranked first in the line segment group may be determined.

[0234] Specifically, the line segments in the line segment group are sorted from small to large according to the Y-axis coordinate values ​​corresponding to the upper boundaries of the circumscribed rectangular boxes of the line segments, thereby determining the first-ranked line segment in the line segment group. The first-ranked line segment here can be called FirstPath, and the first-ranked line segment here can be understood to refer to the line segment with the smallest Y-axis coordinate value.

[0235] S403, traverse the line segments in the line segment group, search for straight lines in the line segment group, and process the straight lines in the line segment group to obtain a table.

[0236] In an embodiment of the present invention, the line segments in the line segment group are traversed, the straight lines in the line segment group are searched, and the straight lines in the line segment group are processed to obtain a table. Among them, the line segment group only contains the Path of the MoveTo (a graphic instruction or operation for moving the drawing position. It needs to specify a target point coordinate as a parameter, and then move the current drawing position to the target point) and LineTo (a graphic instruction or operation for drawing a straight line segment. It needs to specify a target point coordinate as a parameter, and then connect the current drawing position and the target point into a straight line) instructions, that is, the straight line.

[0237] In addition, the straight lines in the line segment group are rendered to obtain a picture, and all connected domains in the picture are found. From all the connected domains, the connected domain with the largest circumscribed rectangular box is determined, and the straight lines in the connected domain with the largest circumscribed rectangular box are expanded and eroded to obtain a table.

[0238] It should be noted that the connected domain formed by the outer border line of the table must be the largest. Therefore, from all connected domains, the connected domain with the largest circumscribed rectangular frame is determined. Here, the straight line in the connected domain with the largest circumscribed rectangular frame is the outer border line of the table.

[0239] The expansion and erosion operations are performed on the straight lines in the largest connected domain of the circumscribed rectangular frame, that is, the expansion and erosion operations are performed on the outer border lines of the table to obtain the table. The expansion and erosion operations here are graphics operations (closing operations) that can connect small gaps.

[0240] The dilation operation can expand the border of the image. The dilation operation merges the background points that are in contact with the current object (foreground) into the current object, thereby expanding the border points of the image outward. If the distance between two objects in the image is close, then during the dilation process, the two objects may be connected together. The erosion operation can eliminate the border points of the image, causing the image to shrink inward along the border, and can also remove the part that is smaller than the specified structure element.

[0241] S404: When the circumscribed rectangular frame of the line segment ranked first is located inside the circumscribed rectangular frame of the table, it is determined that there is no header line in the document page to be identified.

[0242] S405: When the circumscribed rectangular frame of the line segment ranked first is not located inside the circumscribed rectangular frame of the table, it is determined that there is a header line in the document page to be identified.

[0243] In an embodiment of the present invention, for the line segment ranked first, when the circumscribed rectangular box of the line segment ranked first is located inside the circumscribed rectangular box of the table, it is determined that there is no header line in the document page to be identified; when the circumscribed rectangular box of the line segment ranked first is not located inside the circumscribed rectangular box of the table, it is determined that there is a header line in the document page to be identified.

[0244] It should be noted that the header line is usually located at the top of the document page to be identified. According to the position characteristics of the header line in the document page to be identified, theoretically, the first-ranked line segment (that is, the line segment with the smallest Y-axis coordinate value) can represent the header line. However, in order to ensure that it is not confused with the table lines in the table, it is necessary to determine whether the circumscribed rectangular box of the first-ranked line segment is located inside the circumscribed rectangular box of the table. Therefore, when the circumscribed rectangular box of the first-ranked line segment is not located inside the circumscribed rectangular box of the table, there is a header line in the document page to be identified.

[0245] For example, when the BBox (circumscribed rectangular box) of FirstPath is located in the BBox of the table, it is determined that there is no header line in the document page to be identified; when the BBox (circumscribed rectangular box) of FirstPath is not located in the BBox of the table, it is determined that there is a header line in the document page to be identified.

[0246] Based on the detection of the header line in the document page to be identified, the text line belonging to the header can be identified. Specifically, for any text line in the header line group, if any of the following determination conditions is met, the text line is determined to be a non-header text line, otherwise the text line is determined to be a header text line:

[0247] I. There is no header line in the document page to be identified or the header line group is empty.

[0248] Ii. The Y-axis coordinate value corresponding to the upper boundary of the bounding rectangle of the text line is less than the average value, and the average value is the average value between the Y-axis coordinate value corresponding to the upper boundary of the bounding rectangle of the first-ranked line segment and the Y-axis coordinate value corresponding to the lower boundary of the bounding rectangle of the first-ranked line segment. For example, LineBBox.Top<(FirstPath.Top+FirstPath.Bottom) / 2, where (FirstPath.Top+FirstPath.Bottom) / 2<LineBBox.Top+LineBBox.Height*0.75, where the Y-axis coordinate value corresponding to the upper boundary of the bounding rectangle of the text line is LineBBox.Top, the Y-axis coordinate value corresponding to the upper boundary of the bounding rectangle of the first-ranked line segment is FirstPath.Top, the Y-axis coordinate value corresponding to the lower boundary of the bounding rectangle of the first-ranked line segment is FirstPath.Bottom, and the height of the bounding rectangle of the text line is LineBBox.Height.

[0249] Iii. The width of the bounding rectangle of the text line is greater than the width of the bounding rectangle of the first-ranked line segment. For example, LineBBox.Width>FirstPath.Width, where the width of the bounding rectangle of the text line is LineBBox.Width, and the width of the bounding rectangle of the first-ranked line segment is FirstPath.Width.

[0250] S309, and / or, when the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame of the text line meets a preset second condition, the text line is stored in the footer line group.

[0251] In the embodiment of the present invention, for a text line, when the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame of the text line meets the preset second condition, the text line is stored in the footer line group.

[0252] For example, for a text line, when Line.Bottom of the text line satisfies the preset second condition, the text line is stored in a footer line group, namely, FooterLineGroup.

[0253] Specifically, a visible area in a document page to be identified is obtained, and a bounding rectangular frame of the visible area is determined; the product of the height of the bounding rectangular frame of the visible area and a preset ratio is obtained to obtain a limiting threshold; the coordinate difference between the Y-axis coordinate value corresponding to the lower boundary of the bounding rectangular frame of the visible area and the Y-axis coordinate value corresponding to the lower boundary of the bounding rectangular frame of the text line is obtained; when the coordinate difference is less than the product of the limiting threshold and a preset first value, the text line is stored in a footer row group.

[0254] For example, obtain the visible area in the document to be identified, and determine the bounding rectangular box of the visible area, for example, use Page to represent the bounding rectangular box (BBox) of the visible area, obtain the product of the height (Page.Height) of the bounding rectangular box of the visible area and a preset ratio, and obtain a limit threshold (Limit), for example, Limit = Page.Height*9%, obtain the coordinate difference between the Y-axis coordinate value (Page.Bottom) corresponding to the lower boundary of the bounding rectangular box of the visible area and the Y-axis coordinate value (Line.Bottom) corresponding to the lower boundary of the bounding rectangular box of the text line, for example, Page.Bottom-Line.Bottom, and when Page.Bottom-Line.Bottom<Limit*2, add the text line to FooterLineGroup.

[0255] S310, identifying text lines belonging to the footer from the text lines of the footer line group, and assigning structural elements of footer attributes to the text lines belonging to the footer.

[0256] In the embodiment of the present invention, for the footer row group, the text row belonging to the footer is identified from the text rows of the footer row group, and the structural element of the footer attribute is assigned to the text row belonging to the footer.

[0257] Before identifying the text lines belonging to the footer from the text lines of the footer line group, it is necessary to detect whether there is a footer line in the document to be identified. The detection result of the footer line affects the identification of the footer.

[0258] Based on this, Figure 5 FIG. 1 is a schematic diagram of an implementation flow of a footer line detection method provided by an embodiment of the present invention. The method is applied to an electronic device and may specifically include the following steps:

[0259] S501, traverse all line segments in the document page to be identified, and store line segments that meet preset line segment conditions into a line segment group.

[0260] In the embodiment of the present invention, this step is similar to the above step S401, and the embodiment of the present invention will not be described in detail here.

[0261] S502, sorting the line segments in the line segment group, and determining the last-ranked line segment in the line segment group.

[0262] In the embodiment of the present invention, the line segments in the line segment group are sorted, wherein the line segments in the line segment group may be sorted from small to large, and the line segment ranked last in the line segment group may be determined.

[0263] Specifically, the line segments in the line segment group are sorted from small to large according to the Y-axis coordinate values ​​corresponding to the upper boundaries of the circumscribed rectangular boxes of the line segments, thereby determining the last line segment in the line segment group, where the last line segment can be referred to as LastPath. The last line segment can be understood to refer to the line segment with the largest Y-axis coordinate value.

[0264] S503, traverse the line segments in the line segment group, search for straight lines in the line segment group, and process the straight lines in the line segment group to obtain a table.

[0265] In the embodiment of the present invention, this step is similar to the above step S403, and the embodiment of the present invention will not be described in detail here.

[0266] S504: When the circumscribed rectangle of the line segment ranked last is located inside the circumscribed rectangle of the table, it is determined that there is no footer line in the document page to be identified.

[0267] S505: When the circumscribed rectangular frame of the last-ranked line segment is not located inside the circumscribed rectangular frame of the table, it is determined that there is a footer line in the document page to be identified.

[0268] In an embodiment of the present invention, for the last-ranked line segment, when the circumscribed rectangular box of the last-ranked line segment is located inside the circumscribed rectangular box of the table, it is determined that there is no footer line in the document page to be identified; and when the circumscribed rectangular box of the last-ranked line segment is not located inside the circumscribed rectangular box of the table, it is determined that there is a footer line in the document page to be identified.

[0269] It should be noted that the footer line is usually located at the bottom of the document page to be identified. According to the position characteristics of the footer line in the document page to be identified, theoretically, the last-ranked line segment (that is, the line segment with the largest Y-axis coordinate value) can represent the footer line. However, in order to avoid confusion with the table lines in the table, it is necessary to determine whether the bounding rectangle of the last-ranked line segment is located inside the bounding rectangle of the table. Therefore, when the bounding rectangle of the last-ranked line segment is not located inside the bounding rectangle of the table, there is a footer line in the document page to be identified.

[0270] For example, when the BBox (circumscribed rectangular box) of LastPath is located in the BBox of the table, it is determined that there is no footer line in the document page to be identified; when the BBox (circumscribed rectangular box) of LastPath is not located in the BBox of the table, it is determined that there is a footer line in the document page to be identified.

[0271] Based on the above detection of the footer line in the document page to be identified, the text line belonging to the footer can be identified. Specifically, for any text line in the footer line group, if all of the following conditions are met, the text line is determined to be a text line belonging to the footer:

[0272] I. There is a footer line in the document page to be identified, and the footer line group is not empty.

[0273] Ii. The Y-axis coordinate value (LastPath.Top) corresponding to the upper boundary of the circumscribed rectangular box of the last-ranked line segment is smaller than the Y-axis coordinate value (LineBBox.Top) corresponding to the lower boundary of the circumscribed rectangular box of the text line. For example, LastPath.Top<LineBBox.Top.

[0274] iii. The width of the bounding rectangle of the text line (LineBBox.Width) is greater than the width of the bounding rectangle of the last line segment (LastPath.Width). For example, LineBBox.Width<LastPath.Width.

[0275] In addition, the last text line is usually a page number, which is the footer. If a text line is identified to meet the characteristics of the page number, it can be considered that the text line belongs to the footer. Based on this, for any text line in the footer line group, if all of the following conditions are met, the text line is determined to be a footer text line:

[0276] I. The number of text lines is 1. For example, there is only one text line in FooterLineGroup.

[0277] Ii. The number of elements in a text line is less than the preset element number threshold. For example, the total number of Unicode characters in a text line does not exceed 4.

[0278] iii. Elements in a text line are numbers. For example, Unicode in a text line is a number, and the numbers here include Arabic numerals or Roman numerals.

[0279] By judging whether it is necessary to identify the header and footer in the electronic document, and if it is necessary to identify the header and / or footer, identifying all text lines in a document page in the electronic document, traversing the Y-axis coordinate values ​​corresponding to the upper boundaries of the circumscribed rectangular boxes of all text lines and the Y-axis coordinate values ​​corresponding to the lower boundaries of the circumscribed rectangular boxes, the following steps are performed: when the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the text line meets a preset first condition, storing the text line in a header line group, identifying the text line belonging to the header from the text lines in the header line group, and assigning a structural element of a header attribute to the text line belonging to the header, and / or, when the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the text line meets a preset second condition, storing the text line in a footer line group, identifying the text line belonging to the footer from the text lines in the footer line group, and assigning a structural element of a footer attribute to the text line belonging to the footer, the recognition of the header and footer can be realized based on a single document page, less time is spent, and the recognition speed is improved. It can further improve the effect of converting layout electronic documents into streaming electronic documents, improve the editability of layout electronic documents, and improve the readability of layout electronic documents when they are rearranged.

[0280] Corresponding to the above method embodiment, the embodiment of the present invention also provides a document header and footer recognition device, such as Figure 6 As shown, the device may include: a document acquisition module 610, a page determination module 620, a text line recognition module 630, a text line feature determination module 640, a text line traversal module 650, a header recognition module 660, and a footer recognition module 670.

[0281] The document acquisition module 610 is used to acquire electronic documents;

[0282] A page determination module 620 is used to determine a document page to be identified in the electronic document, wherein the document page to be identified is any document page in the electronic document;

[0283] A text line recognition module 630 is used to recognize all text lines in the document page to be recognized;

[0284] A text line feature determination module 640, configured to determine the text line features of all the text lines;

[0285] The text line traversal module 650 is used to traverse the text line features of all the text lines and perform the following steps:

[0286] Header recognition module 660, used to recognize text lines belonging to the header and assign structural elements of header attributes to the text lines belonging to the header;

[0287] and / or,

[0288] The footer identification module 670 is used to identify the text line belonging to the footer and assign the structural element of the footer attribute to the text line belonging to the footer.

[0289] In an optional implementation, the page determination module is specifically used to:

[0290] Parsing the electronic document to obtain all structural elements in the electronic document;

[0291] In the case that all the structural elements contain structural elements with header attributes, a document page to be identified in the electronic document is determined, and a footer identification task is performed for the document page to be identified.

[0292] In an optional implementation, the page determination module is specifically used to:

[0293] Parsing the electronic document to obtain all structural elements in the electronic document;

[0294] In the case that all the structural elements contain structural elements with footer attributes, a document page to be identified in the electronic document is determined, and a header recognition task is performed on the document page to be identified.

[0295] In an optional implementation, the page determination module is specifically used to:

[0296] Parsing the electronic document to obtain all structural elements in the electronic document;

[0297] In the case that all the structural elements do not include structural elements with header attributes and structural elements with footer attributes, a document page to be identified in the electronic document is determined, and a header and footer identification task is performed for the document page to be identified.

[0298] In an optional embodiment, the text line feature includes a Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame;

[0299] The header recognition module specifically includes:

[0300] A text line storage first submodule is used to store the text line into a header line group when the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame of the text line meets a preset first condition;

[0301] The header identification submodule is used to identify the text lines belonging to the header from the text lines in the header line group.

[0302] In an optional implementation manner, the text line is stored in the first submodule specifically for:

[0303] Acquire a visible area in the document page to be identified, and determine a circumscribed rectangular frame of the visible area;

[0304] Obtaining the product of the height of the circumscribed rectangular frame of the visible area and a preset ratio to obtain a limiting threshold;

[0305] When the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame of the text line is less than the product of the limit threshold and a preset first value, the text line is stored in the header line group.

[0306] In an optional embodiment, the device further comprises:

[0307] A line segment storage module, used for traversing all line segments in the document page to be identified, and storing the line segments meeting the preset line segment conditions into a line segment group;

[0308] A line segment sorting module, used for sorting the line segments in the line segment group and determining the line segment ranked first in the line segment group;

[0309] A straight line search module, used for traversing the line segments in the line segment group and searching for straight lines in the line segment group;

[0310] A straight line processing module, used for processing the straight lines in the line segment group to obtain a table;

[0311] A first module for determining a header line, configured to determine that no header line exists in the document page to be identified when the circumscribed rectangular frame of the line segment ranked first is located inside the circumscribed rectangular frame of the table;

[0312] The second module for determining a header line is used to determine that a header line exists in the document page to be identified when the circumscribed rectangular frame of the line segment ranked first is not located within the circumscribed rectangular frame of the table.

[0313] In an optional implementation, the header identification submodule is specifically used for:

[0314] For any of the text lines in the header line group, if any one of the following determination conditions is met, the text line is determined to be a non-header text line; otherwise, the text line is determined to be a header text line:

[0315] There is no header line in the document page to be identified or the header line group is empty;

[0316] The Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the text line is less than an average value, and the average value is an average value between the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the line segment ranked first and the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the line segment ranked first;

[0317] The width of the circumscribed rectangular box of the text line is greater than the width of the circumscribed rectangular box of the line segment ranked first.

[0318] In an optional implementation, the line segment storage module is specifically used for:

[0319] When the X-axis coordinate value corresponding to the left boundary of the circumscribed rectangular box of the line segment is less than the left boundary threshold, the X-axis coordinate value corresponding to the right boundary of the circumscribed rectangular box of the line segment is greater than the right boundary threshold, and the Y-axis coordinate value corresponding to the starting point of the line segment is consistent with the Y-axis coordinate value corresponding to the end point of the line segment, the line segment is stored in the line segment group;

[0320] Among them, the left boundary threshold is the product of a preset second value and the width of the circumscribed rectangular frame of the visible area in the document page to be identified, and the right boundary threshold is the product of a preset third value and the width of the circumscribed rectangular frame of the visible area in the document page to be identified.

[0321] In an optional implementation, the line segment sorting module is specifically used to:

[0322] The line segments in the line segment group are sorted from small to large according to Y-axis coordinate values ​​corresponding to upper boundaries of circumscribed rectangular boxes of the line segments.

[0323] In an optional implementation, the straight line processing module is specifically used to:

[0324] Rendering the straight lines in the line segment group to obtain a picture, and searching for all connected domains in the picture;

[0325] From all the connected domains, the connected domain with the largest circumscribed rectangular frame is determined, and dilation and erosion operations are performed on the straight lines in the connected domain with the largest circumscribed rectangular frame to obtain a table.

[0326] In an optional implementation, the text line feature includes a Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame;

[0327] The footer identification module includes:

[0328] A second submodule for storing text lines is used to store the text line into a footer line group when the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame of the text line meets a preset second condition;

[0329] The footer identification submodule is used to identify the text lines belonging to the footer from the text lines in the footer line group.

[0330] In an optional implementation manner, the text line is stored in the second submodule specifically for:

[0331] Acquire a visible area in the document page to be identified, and determine a circumscribed rectangular frame of the visible area;

[0332] Obtaining the product of the height of the circumscribed rectangular frame of the visible area and a preset ratio to obtain a limiting threshold;

[0333] Obtaining a coordinate difference between a Y-axis coordinate value corresponding to a lower boundary of a circumscribed rectangular frame of the visible area and a Y-axis coordinate value corresponding to a lower boundary of the circumscribed rectangular frame of the text line;

[0334] When the coordinate difference is smaller than the product of the limit threshold and a preset first value, the text line is stored in a footer line group.

[0335] In an optional embodiment, the device comprises:

[0336] A line segment storage module, used for traversing all line segments in the document page to be identified, and storing the line segments meeting the preset line segment conditions into a line segment group;

[0337] A line segment sorting module, used for sorting the line segments in the line segment group and determining the line segment ranked last in the line segment group;

[0338] A straight line search module, used for traversing the line segments in the line segment group and searching for straight lines in the line segment group;

[0339] A straight line processing module, used for processing the straight lines in the line segment group to obtain a table;

[0340] A first footer line determination module is used to determine that there is no footer line in the document page to be identified when the circumscribed rectangular frame of the line segment ranked last is inside the circumscribed rectangular frame of the table;

[0341] The second footer line determination module is used to determine that there is a footer line in the document page to be identified when the circumscribed rectangular frame of the line segment ranked last is not located within the circumscribed rectangular frame of the table.

[0342] In an optional implementation, the footer identification submodule is specifically used for:

[0343] For any text line in the footer line group, the text line is determined to be a text line belonging to the footer when all of the following conditions are met:

[0344] There is a footer line in the document page to be identified, and the footer line group is not empty;

[0345] The Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the line segment ranked last is smaller than the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the text line;

[0346] The width of the circumscribed rectangular box of the text line is greater than the width of the circumscribed rectangular box of the line segment ranked last.

[0347] In an optional implementation, the footer identification submodule is specifically used for:

[0348] For any text line in the footer line group, the text line is determined to be a text line belonging to the footer when all of the following conditions are met:

[0349] The number of text lines is 1;

[0350] The number of elements in the text line is less than a preset element number threshold;

[0351] The elements in the text line are numbers.

[0352] The embodiment of the present invention further provides an electronic device, such as Figure 7 As shown, it includes a processor 71, a communication interface 72, a memory 73 and a communication bus 74, wherein the processor 71, the communication interface 72, and the memory 73 communicate with each other through the communication bus 74.

[0353] A memory 73, for storing computer programs;

[0354] The processor 71 is used to execute the program stored in the memory 73 to implement the following steps:

[0355] Acquire an electronic document and determine a document page to be identified in the electronic document, wherein the document page to be identified is any document page in the electronic document; identify all text lines in the document page to be identified and determine the text line features of all the text lines; traverse the text line features of all the text lines and perform the following steps: identify text lines belonging to a header and assign structural elements of header attributes to the text lines belonging to the header; and / or identify text lines belonging to a footer and assign structural elements of footer attributes to the text lines belonging to the footer.

[0356] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0357] The communication interface is used for communication between the above electronic device and other devices.

[0358] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0359] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0360] In another embodiment of the present invention, a storage medium is provided. The storage medium stores instructions. When the instructions are executed on a computer, the computer executes the document header and footer recognition method described in any of the above embodiments.

[0361] In another embodiment provided by the present invention, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the document header and footer recognition method described in any one of the above embodiments.

[0362] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a storage medium, or transmitted from one storage medium to another storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0363] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0364] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0365] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A method for identifying headers and footers of a document. It is characterized in that The method comprises: Acquire an electronic document, and determine a document page to be identified in the electronic document, wherein the document page to be identified is any document page in the electronic document; Identify all text lines in the document page to be identified, and determine text line features of all the text lines; Traverse the text line features of all the text lines and perform the following steps: Identify the text line belonging to the header, and assign the structural element of the header attribute to the text line belonging to the header; and / or, Identify the text lines that belong to the footer and assign footer attributes to the text lines that belong to the footer.

2. The method according to claim 1, It is characterized in that The step of determining the document page to be identified in the electronic document includes: Parsing the electronic document to obtain all structural elements in the electronic document; In the case that all the structural elements contain structural elements with header attributes, determining a document page to be identified in the electronic document, and performing a footer identification task for the document page to be identified; In the case that all the structural elements contain structural elements with footer attributes, determining a document page to be identified in the electronic document, and performing a header recognition task for the document page to be identified; In the case that all the structural elements do not include structural elements with header attributes and structural elements with footer attributes, a document page to be identified in the electronic document is determined, and a header and footer identification task is performed for the document page to be identified.

3. The method according to claim 1, It is characterized in that The text line feature includes a Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame; The identifying of the text line belonging to the page header includes: When the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular frame of the text line meets a preset first condition, storing the text line into a header line group; From the text lines of the header line group, text lines belonging to a header are identified.

4. The method according to claim 3, It is characterized in that Before identifying the text lines belonging to the header from the text lines of the header line group, the method further includes: Traversing all line segments in the document page to be identified, and storing the line segments that meet the preset line segment conditions into a line segment group; Sorting the line segments in the line segment group and determining the line segment ranked first in the line segment group; Traversing the line segments in the line segment group, searching for straight lines in the line segment group, and processing the straight lines in the line segment group to obtain a table; When the circumscribed rectangular frame of the line segment ranked first is located inside the circumscribed rectangular frame of the table, determining that no header line exists in the document page to be identified; When the circumscribed rectangular frame of the line segment ranked first is not located inside the circumscribed rectangular frame of the table, it is determined that there is a header line in the document page to be identified.

5. The method according to claim 4, It is characterized in that The step of identifying a text line belonging to a header from the text lines of the header line group includes: For any of the text lines in the header line group, if any one of the following determination conditions is met, the text line is determined to be a non-header text line; otherwise, the text line is determined to be a header text line: There is no header line in the document page to be identified or the header line group is empty; The Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the text line is less than an average value, and the average value is an average value between the Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the line segment ranked first and the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the line segment ranked first; The width of the circumscribed rectangular box of the text line is greater than the width of the circumscribed rectangular box of the line segment ranked first.

6. The method according to claim 1, It is characterized in that The text line feature includes a Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame; The identifying of the text line belonging to the footer includes: When the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular frame of the text line meets a preset second condition, storing the text line into a footer line group; From the text lines of the footer line group, text lines belonging to the footer are identified.

7. The method according to claim 6, It is characterized in that Before identifying the text lines belonging to the footer from the text lines of the footer line group, the method further includes: Traversing all line segments in the document page to be identified, and storing the line segments that meet the preset line segment conditions into a line segment group; Sorting the line segments in the line segment group and determining the line segment ranked last in the line segment group; Traversing the line segments in the line segment group, searching for straight lines in the line segment group, and processing the straight lines in the line segment group to obtain a table; When the circumscribed rectangular frame of the line segment ranked last is located inside the circumscribed rectangular frame of the table, determining that there is no footer line in the document page to be identified; When the circumscribed rectangular frame of the line segment ranked last is not located inside the circumscribed rectangular frame of the table, it is determined that there is a footer line in the document page to be identified.

8. The method according to claim 7, It is characterized in that The step of identifying a text line belonging to the footer from the text lines of the footer line group includes: For any text line in the footer line group, the text line is determined to be a text line belonging to the footer when all of the following conditions are met: There is a footer line in the document page to be identified, and the footer line group is not empty; The Y-axis coordinate value corresponding to the upper boundary of the circumscribed rectangular box of the line segment ranked last is smaller than the Y-axis coordinate value corresponding to the lower boundary of the circumscribed rectangular box of the text line; The width of the circumscribed rectangular box of the text line is greater than the width of the circumscribed rectangular box of the line segment ranked last.

9. The method according to claim 6, It is characterized in that The step of identifying a text line belonging to the footer from the text lines of the footer line group includes: For any text line in the footer line group, the text line is determined to be a text line belonging to the footer when all of the following conditions are met: The number of text lines is 1; The number of elements in the text line is less than a preset element number threshold; The elements in the text line are numbers.

10. A document header and footer recognition device, It is characterized in that The device comprises: A document acquisition module, used to acquire electronic documents; A page determination module, used to determine a document page to be identified in the electronic document, wherein the document page to be identified is any document page in the electronic document; A text line recognition module, used to recognize all text lines in the document page to be recognized; A text line feature determination module, used to determine the text line features of all the text lines; The text line traversal module is used to traverse the text line features of all the text lines and perform the following steps: A header recognition module, used to recognize text lines belonging to the header and assign structural elements of header attributes to the text lines belonging to the header; and / or, The footer recognition module is used to recognize the text lines belonging to the footer and to assign structural elements of footer attributes to the text lines belonging to the footer.