Document format conversion method and device, storage medium and equipment
By recognizing full-frame, half-frame, and frameless tables in PDF documents, and combining optical character recognition and object detection models, the system converts them into HTML documents and converts charts into images, solving the problem of inaccurate table and chart recognition and conversion in existing technologies and improving the accuracy of document format conversion.
Patent Information
- Application Number
- CN202210651509.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-09
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2042-06-09
AI Technical Summary
Existing technologies struggle to effectively identify and convert tables and charts in PDF documents, especially non-standard tables and complex layouts, resulting in low parsing accuracy.
By recognizing full-frame, half-frame, and frameless tables in PDF documents, optical character recognition and object detection models are used in conjunction with image processing technology to convert them into HTML documents, and charts are converted into image formats.
It improves the accuracy of PDF document parsing and format conversion, effectively recognizing and converting various types of tables and charts, thus enhancing the accuracy of document format conversion.
Smart Images

Figure CN115114481B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a document format conversion method and device, storage medium and equipment. BACKGROUND
[0002] Portable Document Format (PDF) is an electronic file format designed by Adobe Company. Since it is independent of operating system and platform, it is universal in different devices and systems, therefore, many electronic books, papers and company announcements are published in the form of PDF. The layout in PDF is recorded in the form of coordinates, and the instruction is complex, so it is difficult to directly extract the text information in the paragraph or the structured data in the table from PDF. In the prior art, in order to better extract and display the information in PDF, it is usually converted into an HTML (Hyper Text Markup Language) file for processing, and the format of the HTML file is more conducive to parsing and structured extraction of tables.
[0003] In related PDF parsing technology, the main focus is on the extraction of text information or the conversion of tables, but part of the tables in PDF are not standardized, which may cause line loss, existence of charts, complex layout and other situations, thereby greatly reducing the accuracy of related PDF parsing technology. SUMMARY
[0004] The embodiments of the present application provide a document format conversion method and device, storage medium and equipment, which can effectively identify each element in the PDF document and convert it into an HTML document, thereby improving the accuracy of the PDF document format conversion.
[0005] In one aspect, the embodiments of the present application provide a document format conversion method, which includes: identifying a table in a PDF document, the table including at least one of a full-frame table, a half-frame table and a frameless table; identifying a chart in the PDF document, the chart including at least content information displayed in a graphical manner; and converting the PDF document into an HTML document according to the table and the chart, wherein the table converted in the HTML document is in an HTML form, and the chart converted in the HTML document is in a picture form.
[0006] In another aspect, the embodiments of the present application provide a document format conversion device, which includes:
[0007] A first identification unit is configured to identify a table in a PDF document, the table including at least one of a full-frame table, a half-frame table and a frameless table;
[0008] A second identifying unit is configured to identify a chart in the PDF document, the chart including at least content information displayed in a graphical manner.
[0009] A converting unit is configured to convert the PDF document into an HTML document according to the table and the chart, wherein the table converted in the HTML document is in an HTML form, and the chart converted in the HTML document is in a picture form.
[0010] In another aspect, the embodiments of the present application provide a computer readable storage medium storing a computer program, the computer program being adapted to be loaded by a processor to execute the document format conversion method according to any one of the above embodiments.
[0011] In another aspect, the embodiments of the present application provide a computer device including a processor and a memory, the memory storing a computer program, and the processor being configured to execute the document format conversion method according to any one of the above embodiments by invoking the computer program stored in the memory.
[0012] The embodiments of the present application can effectively identify various elements such as full-frame tables, half-frame tables, frameless tables, charts, etc. in a PDF document, and convert them into an HTML document, thereby improving the accuracy of the PDF document format conversion. BRIEF DESCRIPTION OF DRAWINGS
[0013] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort based on these drawings.
[0014] Figure 1 The first flowchart of the document format conversion method provided by the embodiments of the present application is shown.
[0015] Figure 2 The second flowchart of the document format conversion method provided by the embodiments of the present application is shown.
[0016] Figure 3 The third flowchart of the document format conversion method provided by the embodiments of the present application is shown.
[0017] Figure 4 The fourth flowchart of the document format conversion method provided by the embodiment of the present application.
[0018] Figure 5 The fifth flowchart of the document format conversion method provided by the embodiment of the present application.
[0019] Figure 6 The sixth flowchart of the document format conversion method provided by the embodiment of the present application.
[0020] Figure 7 The seventh flowchart of the document format conversion method provided by the embodiment of the present application.
[0021] Figure 8 The eighth flowchart of the document format conversion method provided by the embodiment of the present application.
[0022] Figure 9 The ninth flowchart of the document format conversion method provided by the embodiment of the present application.
[0023] Figure 10 The tenth flowchart of the document format conversion method provided by the embodiment of the present application.
[0024] Figure 11 The eleventh flowchart of the document format conversion method provided by the embodiment of the present application.
[0025] Figure 12 The twelfth flowchart of the document format conversion method provided by the embodiment of the present application.
[0026] Figure 13 The thirteenth flowchart of the document format conversion method provided by the embodiment of the present application.
[0027] Figure 14 The fourteenth flowchart of the document format conversion method provided by the embodiment of the present application.
[0028] Figure 15 The first application scenario of the document format conversion method provided by the embodiment of the present application.
[0029] Figure 16 The second application scenario of the document format conversion method provided by the embodiment of the present application.
[0030] Figure 17 The first structure of the document format conversion device provided by the embodiment of the present application.
[0031] Figure 18 The second structure of the document format conversion device provided by the embodiment of the present application.
[0032] Figure 19 A structural schematic diagram of a computer device provided by an embodiment of the present application is shown. DETAILED DESCRIPTION
[0033] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person skilled in the art without creative work fall within the scope of protection of the present application.
[0034] The embodiments of the present application provide a document format conversion method and device, a computer device and a storage medium. Specifically, the document format conversion method of the embodiments of the present application can be executed by a computer device, where the computer device can be a terminal or a server and the like. The terminal can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart television, a smart speaker, a wearable smart device, a smart vehicle terminal and the like, and the terminal can further include a client, which can be a video client, a browser client or an instant messaging client and the like. The server can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content distribution networks (CDN), and basic cloud computing services such as big data.
[0035] The embodiments of the present application can be applied to various scenes such as computer vision and image recognition.
[0036] The embodiments of the present application provide a document format conversion method, device, storage medium and equipment, which can identify tables and charts existing in a PDF document, where the tables include at least one of full-frame tables, half-frame tables and frameless tables, and in the process of converting the PDF document into an HTML document, the tables are converted into an HTML format and the charts are converted into a picture form. Further, the layout of the PDF document can also be identified, which includes at least one of single-column layout, double-column layout and multi-column layout, and the reading order is determined according to the layout, and the PDF document is converted into an HTML document in the correct reading order, so as to improve the accuracy of the PDF document format conversion.
[0037] The following will be described in detail. It should be noted that the description order of the following embodiments is not limited as the priority order of the embodiments.
[0038] Embodiments of the present application provide a document format conversion method, which can be executed by a terminal or a server, or jointly executed by a terminal and a server. Embodiments of the present application take the case that the document format conversion method is executed by a terminal as an example for description.
[0039] Please refer to Figures 1 to 16 , Figures 1 to 14 The flowchart of the document format conversion method provided by the embodiments of the present application is shown in Figures 15 to 16 The flowchart of the document format conversion method provided by the embodiments of the present application is shown in
[0040] Step 10: identifying a table in the PDF document, wherein the table includes at least one of a full-frame table, a half-frame table, and a no-frame table.
[0041] The full-frame table refers to a table with complete lines, and the range of each cell of the table can be determined without additional lines.
[0042] The half-frame table refers to a table with some lines, and the range of each cell of the table can be determined with additional lines.
[0043] The no-frame table refers to a table without any lines, and the table cannot be positioned by lines.
[0044] For example, a graphical user interface can be provided on the terminal, and a PDF document to be converted can be obtained in response to a document upload instruction triggered by a user on the graphical user interface. Then, the PDF document is subjected to an identification operation.
[0045] In some embodiments, as shown in Figure 2 Step 10 can be implemented by steps 11 and 12, specifically as follows:
[0046] Step 11: positioning a table based on lines in the PDF document to identify a first table in the PDF document, wherein the first table includes at least one of the full-frame table and the half-frame table.
[0047] For example, the full-frame table and the half-frame table can be positioned based on lines.
[0048] In some embodiments, as shown in Figure 3 Step 11 can be implemented by steps 111 to 116, specifically as follows:
[0049] Step 111: identifying text, lines, coordinates of each line, and width and height between each two lines in the PDF document, wherein the lines include horizontal lines and vertical lines.
[0050] For example, text, lines, coordinates of each line, and width and height between each two lines in a PDF document can be identified based on optical character recognition (OCR) technology.
[0051] Optical Character Recognition (OCR) refers to a process in which an electronic device (such as a scanner or digital camera) inspects characters printed on paper, determines their shapes by detecting light and dark patterns, and then translates the shapes into computer text using character recognition methods. In other words, for printed characters, a technical method is used to convert text in a paper document into a black-and-white dot matrix image file using an optical method, and then convert the text in the image into a text format using recognition software, for further editing and processing by word processing software.
[0052] Step 112: determining, according to the coordinates of all horizontal lines in the lines and the width between each two horizontal lines, a plurality of groups of horizontal lines, each group of horizontal lines comprising two horizontal lines parallel to each other and having similar or identical lengths.
[0053] Each group of horizontal lines comprises two horizontal lines parallel to each other and having similar or identical lengths.
[0054] Specifically, according to the coordinates and width of all horizontal lines, it is determined whether the lines form parallel lines with similar lengths, and grouping is performed accordingly. That is, in each group of horizontal lines after grouping, the horizontal lines form parallel lines with similar lengths.
[0055] Step 113: initializing a first table set, and for each group of horizontal lines in the plurality of groups of horizontal lines, performing table recognition processing on each horizontal line in the plurality of groups of horizontal lines from top to bottom and from bottom to top, respectively, and adding all first tables recognized in the table recognition processing to the first table set.
[0056] In some embodiments, the step of traversing each horizontal line in the multiple groups of horizontal lines from top to bottom and bottom to top for table recognition processing includes: traversing each horizontal line in the multiple groups of horizontal lines from top to bottom and bottom to top for each group of horizontal lines; determining whether the current line is the last line; if the current line is not the last line, determining whether the current line and the first line after the current line satisfy a first condition, wherein the first condition is that there is text between the current line and the first line after the current line, and the text is separated by a space, and the distance between the text and the line is less than a second threshold; if the current line and the first line after the current line satisfy the first condition, forming a new first table with the current line and the first line after the current line; determining whether the current line is the second to last line; if the current line is the second to last line, ending the traversal process.
[0057] In some embodiments, after determining whether the current line is the last line, the process further includes: if the current line is the last line, then the traversal process ends.
[0058] In some embodiments, after determining whether the first condition is satisfied between the current line and the first line after the current line, the method further includes: if the first condition is not satisfied between the current line and the first line after the current line, then setting the first line after the current line as the new current line, and returning to the step of determining whether the current line is the last line.
[0059] In some embodiments, after determining whether the current line is the second to last line, the method further includes: if the current line is not the second to last line, setting the second line after the current line as the new current line, and returning to the step of determining whether the current line is the last line.
[0060] Specifically, such as Figure 4 As shown, the table recognition process corresponding to step 113 can be implemented through steps 1131 to 1138, specifically as follows:
[0061] Step 1131: For each of the multiple groups of horizontal lines, traverse each horizontal line in the group from top to bottom and from bottom to top respectively.
[0062] Step 1132: Determine if the current line is the last line; if not, proceed to step 1133; if yes, proceed to step 1138.
[0063] Step 1133: If the current line is not the last line, determine whether the first condition is met between the current line and the first line after the current line; if yes, proceed to step 1134; if no, proceed to step 1136.
[0064] The first condition is that there is text between the current line and the first line after the current line, and the text is separated by whitespace, and the distance between the text and the line is less than a second threshold.
[0065] Step 1134: If the current line and the first line after the current line satisfy the first condition, then the current line and the first line after the current line form a new first table.
[0066] Step 1135: Determine whether the current line is the second to last line. If not, proceed to step 1137; if yes, proceed to step 1138.
[0067] Step 1136: If the first condition is not met between the current line and the first line after the current line, then set the first line after the current line as the new current line, and return to execute step 1132, that is, return to execute the step of determining whether the current line is the last line.
[0068] Step 1137: If the current line is not the second to last line, set the second line after the current line as the new current line, and return to execute step 1132, that is, return to execute the step of determining whether the current line is the last line.
[0069] Step 1138: End the traversal process.
[0070] If the current line is the last line, then the traversal process ends.
[0071] If the current line is the second to last line, the traversal process ends.
[0072] The following combination Figure 5 An example flowchart further illustrates step 113:
[0073] Begin the traversal, traversing each horizontal line in each of the multiple groups of horizontal lines from top to bottom and from bottom to top respectively.
[0074] Step 113.1, set the current line to the first line;
[0075] Step 113.2, judging whether the current line line is the last line; if not, executing step 113.3; if yes, executing step 113.8;
[0076] Step 113.3, if the current line line is not the last line, judging whether there is text between the current line line and the next line, and the distance between the text and the line is less than the second threshold; if yes, executing step 113.4; if not, executing step 113.6;
[0077] Step 113.4, if there is text between the current line line and the next line, and the distance between the text and the line is less than the second threshold, constructing a new first table with the current line line and the next line.
[0078] Step 113.5, judging whether the current line line is the second last line; if not, executing step 113.7; if yes, executing step 113.8.
[0079] Step 113.6, setting the current line line = the first line after the current line line, i.e. setting the first line after the current line line as the new current line line, and returning to execute step 113.2.
[0080] Specifically, if there is no text between the current line line and the next line, setting the first line after the current line line as the new current line line; or, if there is text between the current line line and the next line, and the distance between the text and the line is not less than the second threshold, setting the first line after the current line line as the new current line line; or, if there is text between the current line line and the next line, and the distance between the text and the line is less than the second threshold, setting the first line after the current line line as the new current line line.
[0081] Step 113.7, if the current line line is not the second last line, setting the second line after the current line line as the new current line line, and returning to execute step 113.2.
[0082] Step 113.8, ending the traversal process.
[0083] Wherein, if the current line line is the last line, ending the traversal process.
[0084] Wherein, if the current line line is the second last line, ending the traversal process.
[0085] For example, the second threshold value can be set as 0.6 times the text height, such as 0.6*text height.
[0086] wherein, for each group of horizontal line groups, there are upper and lower positions on the document page, Figure 5 A traversal process is described, and the traversal order includes two categories, "from top to bottom" and "from bottom to top". For example, in the extreme case, a group of horizontal line groups A has only two horizontal lines, one horizontal line is located at the upper end of the horizontal line group A, marked as a; one horizontal line is located at the lower end of the horizontal line group A, marked as b, then a to b can be traversed in the order of a to b first, and the process of Figure 5 The flowchart shown, and then b to a in the order of b to a, and then execute the process of Figure 5 The flowchart shown again; in the two rounds, the first line corresponding to the first round is a, and the first line corresponding to the second round is b; in the case of clear order, the xth line thereafter is processed in a similar traversal process for each group of horizontal line groups in the multiple groups of horizontal line groups.
[0087] Step 114, merging the first table in the first table set to merge each two first tables in the first table set that exist common lines until there is no first table that can be merged in the first table set to obtain an updated first table set.
[0088] For example, set the first table set to S, and merge all first tables in the first table set S two by two, and the judgment basis for merging is that two first tables exist common lines until there is no first table that can be merged in the first table set S.
[0089] Step 115, determining the boundary coordinates of each first table in the updated first table set according to the coordinates of the lines contained in each first table in the updated first table set.
[0090] For example, based on the lines, a series of first tables are obtained, and according to the coordinates of the lines contained in each first table, the boundary coordinates of each first table can be determined.
[0091] Step 116, identifying the full-frame table and the half-frame table in the PDF document according to the number of horizontal lines, the number of vertical lines and the first threshold value in each first table of the updated first table set.
[0092] Specifically, tables in the updated first table set whose sum of the number of horizontal lines and the number of vertical lines is greater than a first threshold can be identified as full-frame tables; and tables in the updated first table set whose sum of the number of horizontal lines and the number of vertical lines is not greater than a first threshold can be identified as half-frame tables.
[0093] For example, to determine whether each table in the updated set of tables is a full-frame table, the criterion is that the sum of the number of horizontal lines and the number of vertical lines is greater than a first threshold. If it is determined to be a full-frame table, the boundary of each cell is directly defined according to the coordinates of the lines.
[0094] For example, the first threshold can be a value greater than or equal to 3.
[0095] Step 12: Locate the table based on the image in the PDF document to identify the second table in the PDF document, the second table including the frameless table.
[0096] In step 11, full-frame and half-frame tables can be located based on lines in the PDF document. However, the line-based method cannot accurately locate frameless tables. Therefore, image-based methods can be used to fill in the gaps and locate frameless tables.
[0097] In some embodiments, such as Figure 6 As shown, step 12 can be achieved through steps 121 to 123, specifically as follows:
[0098] Step 121: Convert the PDF document into an image in RGB format.
[0099] Step 122: The trained object detection model is used to identify the RGB format image corresponding to the PDF document to obtain the coordinate position of the second table in the PDF document, and all the second tables identified by the object detection model are added to the second table set.
[0100] In some embodiments, the method further includes: acquiring a training dataset, wherein each training data in the training dataset includes a training image and corresponding annotation information, the training image being obtained by converting a PDF document sample into an RGB format image, the annotation information including a labeled classification object corresponding to the training image and the coordinate position of each labeled classification object, the labeled classification object including at least a chart and a table; training an object detection model using the training dataset, such that the predicted classification object corresponding to the training image output by the object detection model is consistent with the labeled classification object corresponding to the training image, and the coordinate position of the predicted classification object output by the object detection model is consistent with the coordinate position of the labeled classification object, thus obtaining the trained object detection model.
[0101] Step 123: Perform table boundary determination processing on the second table set according to the coordinate position of the second table to identify all tables in the PDF document, including the first table and the second table.
[0102] For example, before recognition, pages in a PDF document sample can be converted into RGB format images. Then, a portion of the PDF page images can be sampled, and the coordinate positions of charts and tables in the page images can be labeled. These images are used as training images in the training dataset. The object detection model is trained using these training datasets. The input to the model is the RGB format training images, and the output of the model is the coordinate positions of different categories (such as charts and tables). For example, this object detection model could be the Cascade R-CNN model.
[0103] Then, the trained Cascade RCNN model is used to recognize the RGB format images corresponding to the PDF document, obtaining a series of charts and tables in the PDF document, as well as the coordinate positions of the charts and tables. All tables recognized by the model are added to a second table set M. For charts, the chart region map containing only the coordinate area can be determined based on the chart's coordinate position.
[0104] Then, the table boundary determination process is performed on the second set of tables M to obtain all the final tables in the PDF document. All tables include full-frame tables, half-frame tables, and borderless tables.
[0105] In some embodiments, such as Figure 7 As shown, the execution table boundary determination process corresponding to step 123 can be implemented through steps 1231 to 1333, specifically as follows:
[0106] Step 1231, iterate through each of the second tables in the second table set:
[0107] Step 1232, if there is an intersection between the boundary of the current second table and the boundary of a certain first table in the updated first table set according to the coordinate position of the second table, the boundary of the current second table is modified to the boundary of the first table in the updated first table set which has the largest intersection with the boundary of the current second table;
[0108] Step 1233, the current second table is added to the third table set, wherein the third table set is used to represent all the tables in the identified PDF document, and the third table set contains all the first tables in the updated first table set and all the second tables in the second table set after the adjustment of the table boundary.
[0109] Specifically, each second table in the second table set M is traversed: a. if there is an intersection between the boundary of the current second table T and the boundary of a certain first table in the first table set S, the boundary of the current second table T is modified to the boundary of the first table in the first table set S which has the largest intersection with the boundary of the current second table T; b. the current second table T is added to the final third table set K, wherein the final third table set K contains all the first tables in the first table set S and all the second tables in the second table set M after the adjustment of the table boundary.
[0110] The following further illustrates step 123 in combination with an example flowchart of Figure 8
[0111] Step 123.1, setting the current second table being traversed and processed as table T, and setting table T as the first second table in the second table set M;
[0112] Step 123.2, whether there is a first table in the first table set S which has an intersection with the boundary of table T; if yes, step 123.3 is executed; if no, step 123.4 is executed;
[0113] Step 123.3, if there is a certain first table in the first table set S which has an intersection with the boundary of table T, the boundary of table T is modified to the boundary of the first table in the updated first table set S which has the largest intersection with the boundary of table T;
[0114] Step 123.4, if there is no certain first table in the first table set S which has an intersection with the boundary of table T, table T is added to the final third table set K;
[0115] Step 123.5, judging whether table T is the last table in the second table set M; if no, step 123.6 is executed; if yes, step 123.7 is executed;
[0116] Step 123.6, set table T to be the next second table in the second table set M; and return to execute step 123.2;
[0117] Step 123.7, end the traversal process.
[0118] Step 20, identify a chart in the PDF document, the chart including at least content information displayed in a graphical manner.
[0119] A chart, a region where text and lines, graphics are mixed, is suitable for image processing.
[0120] In some embodiments, the identifying the chart in the PDF document includes:
[0121] By the trained target detection model, the RGB format image corresponding to the PDF document is identified to obtain the chart in the PDF document and the coordinate position of the chart.
[0122] According to the coordinate position of the chart, a chart region map is determined, which only contains the coordinate region in the chart, and the chart region map is used to embed the chart in the HTML document in the form of an image.
[0123] For example, a trained Cascade RCNN model can be used to identify the RGB format image corresponding to the PDF document to obtain a series of charts and tables in the PDF document, as well as the coordinate positions of the charts and tables, and all the tables identified by the model are added to the second table set M. For the chart, according to the coordinate position of the chart, a chart region map is determined, which only contains the coordinate region in the chart.
[0124] Step 40, according to the table and the chart, the PDF document is converted into an HTML document, wherein the table converted in the HTML document is in HTML format, and the chart converted in the HTML document is in image form.
[0125] Specifically, the tables and charts in the PDF document can be identified, wherein the tables include at least one of full-frame tables, half-frame tables, and frameless tables, and when the PDF document is converted into an HTML document, the tables are converted into HTML format, and the charts are converted into image form.
[0126] In some embodiments, as Figure 9 shown, the method further includes step 30:
[0127] Step 30, identify the text and the layout of the PDF document, the layout including at least one of single-column layout, double-column layout, and multi-column layout.
[0128] Single-column layout, indicating that the reading order of different paragraphs is from top to bottom, and the document as a whole has only one column.
[0129] Double / multi-column layout, indicating that the document as a whole has two or more columns (part of the table may span columns), and the reading order of different paragraphs is from top to bottom within the column and from left to right between columns.
[0130] Specifically, the layout of the PDF document can also be identified, and the layout includes at least one of single-column layout, double-column layout, and multi-column layout. The reading order is determined according to the layout, and the PDF document as a whole is converted into an HTML document in HTML form according to the correct reading order, thereby improving the accuracy of the PDF document parsing format conversion.
[0131] In some embodiments, step 40 can be implemented by step 401, specifically:
[0132] Step 401, converting the PDF document into an HTML document according to the table, the chart, the text, and the layout.
[0133] Specifically, the table and chart in the PDF document can be identified, wherein the table includes at least one of a full-frame table, a half-frame table, and a frameless table. Further, the layout of the PDF document can also be identified, and the layout includes at least one of single-column layout, double-column layout, and multi-column layout. When converting the PDF document into an HTML document, the table is converted into HTML format, the chart is converted into picture form, the reading order is determined according to the layout, and the PDF document as a whole is converted into an HTML document in HTML form according to the correct reading order, thereby improving the accuracy of the PDF document parsing format conversion.
[0134] In some embodiments, as shown in Figure 10 step 401 can be implemented by steps 41 to 45, specifically:
[0135] Step 41, obtaining the row and column positions of each cell in the table, and obtaining the text in each cell, and converting the table into HTML form according to the row and column positions of each cell and the text in each cell.
[0136] Wherein, the table is composed of cells, so when converting the table into HTML form, the row and column positions of each cell and the text in each cell in the table need to be determined first, and then the table is converted into HTML form.
[0137] In some embodiments, as shown in Figure 11 step 41 can be implemented by steps 411 to 413, specifically:
[0138] Step 411, table column generation processing is performed on the table to obtain a column set of the table, and the horizontal coordinate boundary of each column is determined according to the text to which each column belongs.
[0139] In some embodiments, the table column generation processing is performed on the table to obtain a column set of the table, including: obtaining a text set containing all texts in a table region of the table, initializing the column set of the table, and initializing the event identifier of the column set to no; determining whether there is a first text in the text set that does not belong to any column; if there is a first text in the text set that does not belong to any column, finding all second texts in the text set covered by the first text in the vertical direction to obtain a second text set, wherein the horizontal coordinates of the second texts in the second text set are all covered by the horizontal coordinate of the first text; dividing the second texts in the second text set into text lines, wherein there is no intersection of vertical coordinates between the text lines; if the number of the text lines is greater than or equal to the number of texts in the second text set, the second texts in the second text set form a new column, which is added to the column set, and the event identifier of the column set is set to yes; traversing all texts in the text set until there is no first text in the text set that belongs to any column; if the event identifier of the column set is yes, merging the columns in the column set according to a second merging condition, wherein the second merging condition is that the horizontal coordinate of one column is completely covered by the horizontal coordinate of another column.
[0140] The following further illustrates step 411 in conjunction with an example flowchart of FIG. 4: Figure 12
[0141] Step 411.1, initialization setting: columns = empty column set, texts = all texts in the table boundary region, changed = no;
[0142] Wherein, texts can be defined as a text set containing all texts in the table region of the table;
[0143] Step 411.2, determining whether there is a first text in texts that does not belong to any column; if yes, performing step 411.3; if no, performing step 411.8;
[0144] Step 411.3, t = texts next first text that does not belong to any column;
[0145] Step 411.4, covered = texts all second texts covered by t in horizontal coordinate;
[0146] covered = covered intersected with texts;
[0147] Step 411.5, divide the second texts in covered into text lines, and there is no intersection of vertical coordinates between the text lines, let row_count be the number of the text lines;
[0148] Step 411.6, judge whether row_count is greater than or equal to the number of texts in covered; if yes, execute step 411.7; if no, return to execute step 411.2;
[0149] Step 411.7, generate a new column with the second texts in covered, and add it to columns; set changes = yes; then return to execute step 411.2;
[0150] If the value of row_count is greater than or equal to the number of texts in covered, it means that there is no intersection of horizontal coordinates between these texts, and they can form a separate column. Then a new column is generated with the second texts in covered, and added to columns, and the variable changed is set to "yes". Until there is no text in texts belonging to any column, step 411.8 is executed.
[0151] Step 411.8, until there is no first text in texts belonging to any column, judge whether changes is yes; if yes, execute step 411.9; if no, execute step 411.10;
[0152] Step 411.9, merge the columns in columns, and the merging condition is that the horizontal coordinates of one column are completely covered by the horizontal coordinates of another column;
[0153] Step 411.10, form a column with all the texts in texts, and add it to columns.
[0154] In Figure 12In some embodiments, texts represents all the texts in the table region after the table boundary is given; changed represents a visual identifier for identifying whether a new column is found in the loop; covered represents all the second texts covered by t in the vertical direction, for example, if texts is t and the horizontal coordinates are x0 and x1, then for any e in texts, if e.x0≥t.x0 and e.x1≤t.x1, then e is a text in covered, e is equivalent to t covering other texts in the horizontal direction; row_count represents the number of rows in covered, and there is no vertical coordinate intersection between rows; columns represents all the columns found.
[0155] In particular, for each semi-frame table or frameless table, the column set columns of the table can be obtained by performing the table column generation process as shown in Figure 12 , and each column has its own text, so the horizontal coordinate boundary of each column can be determined according to the text belonging to each column.
[0156] In step 412, the table row generation process is performed on the table to obtain the row set of the table, and the vertical coordinate boundary of each row is determined according to the text belonging to each row.
[0157] In some embodiments, the table row generation process is performed on the table to obtain the row set of the table, including: obtaining a text set containing all the texts in the table region of the table, initializing the row set of the table, and initializing the event identifier of the row set to no; determining whether there is a third text in the text set that does not belong to any row; if there is a third text in the text set that does not belong to any row, finding all fourth texts covered by the third text in the horizontal direction from the text set to obtain a fourth text set, wherein the vertical coordinates of the fourth texts in the fourth text set are all covered by the vertical coordinates of the third text; dividing the fourth texts in the fourth text set into text columns, wherein there is no intersection of horizontal coordinates between the text columns; if the number of text columns is greater than or equal to the number of texts in the fourth text set, then the fourth texts in the fourth text set form a new row, which is added to the row set, and the event identifier of the row set is set to yes; traversing all the texts in the text set until there is no third text in the text set that belongs to any row; if the event identifier of the row set is yes, then the columns in the column set are merged according to a third merging condition, wherein the third merging condition is that the vertical coordinate of one row is completely covered by the vertical coordinate of another row.
[0158] The following further illustrates step 412 in conjunction with an example flowchart in Figure 13 :
[0159] Step 412.1, initialize setting: rows = empty row set, texts = all texts in the table border area, changed = no;
[0160] Step 412.2, judge whether there is a third text in texts which does not belong to any row; if yes, execute step 412.3; if no, execute step 412.8;
[0161] Step 412.3, make t = the next third text in texts which does not belong to any row;
[0162] Step 412.4, make covered = all fourth texts in texts which are contained by t in the vertical coordinate;
[0163] covered = all fourth texts covered by t in the horizontal direction, covered can be defined as a fourth text set containing all fourth texts, and the vertical coordinates of all fourth texts in covered are covered by the vertical coordinate of t;
[0164] Step 412.5, divide the texts in covered into text columns, and there is no intersection of horizontal coordinates between the text columns, make col_count = the number of text columns;
[0165] Step 412.6, judge whether col_count is greater than or equal to the number of texts in covered; if yes, execute step 412.7; if no, return to execute step 412.2;
[0166] Step 412.7, generate a new row with the fourth texts in covered and add it to rows, set changed = yes, and then return to execute step 412.2;
[0167] If the value of col_count is greater than or equal to the number of texts in covered, it means that these texts have no intersection of vertical coordinates and can form a separate row, so a new column is formed with the fourth texts in covered and added to rows, and the changed variable is set to "yes"; until there is no third text in texts which belongs to any row, step 412.8 is executed;
[0168] Step 412.8, until there is no third text in texts which belongs to any row, judge whether changed is yes; if yes, execute step 412.9; if no, execute step 412.10;
[0169] Step 412.9, merge rows in rows, the merging condition is that the ordinate of one row is completely covered by the ordinate of another row.
[0170] Step 412.10, form a row with all texts in texts, and add the row to rows.
[0171] In Figure 13 , texts represent all texts in the table region after the given table boundary; changed represents a visual identifier for identifying whether a new row is found in the loop; covered represents all fourth texts covered by t in the horizontal direction, such as texts t with ordinate y0 and y1, for any e in texts, if e.y0≥t.y0 and e.y1≤t.y1, then e is a text in covered, and e is equivalent to other texts covered by t in the ordinate; col_count represents the number of columns of texts in covered, and there is no horizontal coordinate intersection between columns. Rows represent all rows found.
[0172] Specifically, for each semi-frame table or frameless table, by executing the table row generation process as shown in Figure 13 , the row set rows of the table can be obtained, and each row has its own text, so the ordinate boundary of each row can be determined according to the text belonging to each row.
[0173] Step 413, generate a plurality of cells according to the column set and the row set, determine the text and coordinates in each cell according to the text belonging to each column, the text belonging to each row, the horizontal coordinate boundary of each column and the ordinate boundary of each row, and merge the cells with coordinate intersection in the plurality of cells to obtain the row and column positions of each cell in the table.
[0174] For example, according to the size of the column set columns (denoted as C) and the size of the row set rows (denoted as R), C*R cells are generated, and the text and coordinates in each cell are determined according to the text belonging to each column, the text belonging to each row, the horizontal coordinate boundary of each column and the ordinate boundary of each row, and the cells with coordinate intersection are merged.
[0175] For each table, after obtaining the boundary and text of each cell, the table can be directly converted into an HTML form.
[0176] Step 42, merge the texts other than the table and the chart according to a first merging condition to obtain a plurality of different paragraphs, wherein the first merging condition is that the distance between the texts is less than a third threshold.
[0177] The text outside the chart region of the chart can be merged according to the merging condition.
[0178] The third threshold value can be divided into a horizontal coordinate threshold value and a vertical coordinate threshold value. Let L be the minimum value of the heights of the two pairs of text. Then the horizontal coordinate threshold value is 0.75*L, and the vertical coordinate threshold value is 1.5*L.
[0179] Step 43, identifying the horizontal coordinate positions of each column in the layout.
[0180] In some embodiments, as shown in FIG. 43, step 43 can be implemented by steps 431 to 436, specifically: Figure 14
[0181] Step 431, initializing an array and setting a fourth threshold value M, wherein the length of the array is equal to the width of the page of the PDF document, the initial variable value of the array is 0, and the M is a positive integer greater than 0;
[0182] Step 432, setting the variable value of each position in the array to the number of texts on each horizontal coordinate in the page of the PDF document;
[0183] Step 433, setting the variable values corresponding to each continuous M horizontal coordinates as a group of sub-arrays;
[0184] Step 434, if there is a first sub-array in which the variable values corresponding to the M horizontal coordinates are all 0, and the variable values corresponding to the M horizontal coordinates in the second sub-arrays on the left and right sides of the first sub-array are all greater than a fifth threshold value, then the first sub-array is determined as a boundary;
[0185] Step 435, determining the number of columns in the layout according to the number of boundaries, wherein the number of columns is the sum of the number of boundaries and 1;
[0186] Step 436, identifying the horizontal coordinate positions of each column in the layout according to the horizontal coordinate positions corresponding to the boundaries in the page of the PDF document.
[0187] For example, the fourth threshold value M is the width of the page of the PDF document divided by 20; and the fifth threshold value is 1.05 times the smallest text height in the document.
[0188] For example, an empty array v is initialized with the length of the width of the PDF page, and the initial value is 0, and a fourth threshold M is defined; the value of each position in the array v is the number of texts in the horizontal coordinate, that is, the texts on the page are projected vertically onto the horizontal coordinate, the more texts, the higher the value of the array; every M horizontal coordinates are a group, if the values of the M horizontal coordinates in the array v are all 0, and the values of the horizontal coordinates on the left and right are greater than the fifth threshold, it is regarded as a boundary, which means that this region of the page is blank, but the left and right are with texts, which is usually the boundary between columns; after all the boundaries are found, all the columns can be obtained, and the number of columns = the number of boundaries + 1; according to the horizontal coordinate position of the boundary in the page of the PDF document, the horizontal coordinate position of each column in the layout is recognized.
[0189] Step 44, according to the horizontal coordinate position of each column in the layout and the corresponding reading order of the layout, the table, the chart and the paragraph are sorted.
[0190] For example, all tables, charts and paragraphs are sorted, and the sorting principle is that the elements in the column are from top to bottom, and the columns are from left to right.
[0191] Step 45, according to the sorting result, the table, the chart and the paragraph are output in HTML form, and the PDF document is converted into an HTML document, wherein the table is output in HTML form, the chart is output in the form of a picture embedded in the HTML document, and the paragraph is output in the form of paragraph text HTML.
[0192] For example, all elements in the PDF document are output in HTML form in order, the paragraph is output in the form of ordinary paragraph text HTML, the chart is output in the form of chart area graph embedded in the HTML document in the form of picture, and the table is output in the form of HTML, so as to obtain the HTML document corresponding to the entire PDF document.
[0193] Please refer to Figure 15 and Figure 16 , Figure 15 The PDF document with charts, multiple tables and double-column layout is shown, and after the document format conversion, the HTML document as shown in Figure 16 is obtained, based on the double-column or multiple-column layout, the PDF document can be converted into an HTML document according to the correct reading order (the elements in the column are from top to bottom, and the columns are from left to right), and multiple tables existing in the PDF document can be recognized, and each element in the HTML document can be sorted according to the correct reading order. For example, according to the correct reading order, as Figure 15The left column displays Text 1, Chart 1, Text 2, and Table 1; the right column displays Text 3, Table 2, Text 4, and Table 3. Table 1 is a half-border table, Table 2 is a borderless table, and Table 3 is a full-border table. After document format conversion, in Figure 16 The chart in Figure 1 will be inserted as an image into the HTML document for output. Figure 16 The code converts Tables 1, 2, and 3 into HTML format for output, allowing for proper reading order. Figure 16 The HTML document shown has the following element order from front to back: Text1, Chart1, Text2, Table1, Text3, Table2, Text4, and Table3.
[0194] The embodiments of this application can locate tables based on lines. This mainly involves grouping horizontal parallel lines and traversing each group of lines from top to bottom and from bottom to top. By traversing in the reverse order, omissions can be avoided. Then, the tables are merged, effectively obtaining the position of the tables based on the lines.
[0195] The embodiments of this application can also locate and correct tables based on images. They mainly utilize the Cascade RCNN model to identify the positions of charts and tables in PDFs, and use the table obtained by locating tables based on lines to jointly determine the table position, so that the whole method can take into account the accuracy of full-frame tables and half-frame / no-frame tables.
[0196] This application embodiment can convert tables into HTML format. It is mainly based on the table column generation and table row generation process, uses coordinate overlay to spontaneously aggregate text, and uses coordinate overlap to determine the existence of rows / columns, thereby generating the final cells.
[0197] The embodiments of this application can perform layout recognition and final HTML conversion. It mainly utilizes vertical projection to consider the one-dimensional spatial characteristics of the text and uses an image-like method to determine whether the layout is single / double / multi-column, rather than relying on the content of the text.
[0198] All of the above technical solutions can be combined in any way to form optional embodiments of this application, and will not be described in detail here.
[0199] The embodiment of the present application can effectively identify various elements in the PDF document, such as full-frame table, half-frame table, frameless table, chart, paragraph, and layout, and convert them into an HTML document, thereby improving the accuracy of the PDF document format conversion.
[0200] To better implement the document format conversion method of the embodiment of the present application, the embodiment of the present application further provides a document format conversion device. Please refer to Figure 17 , Figure 17 The structure diagram of the document format conversion device provided by the embodiment of the present application is shown in FIG. 2. The document format conversion device 200 can include:
[0201] The first identification unit 201 is configured to identify a table in the PDF document, wherein the table includes at least one of a full-frame table, a half-frame table, and a frameless table.
[0202] The second identification unit 202 is configured to identify a chart in the PDF document, wherein the chart includes at least content information displayed in a graphical manner.
[0203] The conversion unit 204 is configured to convert the PDF document into an HTML document according to the table and the chart, wherein the table converted in the HTML document is in an HTML form, and the chart converted in the HTML document is in a picture form.
[0204] In some embodiments, the first identification unit 201 is configured to: position a table based on lines in the PDF document to identify a first table in the PDF document, wherein the first table includes at least one of the full-frame table and the half-frame table.
[0205] In some embodiments, the first identifying unit 201, when identifying the first table in the PDF document based on the lines in the PDF document, specifically configured to: identify the text, lines, coordinates of each line, and width and height between each two lines in the PDF document, wherein the lines include horizontal lines and vertical lines; determine a plurality of groups of horizontal lines that are parallel to each other and have similar or identical lengths from the coordinates of all horizontal lines and the width between each two horizontal lines, wherein each group of horizontal lines includes two horizontal lines that are parallel to each other and have similar or identical lengths; initialize a first table set, and for each group of horizontal lines in the plurality of groups of horizontal lines, perform table identification processing from top to bottom and from bottom to top for each horizontal line in the plurality of groups of horizontal lines, and add all first tables identified in the table identification processing to the first table set; perform merging processing on the first tables in the first table set to merge each two first tables in the first table set that have common lines until there is no first table that can be merged in the first table set, to obtain an updated first table set; determine the boundary coordinates of each first table in the updated first table set according to the coordinates of the lines included in each first table in the updated first table set; and identify the full-frame table and the half-frame table in the PDF document according to the number of horizontal lines, the number of vertical lines, and a first threshold in each first table in the updated first table set.
[0206] In some embodiments, the first identifying unit 201, when identifying the full-frame table and the half-frame table in the PDF document according to the number of horizontal lines, the number of vertical lines, and a first threshold in each first table in the updated first table set, is specifically configured to: identify the table in the updated first table set as the full-frame table if the sum of the number of horizontal lines and the number of vertical lines is greater than the first threshold; and identify the table in the updated first table set as the half-frame table if the sum of the number of horizontal lines and the number of vertical lines is not greater than the first threshold.
[0207] In some embodiments, the first identifying unit 201 is specifically configured to, when performing the table identifying process on each horizontal line in each group of horizontal lines from top to bottom and from bottom to top respectively, for each group of horizontal lines, traverse each horizontal line in the group of horizontal lines from top to bottom and from bottom to top respectively; determine whether the current line is the last line; if the current line is not the last line, determine whether a first condition is met between the current line and the first line after the current line, wherein the first condition is that there is text between the current line and the first line after the current line, and there is a blank separation between the texts, and the distance between the texts and the lines is less than a second threshold; if the first condition is met between the current line and the first line after the current line, form a new first table with the current line and the first line after the current line; determine whether the current line is the second last line; and if the current line is the second last line, end the traversal process.
[0208] In some embodiments, after determining whether the current line is the last line, the first identifying unit 201 is further configured to, if the current line is the last line, end the traversal process.
[0209] In some embodiments, after determining whether the first condition is met between the current line and the first line after the current line, the first identifying unit 201 is further configured to, if the first condition is not met between the current line and the first line after the current line, set the first line after the current line as a new current line, and return to the step of determining whether the current line is the last line.
[0210] In some embodiments, after determining whether the current line is the second last line, the first identifying unit 201 is further configured to, if the current line is not the second last line, set the second line after the current line as a new current line, and return to the step of determining whether the current line is the last line.
[0211] In some embodiments, the first identifying unit 201 is further configured to: locate the table based on the image in the PDF document to identify a second table in the PDF document, wherein the second table includes the frameless table.
[0212] In some embodiments, the first identifying unit 201, when locating the table in the PDF document based on the image to identify the second table in the PDF document, is specifically configured to: convert the PDF document into an image in RGB format; identify the image in RGB format corresponding to the PDF document through the trained target detection model to obtain the second table in the PDF document and the coordinate position of the second table, and add all the second tables identified by the target detection model to a second table set; and perform table boundary determination processing on the second table set according to the coordinate position of the second table to identify all the tables in the PDF document, wherein the all the tables include the first table and the second table.
[0213] In some embodiments, the first identifying unit 201, when performing the table boundary determination processing on the second table set according to the coordinate position of the second table to identify all the tables in the PDF document, is specifically configured to: traverse each second table in the second table set; if it is determined according to the coordinate position of the second table that there is an intersection of boundaries between the current second table and a certain first table in the updated first table set, modify the boundary of the current second table to the boundary of the first table in the updated first table set that has the largest intersection with the boundary of the current second table; and add the current second table to a third table set, wherein the third table set is used to represent all the tables identified in the PDF document, and the third table set contains all the first tables in the updated first table set and all the second tables in the second table set after the boundary adjustment.
[0214] In some embodiments, as shown in Figure 18 The document format conversion apparatus 200 further includes a training unit 205.
[0215] The training unit 205 can be configured to: obtain a training data set, wherein each training data in the training data set includes a training image and annotation information corresponding to the training image, the training image is obtained by converting a PDF document sample into an image in RGB format, the annotation information includes an annotation classification object corresponding to the training image and a coordinate position of each annotation classification object, and the annotation classification object at least includes a chart and a table; and train a target detection model using the training data set to obtain the trained target detection model when a predicted classification object output by the target detection model is consistent with the annotation classification object corresponding to the training image, and the coordinate position of the predicted classification object output by the target detection model is consistent with the coordinate position of the annotation classification object.
[0216] In some embodiments, the second identification unit 202 is specifically configured to: identify an image in RGB format corresponding to the PDF document by using the trained target detection model to obtain a chart in the PDF document and a coordinate position of the chart; and determine a chart region map in which only a coordinate region is included in the chart according to the coordinate position of the chart, the chart region map being used to embed the chart in the HTML document in the form of a picture.
[0217] In some embodiments, the document format conversion apparatus 200 further includes a third identification unit 203.
[0218] The third identification unit 203 is configured to identify text and a layout of the PDF document, the layout including at least one of a single-column layout, a double-column layout, and a multi-column layout.
[0219] The conversion unit 204 is further configured to convert the PDF document into an HTML document according to the table, the chart, the text, and the layout.
[0220] In some embodiments, when converting the PDF document into an HTML document according to the table, the chart, the text paragraph, and the layout, the conversion unit 204 is specifically configured to: obtain a row-column position of each cell in the table and text in each cell, and convert the table into an HTML form according to the row-column position of each cell and the text in each cell; merge text other than the table and the chart according to a first merging condition to obtain a plurality of different paragraphs, wherein the first merging condition is that a distance between the text is less than a third threshold; identify a horizontal coordinate position of each column in the layout; sort the table, the chart, and the paragraphs according to the horizontal coordinate position of each column in the layout and a corresponding reading order of the layout; and output the table, the chart, and the paragraphs in an HTML form according to a sorting result, to convert the PDF document into an HTML document, wherein the table is output in an HTML form, the chart is embedded in the HTML document in the form of a picture, and the paragraphs are output in an HTML form of paragraph text.
[0221] In some embodiments, when merging text other than the table and the chart according to the first merging condition, the conversion unit 204 can be configured to merge text other than a chart region map of the chart according to a merging condition.
[0222] In some embodiments, the chart region map of the chart is output in the form of a picture embedded in the HTML document.
[0223] In some embodiments, the conversion unit 204, in obtaining the row-column position of each cell in the table, is specifically configured to: perform a table column generation process on the table to obtain a column set of the table, and determine a horizontal coordinate boundary of each column according to the text belonging to each column; perform a table row generation process on the table to obtain a row set of the table, and determine a vertical coordinate boundary of each row according to the text belonging to each row; generate a plurality of cells according to the column set and the row set, and determine the text and coordinates in each cell according to the text belonging to each column, the text belonging to each row, the horizontal coordinate boundary of each column, and the vertical coordinate boundary of each row; and perform a merging process on cells having coordinate intersections in the plurality of cells to obtain the row-column position of each cell in the table.
[0224] In some embodiments, the conversion unit 204, in performing a table column generation process on the table to obtain a column set of the table, is specifically configured to: obtain a text set containing all the texts in a table region of the table, and initialize the column set of the table and the event identifier of the column set to no; determine whether there is a first text in the text set that does not belong to any column; if there is a first text in the text set that does not belong to any column, find all second texts in the text set that are covered by the first text in the vertical direction to obtain a second text set, wherein the horizontal coordinates of the second texts in the second text set are all covered by the horizontal coordinate of the first text; divide the second texts in the second text set into text rows, wherein there is no intersection of vertical coordinates between the text rows; if the number of the text rows is greater than or equal to the number of texts in the second text set, form a new column with the second texts in the second text set, add the new column to the column set, and set the event identifier of the column set to yes; traverse all the texts in the text set until there is no first text in the text set that belongs to any column; and if the event identifier of the column set is yes, merge the columns in the column set according to a second merging condition, wherein the second merging condition is that the horizontal coordinate of one column is completely covered by the horizontal coordinate of another column.
[0225] In some embodiments, the conversion unit 204 is specifically configured to: obtain a text set containing all texts in a table region of the table, and initialize a row set of the table and an event identifier of the row set to no when performing a table row generation process on the table to obtain the row set of the table; determine whether there is third text not belonging to any row in the text set; if there is third text not belonging to any row in the text set, find all fourth texts covered by the third text in a horizontal direction from the text set to obtain a fourth text set, wherein the fourth texts in the fourth text set are all covered by the vertical coordinate of the third text; divide the fourth texts in the fourth text set into text columns, wherein there is no intersection of horizontal coordinates between the text columns; if the number of the text columns is greater than or equal to the number of texts in the fourth text set, form a new row with the fourth texts in the fourth text set, add the new row to the row set, and set the event identifier of the row set to yes; traverse all texts in the text set until there is no third text belonging to any row in the text set; and if the event identifier of the row set is yes, merge columns in the column set according to a third merging condition, wherein the third merging condition is that the vertical coordinate of one row is completely covered by the vertical coordinate of another row.
[0226] In some embodiments, the conversion unit 204 is specifically configured to: initialize an array and set a fourth threshold M, wherein the length of the array is equal to the width of a page of the PDF document, the initial variable value of the array is 0, and the M is a positive integer greater than 0; set the variable value of each position of the array to the number of texts at each horizontal coordinate in the page of the PDF document; set the variable values corresponding to each continuous M horizontal coordinates as a group of sub-arrays; if there is a first sub-array in which the variable values corresponding to the M horizontal coordinates are all 0 in the array, and the variable values corresponding to the M horizontal coordinates in the second sub-arrays on the left and right sides of the first sub-array are all greater than a fifth threshold, determine the first sub-array as a boundary; determine the number of columns in the layout according to the number of boundaries, wherein the number of columns is the sum of the number of boundaries and 1; and identify the horizontal coordinate position of each column in the layout according to the horizontal coordinate position corresponding to the boundary in the page of the PDF document.
[0227] The units in the document format conversion apparatus 200 described above can be all or partially implemented by software, hardware, and combinations thereof. The units described above can be embedded in or independent of a processor in a computer device in a hardware form, or stored in a memory in a computer device in a software form, so as to be called and executed by a processor to perform the operations corresponding to the units described above.
[0228] The document format conversion apparatus 200 can be integrated in a terminal or a server having a storage and a processor installed to have a computing capability, or the document format conversion apparatus 200 is the terminal or the server.
[0229] In some embodiments, the present application also provides a computer device including a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above-mentioned method embodiments when executing the computer program.
[0230] As Figure 19 shown, Figure 19 A structural schematic diagram of a computer device provided by the embodiments of the present application is shown in the figure, and the computer device can be a terminal. The computer device 300 includes a processor 301 having one or more processing cores, a memory 302 having one or more computer readable storage media, and a computer program stored in the memory 302 and executable on the processor. The processor 301 is electrically connected to the memory 302. Those skilled in the art can understand that the computer device structure shown in the figure does not constitute a limitation on the computer device, and can include more or fewer components than shown in the figure, or combine certain components, or different component arrangements.
[0231] The processor 301 is the control center of the computer device 300, and connects various parts of the entire computer device 300 through various interfaces and lines. By running or loading the software program and / or module stored in the memory 302 and calling the data stored in the memory 302, the processor 301 performs various functions and processes data of the computer device 300, thereby performing overall processing of the computer device 300.
[0232] In the embodiments of the present application, the processor 301 in the computer device 300 will load the instructions corresponding to the processes of one or more application programs into the memory 302, and run the application programs stored in the memory 302 by the processor 301, thereby realizing various functions:
[0233] Identify a table in a PDF document, the table including at least one of a full-frame table, a half-frame table, and a frameless table; identify a chart in the PDF document, the chart including at least content information displayed in a graphical manner; convert the PDF document into an HTML document according to the table and the chart, wherein the table converted in the HTML document is in an HTML form, and the chart converted in the HTML document is in a picture form.
[0234] The specific implementation of each operation can refer to the previous embodiments, which will not be repeated here.
[0235] In some embodiments, as shown in FIG. 3, Figure 19 The computer device 300 further includes a touch display 303, a radio frequency circuit 304, an audio circuit 305, an input unit 306, and a power supply 307. The processor 301 is electrically connected with the touch display 303, the radio frequency circuit 304, the audio circuit 305, the input unit 306, and the power supply 307, respectively. Those skilled in the art can understand that the computer device structure shown in the figure does not constitute a limitation on the computer device, which can include more or fewer components than the figure, or combine certain components, or different component arrangements. Figure 19 The computer device structure shown in the figure does not constitute a limitation on the computer device, which can include more or fewer components than the figure, or combine certain components, or different component arrangements.
[0236] The touch display 303 can be used to display a graphical user interface and receive operation instructions generated by a user acting on the graphical user interface. The touch display 303 can include a display panel and a touch panel. The display panel can be used to display information input by a user or information provided to a user and various graphical user interfaces of the computer device, which can be composed of graphics, text, icons, videos, and any combination thereof. In some embodiments, the display panel can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like. The touch panel can be used to collect touch operations of a user thereon or adjacent thereto (such as operations of a user using a finger, a stylus, or any suitable object or accessory on or adjacent to the touch panel), and generate corresponding operation instructions, and the operation instructions execute corresponding programs. In some embodiments, the touch panel can include two parts, a touch detection device and a touch controller. The touch detection device detects the touch position of the user and detects the signals brought by the touch operation, and transmits the signals to the touch controller; the touch controller receives the touch information from the touch detection device, and converts it into touch coordinates, and then sends it to the processor 301, and can also receive commands from the processor 301 and execute them. The touch panel can cover the display panel, and when the touch panel detects a touch operation thereon or adjacent thereto, it transmits to the processor 301 to determine the type of the touch event, and then the processor 301 provides corresponding visual output on the display panel according to the type of the touch event. In the embodiments of the present application, the touch panel and the display panel can be integrated into the touch display 303 to realize the input and output functions. However, in some embodiments, the touch panel and the touch panel can realize the input and output functions as two independent components. That is, the touch display 303 can also realize the input function as part of the input unit 306.
[0237] The radio frequency circuit 304 can be used to transceive radio frequency signals to establish wireless communication with a network device or other computer device, and transceive signals between the network device or other computer device.
[0238] The audio circuit 305 can be configured to provide an audio interface between a user and the computer device through a speaker and a microphone. The audio circuit 305 can convert received audio data into an electrical signal and transmit the electrical signal to the speaker for conversion into an audible signal. On the other hand, the microphone can collect a sound signal and convert the sound signal into an electrical signal, which is received by the audio circuit 305 and converted into audio data. The audio data can be output to the processor 301 for processing, and then transmitted to another computer device through the radio frequency circuit 304 or stored in the memory 302 for further processing. The audio circuit 305 can further include a jack for a headset to provide communication between the headset and the computer device.
[0239] The input unit 306 can be configured to receive inputted digital, character information or object feature information (e.g., fingerprint, iris, face information, etc.), and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.
[0240] The power supply 307 can be configured to supply power to various components of the computer device 300. In some embodiments, the power supply 307 can be logically connected to the processor 301 through a power management system, so that the power management system can manage charging, discharging, power consumption management, etc. The power supply 307 can further include one or more direct current or alternating current power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, etc.
[0241] Although Figure 19 The computer device 300 can further include a camera, a sensor, a wireless fidelity module, a Bluetooth module, etc., which are not shown in the figure.
[0242] The present application further provides a computer readable storage medium for storing a computer program. The computer readable storage medium can be applied to a computer device, and the computer program causes the computer device to perform corresponding procedures in the document format conversion method according to the embodiments of the present application. For brevity, details are not described herein.
[0243] The present application further provides a computer program product including a computer program stored in a computer readable storage medium. The processor of the computer device reads the computer program from the computer readable storage medium, and the processor executes the computer program, so that the computer device performs corresponding procedures in the document format conversion method according to the embodiments of the present application. For brevity, details are not described herein.
[0244] The application further provides a computer program, which comprises a computer program stored in a computer readable storage medium. A processor of a computer device reads the computer program from the computer readable storage medium, and executes the computer program, so that the computer device executes corresponding procedures in the document format conversion method in the embodiments of the application. For brevity, details are not described herein again.
[0245] It should be understood that the processor in the embodiments of the application can be an integrated circuit chip with processing capability of signals. In the implementation process, each step of the method embodiments can be completed by integrated logic circuits or instructions in the form of software in the processor. The processor can be a general processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. Each method, step and logic block diagram disclosed in the embodiments of the application can be implemented or executed. The steps of the method disclosed in the embodiments of the application can be directly embodied as hardware code processing executed by the processor, or executed by a combination of hardware and software modules in the code processing processor. The software module can be located in a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, and other mature storage media in the art. The storage medium is located in the storage, and the processor reads the information in the storage, and combines the hardware to complete the steps of the above method.
[0246] It is to be understood that the memory in the embodiments of the present application can be a volatile memory or a nonvolatile memory, or can include both volatile and nonvolatile memory. Among them, the nonvolatile memory can be a read-only memory (Read-Only Memory, ROM), a programmable read-only memory (Programmable ROM, PROM), an erasable programmable read-only memory (Erasable PROM, EPROM), an electrically erasable programmable read-only memory (Electrically EPROM, EEPROM) or a flash memory. The volatile memory can be a random access memory (Random Access Memory, RAM) used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (Static RAM, SRAM), dynamic random access memory (Dynamic RAM, DRAM), synchronous dynamic random access memory (Synchronous DRAM, SDRAM), double data rate synchronous dynamic random access memory (Double Data Rate SDRAM, DDR SDRAM), enhanced synchronous dynamic random access memory (Enhanced SDRAM, ESDRAM), synchronous link dynamic random access memory (Synchlink DRAM, SLDRAM) and direct memory bus random access memory (Direct Rambus RAM, DR RAM). It should be noted that the memory of the system and method described herein is intended to include, but not limited to, these and any other suitable types of memory.
[0247] It should be understood that the above-mentioned memory is exemplary but not limiting, for example, the memory in the embodiments of the present application can also be static random access memory (static RAM, SRAM), dynamic random access memory (dynamic RAM, DRAM), synchronous dynamic random access memory (synchronous DRAM, SDRAM), double data rate synchronous dynamic random access memory (double data rate SDRAM, DDR SDRAM), enhanced synchronous dynamic random access memory (enhanced SDRAM, ESDRAM), synchronous link dynamic random access memory (synch link DRAM, SLDRAM) and direct memory bus random access memory (Direct Rambus RAM, DR RAM) and the like. That is, the memory in the embodiments of the present application is intended to include, but not limited to, these and any other suitable types of memory.
[0248] Those skilled in the art can clearly understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0249] Those skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working processes of the above-described system, device and unit can refer to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
[0250] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division, and there can be another division manner in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interface, device or unit, and can be electrical, mechanical or other forms.
[0251] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. they can be located in one place or distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0252] In addition, each functional unit in the embodiments of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0253] When the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the parts that make contributions to the prior art or parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server) to execute all or part of the steps of the methods described in the embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk, and various program code storage media.
[0254] The above description is only specific embodiments of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A document format conversion method characterized by, The method comprises: identifying a table in a PDF document, the table comprising at least one of a full-frame table, a half-frame table, and a frameless table; identifying a chart in the PDF document, the chart comprising at least content information displayed in a graphical manner; converting the PDF document into an HTML document according to the table and the chart, wherein the table converted in the HTML document is in an HTML form, and the chart converted in the HTML document is in a picture form; wherein the identifying the table in the PDF document comprises: positioning a table based on lines in the PDF document to identify a first table in the PDF document, the first table comprising at least one of the full-frame table and the half-frame table, and specifically: identifying text, lines, coordinates of each line, and width and height between each two lines in the PDF document, wherein the lines comprise horizontal lines and vertical lines; determining, according to coordinates of all horizontal lines and width between each two horizontal lines, a plurality of groups of horizontal lines that are parallel to each other and have similar or identical lengths, wherein each group of horizontal lines comprises two horizontal lines that are parallel to each other and have similar or identical lengths; initializing a first table set, and for each group of horizontal lines in the plurality of groups of horizontal lines, performing table identification processing on each horizontal line in the group of horizontal lines from top to bottom and from bottom to top, respectively, and adding all first tables identified in the table identification processing to the first table set, including: for each group of horizontal lines in the plurality of groups of horizontal lines, traversing each horizontal line in the group of horizontal lines from top to bottom and from bottom to top, respectively; determining whether the current line is the last line; if the current line is not the last line, determining whether a first condition is met between the current line and the first line after the current line, wherein the first condition is that there is text between the current line and the first line after the current line, and the text is separated by a blank, and the distance between the text and the lines is less than a second threshold; if the first condition is met between the current line and the first line after the current line, the current line and the first line after the current line form a new first table; determining whether the current line is the second-to-last line; if the current line is the second-to-last line, ending the traversal process.
2. The document format conversion method of claim 1, wherein, The positioning of the table based on the lines in the PDF document to identify the first table in the PDF document further comprises: performing merging processing on the first tables in the first table set to merge each two first tables in the first table set that have common lines, until there is no first table that can be merged in the first table set, to obtain an updated first table set; determining boundary coordinates of each first table in the updated first table set according to coordinates of lines contained in each first table in the updated first table set; identifying the full-frame table and the half-frame table in the PDF document according to the number of horizontal lines, the number of vertical lines and the first threshold in each first table of the updated first table set.
3. The document format conversion method of claim 1, wherein, After the step of judging whether the first condition is met between the current line and the first line after the current line, the method further comprises: if the first condition is not met between the current line and the first line after the current line, setting the first line after the current line as a new current line, and returning to the step of judging whether the current line is the last line.
4. The document format conversion method of claim 1, wherein, After the step of judging whether the current line is the second last line, the method further comprises: if the current line is not the second last line, setting the second line after the current line as a new current line, and returning to the step of judging whether the current line is the last line.
5. The document format conversion method of claim 2, wherein, The method of identifying the table in the PDF document further comprises: positioning the table based on the image in the PDF document to identify a second table in the PDF document, the second table comprising the frameless table.
6. The document format conversion method of claim 5, wherein, The method of positioning the table based on the image in the PDF document to identify the second table in the PDF document comprises: converting the PDF document into an image in RGB format; identifying the image in RGB format corresponding to the PDF document through a trained target detection model to obtain the second table in the PDF document and the coordinate position of the second table, and adding all the second tables identified by the target detection model to a second table set; performing table boundary determination processing on the second table set according to the coordinate position of the second table to identify all the tables in the PDF document, the all the tables comprising the first table and the second table.
7. The document format conversion method of claim 6, wherein, The method of performing table boundary determination processing on the second table set according to the coordinate position of the second table to identify all the tables in the PDF document comprises: traversing each second table in the second table set: if there is an intersection of boundaries between the current second table and a certain first table in the updated first table set according to the coordinate position of the second table, modifying the boundary of the current second table to the boundary of the first table in the updated first table set with the largest intersection of boundaries with the current second table; adding the current second table to a third table set, wherein the third table set is used to represent all the tables identified in the PDF document, and the third table set contains all the first tables in the updated first table set and all the second tables with adjusted table boundaries in the second table set.
8. The document format conversion method of claim 7, wherein, The method further comprises: obtaining a training data set, wherein each training data in the training data set comprises a training image and annotation information corresponding to the training image, the training image is obtained by converting a PDF document sample into an image in RGB format, and the annotation information comprises an annotation classification object corresponding to the training image and a coordinate position of each annotation classification object, the annotation classification object at least comprises a chart and a table; training a target detection model by using the training data set, so as to obtain the trained target detection model when a predicted classification object output by the target detection model is consistent with the annotation classification object corresponding to the training image, and a coordinate position of the predicted classification object output by the target detection model is consistent with the coordinate position of the annotation classification object.
9. The document format conversion method of claim 6, wherein, The chart in the PDF document is identified, comprising: identifying the chart in the PDF document and the coordinate position of the chart by using the trained target detection model on the image in RGB format corresponding to the PDF document; determining a chart area graph containing only a coordinate area in the chart according to the coordinate position of the chart, and the chart area graph is used to embed the chart in the HTML document in the form of a picture.
10. The document format conversion method according to any one of claims 1 to 9, wherein, The method further comprises: identifying text and a layout of the PDF document, the layout comprises at least one of a single-column layout, a double-column layout and a multi-column layout; The method further comprises: converting the PDF document into an HTML document according to the table and the chart, comprising:
11. The document format conversion method of claim 10, wherein, converting the PDF document into an HTML document according to the table, the chart, the text and the layout. The method further comprises: obtaining a row and column position of each cell in the table, and obtaining text in each cell, and converting the table into an HTML form according to the row and column position of each cell and the text in each cell; merging text other than the table and the chart according to a first merging condition to obtain a plurality of different paragraphs, wherein the first merging condition is that a distance between the text is less than a third threshold value; identifying a horizontal coordinate position of each column in the layout; sorting the table, the chart and the paragraphs according to the horizontal coordinate position of each column in the layout and a reading order corresponding to the layout; 12. The document format conversion method of claim 11, wherein, outputting the table, the chart and the paragraphs in an HTML form according to a sorting result, and converting the PDF document into an HTML document, wherein the table is output in an HTML form, the chart is embedded in the HTML document in the form of a picture, and the paragraphs are output in an HTML form of paragraph text. The method further comprises: performing table column generation processing on the table to obtain a column set of the table, and determining a horizontal coordinate boundary of each column according to text belonging to each column. performing table row generation processing on the table to obtain a row set of the table, and determining a vertical coordinate boundary of each row according to text to which each row belongs; generating a plurality of cells according to the column set and the row set, determining text and coordinates within each cell according to text to which each column belongs, text to which each row belongs, a horizontal coordinate boundary of each column, and a vertical coordinate boundary of each row, and performing merging processing on cells having coordinate intersection in the plurality of cells to obtain a row-column position of each cell in the table.
13. The document format conversion method of claim 12, wherein, The performing table column generation processing on the table to obtain a column set of the table comprises: obtaining a text set containing all text in a table region of the table, initializing the column set of the table, and initializing an event identifier of the column set to no; determining whether there is first text not belonging to any column in the text set; if there is first text not belonging to any column in the text set, finding all second text covered by the first text in a vertical direction from the text set to obtain a second text set, wherein horizontal coordinates of second text in the second text set are all covered by horizontal coordinates of the first text; dividing second text in the second text set into text rows, wherein there is no intersection of vertical coordinates between the text rows; if the number of the text rows is greater than or equal to the number of text in the second text set, constructing a new column with second text in the second text set, adding the new column to the column set, and setting the event identifier of the column set to yes; traversing all text in the text set until there is no first text belonging to any column in the text set; if the event identifier of the column set is yes, merging columns in the column set according to a second merging condition, wherein the second merging condition is that horizontal coordinates of one column are completely covered by horizontal coordinates of another column.
14. The document format conversion method of claim 12, wherein, The performing table row generation processing on the table to obtain a row set of the table comprises: obtaining a text set containing all text in a table region of the table, initializing the row set of the table, and initializing an event identifier of the row set to no; determining whether there is third text not belonging to any row in the text set; if there is third text not belonging to any row in the text set, finding all fourth text covered by the third text in a horizontal direction from the text set to obtain a fourth text set, wherein vertical coordinates of fourth text in the fourth text set are all covered by vertical coordinates of the third text; dividing fourth text in the fourth text set into text columns, wherein there is no intersection of horizontal coordinates between the text columns; if the number of the text columns is greater than or equal to the number of text in the fourth text set, constructing a new row with fourth text in the fourth text set, adding the new row to the row set, and setting the event identifier of the row set to yes; traversing all text in the text set until there is no third text belonging to any row in the text set; If the event identifier of the row set is yes, columns in the column set are merged according to a third merging condition, wherein the third merging condition is that the ordinate of one row is completely covered by the ordinate of another row.
15. The document format conversion method of claim 11, wherein, The identifying the horizontal coordinate position of each column in the layout includes: initializing an array and setting a fourth threshold M, wherein the length of the array is equal to the width of the page of the PDF document, the initial variable value of the array is 0, and M is a positive integer greater than 0; setting the variable value of each position in the array as the number of texts on each horizontal coordinate in the page of the PDF document; setting the variable value corresponding to each continuous M horizontal coordinates as a group of subarrays; if there is a first subarray in which the variable values corresponding to the M horizontal coordinates are all 0 in the array, and the variable values corresponding to the M horizontal coordinates in the second subarrays on the left and right of the first subarray are all greater than a fifth threshold, then the first subarray is determined as a boundary; determining the number of columns in the layout according to the number of boundaries, wherein the number of columns is the sum of the number of boundaries and 1; and identifying the horizontal coordinate position of each column in the layout according to the horizontal coordinate position corresponding to the boundary in the page of the PDF document.
16. A document format conversion apparatus characterized by comprising: The device comprises: A first identification unit is configured to identify a table in a PDF document, wherein the table comprises at least one of a full-frame table, a half-frame table, and a frameless table. A second identification unit is configured to identify a chart in the PDF document, wherein the chart comprises at least content information displayed in a graphical manner. A conversion unit is configured to convert the PDF document into an HTML document according to the table and the chart, wherein the table converted in the HTML document is in an HTML form, and the chart converted in the HTML document is in a picture form. The first identification unit is configured to position a table based on lines in the PDF document to identify a first table in the PDF document, wherein the first table comprises at least one of the full-frame table and the half-frame table. The first identification unit is configured to identify text, lines, coordinates of each line, and width and height between each two lines in the PDF document, wherein the lines comprise horizontal lines and vertical lines. The first identification unit is configured to determine a plurality of groups of horizontal lines that are parallel to each other and have similar or identical lengths according to coordinates of all the horizontal lines and width between each two horizontal lines, wherein each group of horizontal lines comprises two horizontal lines that are parallel to each other and have similar or identical lengths. The initialization of the first table set, for each of the plurality of horizontal line groups, respectively from top to bottom and from bottom to top, each horizontal line in the plurality of horizontal line groups is table recognition processing, and all the first tables identified in the table recognition processing are added to the first table set, including: for each of the plurality of horizontal line groups, respectively from top to bottom and from bottom to top, each horizontal line in the horizontal line group is traversed; determine whether the current line is the last line; if the current line is not the last line, determine whether the first condition is met between the current line and the first line after the current line, wherein the first condition is that there is text between the current line and the first line after the current line, and the text is separated by a blank, and the distance between the text and the line is less than a second threshold; if the first condition is met between the current line and the first line after the current line, the current line and the first line after the current line form a new first table; determine whether the current line is the second last line; if the current line is the second last line, the traversal process is ended.
17. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is suitable for being loaded by a processor to execute the document format conversion method of any one of claims 1-15.
18. A computer device, comprising: The computer device includes a processor and a memory, and the memory stores a computer program, and the processor is used to execute the document format conversion method of any one of claims 1-15 by calling the computer program stored in the memory.
19. A computer program product comprising computer instructions, characterized in that, The computer instructions are executed by the processor to implement the document format conversion method of any one of claims 1-15.
Citation Information
Patent Citations
Method for generating PDF text paragraphs
CN101876967A
Page conversion method and device and page conversion equipment
CN107943956A
Method and device for positioning chart in PDF document and computer equipment
CN110348294A
PDF document analysis method and device
CN111368511A