Document conversion methods and apparatus, computer-readable storage media, computer equipment

By parsing PDF documents page by page, mapping them to preset pages, constructing text blocks and shape blocks, and generating Word documents according to preset layout rules, the problem of inaccurate layout when converting PDF to Word documents is solved, and the conversion accuracy is improved.

CN115510821BActive Publication Date: 2026-03-13WANGXU TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-28
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

Existing methods for converting PDF documents to Word documents are prone to element position deviations, resulting in inaccurate layouts in the converted Word documents.

Method used

By parsing the PDF document page by page, mapping it to a preset page, constructing text blocks and shape blocks, and determining the sections and columns according to preset layout rules, a Word document with the same element layout as the preset page is generated.

Benefits of technology

It improves the fidelity of document conversion, ensuring that the layout of elements in the converted Word document is consistent with that of the PDF document, and reduces positional deviations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115510821B_ABST
    Figure CN115510821B_ABST
Patent Text Reader

Abstract

This application provides a document conversion method, including parsing a first document page by page to obtain all elements of each page of the first document, each element having a position and content; mapping all elements of each page to each preset page; constructing several text blocks and / or several shape blocks according to the position and content of each element in each preset page; determining the section and column division of each text block and / or each shape block in each preset page according to preset layout rules; and generating a second document based on each preset page with all elements laid out. This application improves the accuracy of document conversion by adding layout to all elements of each page of the first document according to content arrangement, ensuring that the positions of each element are basically consistent before and after conversion. Furthermore, this application also provides an apparatus, a computer-readable storage medium, and a computer device using the aforementioned document conversion method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of document conversion technology, and in particular to a document conversion method and apparatus, a computer-readable storage medium, and a computer device. Background Technology

[0002] Documents come in various forms, ranging from non-editable to editable. For example, PDF and Word documents are commonly used for both. Due to the uneditable nature of non-editable documents, it's often necessary to convert them to editable versions during use. While most PDF documents are non-editable, some software can edit them, but this is generally less convenient than using Word documents. Therefore, when users want to edit content from a PDF document to create a new document, they usually need to convert the PDF to a Word document.

[0003] Currently, there are methods to convert PDF documents to Word documents. However, since PDF documents do not have the flow layout of lines, sections, and columns found in Word documents, current conversion methods generally only arrange the elements in the Word document according to their positions on each page of the PDF document. Sometimes, elements may overlap or be misaligned. In other words, using current conversion methods often results in discrepancies between the positions of elements in the converted Word document and those in the PDF document. Summary of the Invention

[0004] In view of this, it is necessary to provide a document conversion method and apparatus, a computer-readable storage medium and a computer device, which can improve the accuracy of document conversion.

[0005] In a first aspect, embodiments of this application provide a document conversion method for converting an uneditable first document into an editable second document. The document conversion method includes: parsing the first document page by page to obtain all elements, where each element on each page of the first document has a position and content; mapping all elements of each page to a preset page, such that each page contains all elements of the corresponding page in the first document; constructing several text blocks and / or several shape blocks based on the position and content of each element on each preset page; determining the sectioning and column division of each text block and / or each shape block on each preset page according to preset layout rules, thereby obtaining the layout of all elements of each page on the corresponding preset page; and generating a second document based on each preset page with all elements laid out; the element layout of each page of the second document is the same as the element layout of the corresponding preset page.

[0006] Secondly, embodiments of this application provide a computer device, which includes a memory and a processor. The memory is used to store program instructions. The processor is used to execute the program instructions to implement the document conversion method described above.

[0007] Thirdly, embodiments of this application provide a document conversion device, which includes a parsing module, a mapping module, a construction module, a layout module, and a generation module. The parsing module is used to parse a first document page by page to obtain all elements of each page of the first document, each element having a position and content. The mapping module is used to map all elements of each page of content to each preset page, so that each page contains all elements of the corresponding page in the first document. The construction module is used to construct several text blocks and / or several shape blocks based on the position and content of each element in each preset page. The layout module is used to determine the sectioning and column division of each text block and / or each shape block in each preset page according to preset layout rules, obtaining the layout of all elements of each page of content in the corresponding preset page. The generation module is used to generate a second document based on each preset page with all elements laid out; the element layout of each page of the second document is the same as the element layout of the corresponding preset page.

[0008] Fourthly, embodiments of this application provide a computer-readable storage medium for storing computer program instructions, which are executed by a processor to implement the above-described document conversion method.

[0009] The document conversion method described above can convert an uneditable first document into an editable second document. During the conversion process, the method can also add section breaks and column layouts to all elements on each page of the first document, which greatly improves the positional deviation of all elements in the first document when converted to the second document due to the lack of layout, thereby improving the fidelity of converting an uneditable document into an editable document. Attached Figure Description

[0010] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.

[0011] Figure 1 This is a flowchart illustrating the document conversion method provided in an embodiment of this application.

[0012] Figure 2A schematic diagram of elements in the first document provided for embodiments of this application.

[0013] Figure 3 This is a schematic diagram illustrating the mapping of a page in a first document to a preset page in an embodiment of this application.

[0014] Figure 4 This is a schematic diagram illustrating the creation of text blocks or shape blocks in a preset page, as provided in an embodiment of this application.

[0015] Figure 5 A flowchart illustrating the sub-steps of step S107 of the document conversion method provided in the first embodiment of this application.

[0016] Figure 6 A flowchart illustrating the sub-steps of step S107 of the document conversion method provided in the second embodiment of this application.

[0017] Figure 7 A flowchart illustrating the sub-steps of step S107 of the document conversion method provided in the third embodiment of this application.

[0018] Figure 8 This is a flowchart illustrating the sub-steps of step S107 in the document conversion method provided in the fourth embodiment of this application.

[0019] Figure 9 A flowchart illustrating the sub-steps of step S105 of the document conversion method provided in the first embodiment of this application.

[0020] Figure 10 This is a flowchart illustrating the sub-steps of step S105 of the document conversion method provided in the second embodiment of this application.

[0021] Figure 11 A schematic diagram of a document conversion apparatus provided in an embodiment of this application.

[0022] Figure 12 This is a schematic diagram of the document conversion process provided in an embodiment of this application.

[0023] Figure 13a This is a schematic diagram of a two-column page of the first document provided in an embodiment of this application.

[0024] Figure 13b A schematic diagram of a single-column page of the first document provided for an embodiment of this application.

[0025] Figure 14 A schematic diagram of a computer device provided for an embodiment of this application.

[0026] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0027] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.

[0028] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar planning objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data are interchangeable where appropriate; in other words, the described embodiments are implemented according to a sequence other than that illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, may also include other content; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0029] It should be noted that the use of terms such as "first" and "second" in this application is for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" and "second" may explicitly or implicitly include one or more of that feature. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.

[0030] This application provides a document conversion method that can convert an uneditable document into an editable document, and can also arrange the content of each page in the uneditable document according to the layout of the editable document, so that the content layout of the document before and after conversion is the same.

[0031] Please refer to Figure 1 This application provides a document conversion method for converting an uneditable first document into an editable second document. The document conversion method includes the following steps.

[0032] Step S101: Parse the first document page by page to obtain all elements of each page of the first document. Each element has a position and content. The content of each element is either text content or formatted content.

[0033] In this embodiment, elements whose content is text are called text elements, and elements whose content is formatted are called formatting elements. Text content includes text, images, graphics, etc. Formatting content includes the formatting used to represent text content, such as strokes, underlines, table borders, fill, text highlighting, cell background color, etc. Figure 2 As shown, element C1, which contains text, and element C2, which contains an image, are text elements. Element S1, which contains a background color, element S2, which contains an underline, and element S3, which contains a rectangle, are formatting elements.

[0034] Understandably, the text content and the formatted content representing the text content are represented by different elements. The content of each page of the first document can be obtained through a deep learning model or a specific method. In a concrete implementation, the first document can be a PDF document, and the content of each page of the first document is each PDF page in the PDF document. PDF documents generally include text-format PDF documents and scanned PDF documents. Text-format PDF documents can be parsed using the PDFium tool. However, scanned PDF documents often require parsing using deep learning techniques. The deep learning model can be implemented using existing models, which will not be elaborated here. Understandably, in some feasible embodiments, the first document can also be, but is not limited to, image format documents, such as JPG format documents, PNG format documents, etc.

[0035] Step S103: Map all elements of each page's content to each preset page, so that each preset page contains all elements of the corresponding page in the first document.

[0036] In this embodiment, each preset page is used to layout all elements of the content on each page. The preset page has the same layout method as the second document, and the elements in the preset page can be laid out using the layout method. More specifically, all elements of the content on each page of the first document can be laid out on the corresponding preset page to obtain the layout attributes of each element, and the layout attributes obtained after layout can be supported by the second document. That is, the layout attributes obtained by each element after layout on the preset page are still effective in the second document.

[0037] In this embodiment, the document conversion method provided by this application also creates a blank preset page for each page of the first document, and lays out all elements of each page content of the first document on each preset page, thereby giving each element layout attributes. The size of the preset page matches the size of each page of the PDF document. Specifically, the document conversion method provided by this application first parses the size of each page in the first document, such as the height and width of the page; then, based on the obtained page height and width, it sets the height and width of the preset page, thereby matching the size of each page of the first document with each preset page.

[0038] In this embodiment, all elements of each page of the first document are mapped to a preset page according to their position. Figure 3 This diagram illustrates how all elements a1 to an on a page 11 of the first document F are mapped one-to-one to a preset page X according to their positions. The positions of elements a1 to an are coordinates (X01, Y01)...(X0n, Y0n). After mapping to the preset page X, the positions of elements a1 to an are coordinates (X11, Y11)...(X1n, Y1n). In other words, each element a1 to an has a unique coordinate correspondence on the preset page. It is understandable that the second document is an editable document, and editable documents typically have layout attributes, allowing users to present a better layout when editing content, achieving neat and standardized content formatting. The elements of the non-editable first document do not have layout attributes. That is, before being mapped to the preset page, each element of each page of the first document does not contain layout attributes. In this embodiment, the preset page provides the same layout attributes as the second document. After all elements of each page of the first document are laid out on the corresponding preset page, each element acquires layout attributes.

[0039] In practice, the second document can be a Word document, whose layout attributes include lines, section breaks, and columns. Similarly, the preset page also provides corresponding layout attributes such as lines, section breaks, and columns. In other words, elements without layout attributes are laid out on the preset page to obtain their own line, section, and column layout attributes.

[0040] Step S105: Construct several text blocks and / or several shape blocks based on the position and content of each element in each preset page.

[0041] In this embodiment, the positional relationships between elements are combined with their content to infer whether the elements can be combined, thereby integrating multiple text elements or multiple shape elements to form an element block. That is, the element block is either a text block or a shape block. Specifically, an element block formed by integrating multiple text elements is called a text block. Multiple shape elements are combined to form a shape block.

[0042] Please refer to Figure 4 In this embodiment, the determination of whether to combine these elements to form an element block is mainly based on the positional relationship between each element.

[0043] For example, if elements A and B overlap in position, and element A contains text while element B contains an image, then elements A and B can be combined to form text block C. In other words, text block C is essentially an image with text.

[0044] For example, if elements D1, D2, and D3 are all text elements, and elements D1, D2, and D3 are located on consecutive lines with the same font and roughly the same text length, then elements D1, D2, and D3 can be combined to form a text block D0, which is equivalent to a text paragraph.

[0045] In this embodiment, each text block includes position coordinates, region information, a line, and elements for each line. The position coordinates of the text block are represented by the coordinates of its top-left corner. The region information represents the size information of the text block within the preset page, such as its height and width. Correspondingly, the shape block also includes position coordinates, region information, a line, and elements for each line. In this embodiment, the lines of the text block within the preset page are represented by the top and bottom horizontal lines, and the left and right vertical lines.

[0046] In this embodiment, before creating each element block, the row of each element is determined, that is, the elements on each page are divided into rows. In specific implementation, each element is divided into the same row according to its position. In specific implementation, elements with little difference in vertical position are divided into one row.

[0047] In this embodiment, after the row of each element is determined, the position coordinates and covered area of ​​each text block are determined based on the row of each element. The top edge of the starting line and the bottom edge of the ending line in the text block are used as the top and bottom edges of the text block, and the left edge (leftmost edge) and right edge (rightmost edge) with the smallest horizontal coordinate in the text block are used as the left and right edges of the text block, thus determining the area information. In this way, all elements are located within the area covered by the text block or shape block. By constructing text blocks or shape blocks, it is possible to prevent line breaks, overflow, or changes in font size among the elements.

[0048] The following is an example Figure 4The construction of a text block is illustrated using element block D0 as an example. Elements D1, D2, and D3 in element block D0 are located on different lines. The line containing element D1 is the starting line of element block D0, so its top edge is taken as the top edge L1 of element block D0. The line containing element D3 is the ending line of element block D0, so its bottom edge is taken as the bottom edge L2 of element block D0. The left edge of the line containing element D2 is the leftmost line in element block D0, so it is taken as the left edge of element block D0. The right edge of the line containing element D1 is the rightmost line in element block D0, so it is taken as the right edge of element block D0. The top, bottom, left, and right edges L1-L4 of element block D0 determine the area covered by element block D0, thus obtaining the area information of element block D0. Based on the area covered by element block D0, the coordinates of the top-left corner of element block D0 can be determined.

[0049] Understandably, when constructing a text block, the line of each element block is first determined based on the position of each element; then the text block area is determined based on the line, thereby determining the position coordinates of each text block, i.e., the position coordinates of the upper left corner of the text block, as well as the area information of the text block, i.e., its width and height.

[0050] Please refer to it again. Figure 4 For example, if elements E1 to E10 are multiple sets of intersecting border lines, then elements E1 to E10 combined form shape block E0, which is equivalent to a table. Similarly, if multiple elements represent a text block, then combining these elements forms an element block, i.e., a shape block. Likewise, a shape block also includes position coordinates, area information, rows, and elements within each row. In other words, the method for constructing element blocks can be understood as setting corresponding rules based on different content formats in the PDF, thereby constructing each element block according to the rules. It can also be understood that by combining multiple elements to form an element block and then performing layout calculations, only the layout of the element block needs to be calculated, without needing to calculate the layout of each individual element, which can greatly reduce the computational workload of calculating the layout of each element. The following will use a table as an example to describe the shape block creation process; please refer to the description related to constructing shape blocks below for details.

[0051] Step S107: Determine the sections and columns of each text block and / or each shape block in each preset page according to the preset layout rules, and obtain the layout of all elements of each page content in the corresponding preset page.

[0052] In this embodiment, determining the sections and columns of each text block and / or each shape block in each preset page according to preset layout rules specifically involves determining the sections of each text block and / or each shape block in each preset page according to preset layout rules, and then determining the columns of each text block and / or each shape block.

[0053] Preferably, the sections of each text block are determined according to preset layout rules, and then the columns of each text block are determined. Then, the sections and columns of the corresponding shape blocks are determined based on the sections and columns of each text block. The layout of the shape blocks is determined based on the layout of the text blocks, and corresponding text blocks and shape blocks are placed in the same section and column. How the sections and columns are determined will be described below.

[0054] Step S109: Generate a second document based on each preset page with all elements laid out, and the second document is an editable document. The element layout of each page of the second document is the same as the element layout of the corresponding preset page.

[0055] Understandably, once the layout attributes of all elements on each page are determined within the corresponding preset page, the layout of each element on each preset page is determined. After each preset page with all elements laid out is converted accordingly, a second document is obtained, which is then saved. For example... Figure 12 As shown, the elements in page F of the first document are mapped to a preset page X and laid out on the preset page, and then the second document W is generated. Taking the second document W as a Word document as an example, it can be understood that in this method, the preset page X is created using an XML file.

[0056] Please refer to Figure 5 This is a flowchart of a sub-step of step S107 provided in the first embodiment of this application. Step S107 further includes steps S500-S508. In this embodiment, steps S500-S508 implement how to segment the elements.

[0057] Step S500: Calculate the gap between each text block in each line.

[0058] Step S502: Determine the number of columns for each line based on the gap between each text block. When the gap between two text blocks is greater than a first preset value, the two text blocks are determined to be in two different columns; when the gap between two text blocks is less than or equal to the first preset value, the two text blocks are determined to be in the same column.

[0059] Step S504: Check the number of columns in each row.

[0060] Step S506: When the number of columns in a row is different from the number of columns in the row preceding the row, the row and the row preceding the row are divided into different sections.

[0061] Step S508: When the number of columns in a row is the same as the number of columns in the row preceding the row, the row and the row preceding the row are placed in the same section.

[0062] Understandably, elements in each row within a section should have the same number of columns, meaning the layout needs to be consistent. Therefore, in this embodiment, the number of columns in the upper and lower rows is used to determine whether to divide the upper and lower rows into the same section or different sections.

[0063] Please refer to Figure 6 This is a flowchart of a sub-step of step S107 provided in the second embodiment of this application. Step S107 further includes steps S600-S604. In this embodiment, each row is divided into single-column or double-column columns, such as... Figure 13a and 13b As shown, the layout of the first document is equivalent to a two-column page as shown in page F1, and the layout of the first document is equivalent to a single-column page as shown in F2. Steps S600-S604 implement a method for dividing elements into columns for each row.

[0064] Step S600: Calculate the gap between each text block in each line.

[0065] Step S602: Determine the number of columns for each line based on the gap between each text block. When the gap between two text blocks is greater than a first preset value, the two text blocks are determined to be in two different columns; when the gap between two text blocks is less than or equal to the first preset value, the two text blocks are determined to be in the same column.

[0066] Step S604: If the number of columns in a row is greater than two, set the row as a single column.

[0067] In the above embodiment, rows with more than two columns are set as single columns. PDF files generally have a maximum of two columns. Therefore, if there are more than two columns, it means that the text blocks in each line are not actually divided into columns, but rather the text blocks are arranged. Thus, such rows are designated as single columns, thereby quickly determining the column division for rows with more than two columns.

[0068] Please refer to Figure 7 This is a flowchart of a sub-step of step S107 provided in the third embodiment of this application. Step S107 further includes steps S700-S704.

[0069] Step S700: If the number of columns in a row is equal to two, and the width of one column in the row is less than a second preset value, then the row is set as a single column.

[0070] Understandably, if a line has two columns but the column width is relatively small, it means that the text block in this line is not divided into columns and is therefore considered a single column. This allows for quick identification of the columns in a line with two columns but a small column width.

[0071] In this embodiment, if the number of columns in a row is equal to two but the column width is not less than a preset value, the column division of the row can be further determined through the following steps.

[0072] Step S702: If the number of columns in a row is equal to two, detect the number of columns in the previous section of the row, the column dividing line of the previous section, and the column dividing line of the section in which the row is located.

[0073] Step S704: If the number of columns in the previous section of the row is also equal to two, and the column dividing line of the previous section does not coincide with the column dividing line of the section where the row is located, then the row is set as a single column.

[0074] Understandably, in steps S702-S704, under normal circumstances, if consecutive rows are double-column, the dividing lines should coincide. However, rows in the same section are either all single-column or all double-column. Therefore, if a row has two columns but the dividing line of the previous section does not coincide with the dividing line of the section in which the row is located, it means that the row has not been divided into columns and is thus considered a single column. In other words, rows with two columns but whose dividing lines do not coincide with the dividing lines of the previous section are quickly identified as single columns.

[0075] Through the above embodiments, this application can divide a row into columns when the number of columns in a row is equal to two.

[0076] Please refer to Figure 8 This is a flowchart of a sub-step of step S107 provided in the fourth embodiment of this application. Step S107 further includes steps S800-S808.

[0077] Step S800: If the number of columns in a row is one and the number of columns in the preceding section of the row is two, determine whether the text block of the row is completely located in the left column of the preceding section. Within a section, columns are arranged from left to right; the leftmost column is the left column, and the rightmost column is the right column.

[0078] Step S802: When the text block of the row is completely located in the left column of the previous section of the row, the row is set to two columns.

[0079] In this embodiment, if the number of columns in a row is equal to one and the number of columns in the preceding section of the row is two, but the text block of the row is not completely located in the left column of the preceding section, the column division of the row can be further determined through the following steps.

[0080] Step S804: If the number of columns in a row is equal to one and the number of columns in the previous section of the row is two, detect the height of the previous section of the row.

[0081] Step S806: Determine whether the height of the previous section of the row is less than a third preset value.

[0082] Step S808: When the height of the previous section of the row is less than the third preset value, the row is set as a single column, and the column of the previous section of the row is adjusted to a single column.

[0083] This embodiment demonstrates how to determine the number of columns in a row when the number of columns in a row is equal to one.

[0084] Understandably, in this application, whether it is dividing into sections or determining single or double columns, it is done line by line and determined based on the number of columns in each row of elements.

[0085] Please refer to the following: Figure 9 This is a flowchart of a sub-step of step S105 provided in the first embodiment of this application. Step S105 further includes steps S900-S908. In this embodiment, it is implemented how to construct a shape block. In this embodiment, an explicit table shape block is constructed, that is, the area of ​​the table that displays border lines in the PDF document.

[0086] Step S900: Detect whether there is one or more sets of intersecting border lines, each border line corresponding to one element.

[0087] Step S902: If there are multiple sets of intersecting border lines, determine the area corresponding to the multiple sets of intersecting border lines as a potential explicit table area to obtain the area information of a shape block.

[0088] Step S904: Determine the table structure of the potential explicit table area based on the one or more sets of intersecting border lines to obtain one or more cells. For example, imaginary horizontal and vertical lines can be used to calculate whether the horizontal and vertical lines intersect with the vertical or horizontal border lines respectively. If no intersection points are found, it indicates the existence of merged cells in the horizontal or vertical direction, thus obtaining the table structure of the explicit table area.

[0089] Step S906: Confirm the area corresponding to the cell as the area information of each cell.

[0090] Step S908: Obtain the corresponding explicit table shape block based on the area information of the shape block, the area information of each cell, and the elements corresponding to each border line.

[0091] In this embodiment, by recognizing the explicit table area, the text blocks in the corresponding area are set to table format, thereby improving the convenience of editing in the editable second document and meeting layout requirements.

[0092] Please refer to the following: Figure 10 This is a flowchart of a sub-step of step S105 provided in the second embodiment of this application. Step S105 further includes steps S1001-S1009. In this embodiment, an invisible table-shaped block is constructed, that is, an area in the PDF document that does not display border lines but needs to be used as a table to layout the corresponding text blocks. For example, some areas may not contain tables, but can be moved as a whole during editing, such as text blocks without borders but laid out in a table format. In an editable document, editing these text blocks requires setting a table for layout purposes.

[0093] Step S1001: Determine the potential implicit table area based on the positional relationship between each text block.

[0094] Step S1003: Determine the imaginary border lines of the potential implicit table area. Each imaginary border line is represented by an imaginary element, which includes position and format content.

[0095] Step S1005: Determine the table structure of the potential implicit table area based on the imaginary border lines to obtain one or more cells. The specific implementation method is the same as step S904.

[0096] Step S1007: Confirm the area corresponding to the cell as the area information of each cell.

[0097] Step S1009: Obtain the corresponding invisible table shape block based on the area information of the shape block, the area information of each cell, and the imaginary elements corresponding to each imaginary border line.

[0098] In this embodiment, by identifying the hidden table area and adding imaginary border lines, the text block content in the area is set into a table format, thereby improving the convenience of editing in the editable second document and meeting layout requirements.

[0099] Please refer to Figure 11This is a functional block diagram of the document conversion device 100. The document conversion device 100 is used to convert an uneditable first document into an editable second document. The document conversion device 100 includes a parsing module 101, a mapping module 103, a construction module 105, a layout module 107, and a generation module 109.

[0100] The parsing module 101 is used to parse the first document page by page to obtain all elements of the content of each page of the first document. Each element has a position and content. The specific implementation process of the parsing module 101 can be referred to the description in step S101 above, and will not be repeated here.

[0101] The mapping module 103 is used to map all elements of each page's content to each preset page, so that each preset page contains all elements of the corresponding page in the first document. The mapping module 103 is described in the above step S103 and will not be repeated here.

[0102] The construction module 105 is used to construct several text blocks and / or several shape blocks based on the position and content of each element in each preset page. The construction module 105 can be referred to the description of step S105 and its sub-steps above, and will not be repeated here.

[0103] The layout module 107 is used to determine the sections and columns of each text block and / or each shape block in each preset page according to preset layout rules, thereby obtaining the layout of all elements of each page's content in the corresponding preset page. The layout module 107 can be referred to the description of step S107 and its sub-steps above, and will not be repeated here.

[0104] The generation module 109 is used to generate a second document based on each preset page with all elements laid out, and the second document is an editable document; the element layout of each page of the second document is the same as the element layout of the corresponding preset page. The generation module 109 can be referred to the description of step S109 above, and will not be repeated here.

[0105] Please refer to Figure 14 This is a schematic diagram of the internal structure of a computer device provided in an embodiment of this application. The computer device 10 includes a memory 11 and a processor 12. The memory 11 is used to store program instructions, and the processor 12 is used to execute the program instructions to implement the above-described document conversion method.

[0106] In some embodiments, the processor 12 may be a central processing unit (CPU), controller, microcontroller, microprocessor or other data processing chip, used to run program instructions stored in the memory 11.

[0107] The memory 11 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of a computer device, such as a hard disk. In other embodiments, the memory 11 may be an external storage device of a computer device, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, FlashCard, etc., provided on the computer device. Furthermore, the memory 11 may include both internal and external storage units of the computer device. The memory 11 can be used not only to store application software and various types of data installed on the computer device, such as code implementing document conversion methods, but also to temporarily store data that has been output or will be output.

[0108] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

[0109] The above examples are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application are still within the scope of this application.

Claims

1. A document conversion method, wherein the document conversion method is used to convert an uneditable first document into an editable second document, characterized in that, The document conversion method includes: The first document is parsed page by page to obtain all elements of the content of each page of the first document. Each element has a position and content. Map all elements of each page's content to each preset page, so that each preset page contains all elements of the corresponding page in the first document; Several text blocks and / or several shape blocks are constructed based on the position and content of each element in each preset page; According to preset layout rules, the sections and columns of each text block and / or each shape block in each preset page are determined, resulting in the layout of all elements of each page's content in the corresponding preset page. This assigns layout attributes to each element in the preset page, including line, section, and column attributes. The elements in the first document do not yet have layout attributes. A second document is generated based on each preset page with all elements laid out. The element layout of each page in the second document is the same as the element layout of the corresponding preset page. The step of determining the section and column division of each text block and / or each shape block in each preset page according to preset layout rules involves: first determining the section division of each text block and / or each shape block in each preset page, and then determining the column division of each text block and / or each shape block; specifically including: Check the number of columns in each row; If the number of columns in a row is different from the number of columns in the row preceding it, then the row and the row preceding it shall be placed in different sections. When the number of columns in a row is the same as the number of columns in the row preceding it, the row and the row preceding it are placed in the same section. The shape blocks include table shape blocks; several shape blocks are constructed based on the position and content of each element in each preset page, including: Detect whether there is one or more sets of intersecting border lines, each border line corresponding to one element; If there are multiple sets of intersecting border lines, the area corresponding to the multiple sets of intersecting border lines is determined as a potential explicit table area to obtain the area information of a shape block. The table structure of the potential explicit table area is determined based on the one or more sets of intersecting border lines to obtain one or more cells; The area corresponding to the cell is identified as the area information for each cell; The corresponding explicit table shape block is obtained based on the area information of the shape block, the area information of each cell, and the elements corresponding to each border line.

2. The document conversion method as described in claim 1, characterized in that, The text block comprises one or more lines, each line being either a single column or a double column; the column division of each text block and / or each shape block in each preset page is determined according to preset layout rules, including: Calculate the gaps between each text block in each line; The number of columns for each line is determined based on the gaps between the text blocks. When the gap between two text blocks is greater than a first preset value, the two text blocks are determined to be in two different columns. When the gap between two text blocks is less than or equal to the first preset value, the two text blocks are determined to be in the same column. If a row has more than two columns, the row will be set as a single column.

3. The document conversion method as described in claim 2, characterized in that, The layout rules for determining the columns of each text block and / or each shape block on each preset page also include: If a row has two columns, and one column in the row has a width less than a second preset value, then the row is set to a single column; the column width is the width of all text blocks in the same column; or If the number of columns in a row is equal to two, detect the number of columns in the previous section of the row, the column dividing line of the previous section, and the column dividing line of the section in which the row is located. If the number of columns in the preceding section of the row is also equal to two, and the column dividing line of the preceding section of the row does not coincide with the column dividing line of the section in which the row is located, then the row is set as a single column.

4. The document conversion method as described in claim 3, characterized in that, The layout rules for determining the columns of each text block and / or each shape block on each preset page also include: If the number of columns in a row is equal to one and the number of columns in the preceding section of the row is two, determine whether the text block of the row is completely located in the left column of the preceding section of the row. In a section, the columns are arranged from left to right, the left column is the left column and the right column is the right column. When the text block of the line is completely located in the left column of the preceding section of the line, set the line to two columns; or If the number of columns in a row is equal to one and the number of columns in the previous section of the row is two, then the height of the previous section of the row is detected. Determine whether the height of the preceding section of the row is less than a third preset value; When the height of the preceding section of the row is less than the third preset value, the column layout of the preceding section of the row is adjusted to a single column.

5. The document conversion method as described in claim 1, characterized in that, Constructing several shape blocks based on the position and content of each element in each preset page also includes: The potential implicit table area is determined based on the positional relationship between the text blocks; Identify the imaginary border lines of the potential implicit table area, each imaginary border line being represented by an imaginary element, the imaginary element including position and format content; The table structure of the potential implicit table area is determined based on the imaginary border lines to obtain one or more cells; The area corresponding to the cell is identified as the area information for each cell; The corresponding invisible table shape block is obtained based on the area information of the shape block, the area information of each cell, and the imaginary elements corresponding to each imaginary border line.

6. A computer device for document conversion, characterized in that, include: Memory, used to store program instructions; as well as A processor for executing the program instructions to implement the document conversion method as described in any one of claims 1 to 5.

7. A document conversion device, characterized in that, include: The parsing module is used to parse the first document page by page to obtain all elements of the content of each page of the first document, and each element has a position and content; The mapping module is used to map all elements of each page's content to each preset page, so that each preset page contains all elements of the corresponding page in the first document; A construction module is used to construct several text blocks and / or several shape blocks based on the position and content of each element in each preset page. The layout module is used to determine the section and column division of each text block and / or each shape block in each preset page according to preset layout rules, so as to obtain the layout of all elements of each page content in the corresponding preset page, and give each element in the preset page layout attributes, including lines, sections, and columns; the elements of the first document do not have layout attributes. as well as The generation module is used to generate a second document based on each preset page with all elements laid out. The element layout of each page in the second document is the same as the element layout of the corresponding preset page. The step of determining the section and column division of each text block and / or each shape block in each preset page according to preset layout rules involves: first determining the section division of each text block and / or each shape block in each preset page, and then determining the column division of each text block and / or each shape block; specifically including: Check the number of columns in each row; If the number of columns in a row is different from the number of columns in the row preceding it, then the row and the row preceding it shall be placed in different sections. When the number of columns in a row is the same as the number of columns in the row preceding it, the row and the row preceding it are placed in the same section. The shape blocks include table shape blocks; several shape blocks are constructed based on the position and content of each element in each preset page, including: Detect whether there is one or more sets of intersecting border lines, each border line corresponding to one element; If there are multiple sets of intersecting border lines, the area corresponding to the multiple sets of intersecting border lines is determined as a potential explicit table area to obtain the area information of a shape block. The table structure of the potential explicit table area is determined based on the one or more sets of intersecting border lines to obtain one or more cells; The area corresponding to the cell is identified as the area information for each cell; The corresponding explicit table shape block is obtained based on the area information of the shape block, the area information of each cell, and the elements corresponding to each border line.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store computer program instructions, which are executed by a processor to implement the document conversion method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Document processing method, electronic equipment and storage medium

    CN114118011A

  • Design document generation method and device, computer equipment and storage medium

    CN114139494A

  • Document format conversion method and device, storage medium and equipment

    CN115114481A