File conversion method capable of reserving PDF (Portable Document Format) file format
By converting PDF files to XML format and filling them into a two-dimensional list, the problem that the existing technology cannot completely preserve the original text structure of PDF files is solved, and efficient and accurate PDF to Excel conversion is achieved, suitable for PDF file processing in complex layouts.
Patent Information
- Application Number
- CN202411560716.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-04
- Publication Date
- 2025-03-07
AI Technical Summary
Existing PDF conversion tools cannot completely preserve the original text structure of PDF files and convert them to Excel format, especially for PDF files with non-standard or complex layouts.
By converting PDF files to XML format, capturing text and layout information, and populating them into a two-dimensional list, removing blank rows and columns from the list, optimizing the data structure, and finally writing the processed data to Excel objects.
It effectively retains the text layout and structure in PDF files, improves the accuracy and efficiency of data conversion, and ensures that the converted Excel file can maintain the appearance and format of the original file, making it easier for users to edit and analyze.
Smart Images

Figure CN119578373A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a file conversion method retaining a PDF file format. Background Art
[0002] With the continuous advancement of information technology, PDF, as a standard format for electronic files, has been widely used in file storage and sharing. However, existing technologies often cause the loss of text layout and structural information in PDF files during the conversion process, making it impossible for the converted files to maintain the same appearance and format as the original PDF files. In addition, although some methods can correctly convert PDF formats, they may only be applicable to PDF files of specific formats. For PDF files with non-standard or complex layouts, these methods cannot handle formatting issues well, causing inconvenience to users.
[0003] For example, a "PDF file table parsing method and system" disclosed in Chinese patent literature, with publication number CN108664458, uses a multi-step conversion method to first convert a PDF file into a Word file, and then convert the Word file into HTML format, thereby accurately parsing and structuring the table information in the PDF file and improving the accuracy of reading the table information. However, the multi-step conversion process set by this solution is complicated, and ultimately the table information cannot be generated in an Excel file. In addition, when this method processes non-standard or specially formatted PDF files, the accuracy and compatibility may be affected. Summary of the invention
[0004] The present invention mainly solves the problem that the existing PDF conversion tools cannot completely retain the original text structure of the PDF file and convert it into Excel format. In response to this technical problem, the present invention provides a file conversion method that retains the PDF file format, by converting the PDF file into XML format, using the XML tagging ability to capture the text and layout information in the PDF file, and filling the text information and its position coordinates in the XML file into the corresponding position of the two-dimensional list; on this basis, the blank rows and columns in the list are removed by the data compression algorithm, the data structure is optimized, and finally the processed two-dimensional list data is written into the Excel object. Through this series of steps, the present invention not only retains the text layout and structure in the PDF file, but also improves the accuracy and efficiency of data conversion, and provides convenience for users to further edit and analyze the data.
[0005] The above technical problems of the present invention are mainly solved by the following technical solutions: A file conversion method for retaining the PDF file format of the present invention comprises: reading a PDF file to obtain text information and layout information, obtaining the position coordinates of pixel points corresponding to the text information, and generating an XML file through the position coordinates and the layout information; obtaining the size information of the PDF file according to the layout information, establishing a two-dimensional list based on the size information, parsing the XML file, and storing the text information in the XML file into the two-dimensional list; compressing empty rows and empty columns in the list, and writing the data in the two-dimensional list into an Excel object.
[0006] The beneficial effect of the present invention is that the text information and layout information in the PDF file are extracted, and the information is accurately converted into a structured XML file, and then the size information is used to construct a data structure suitable for Excel. This process ensures that the visual format of the original PDF file is maintained in the converted Excel table, which is convenient for users to edit and analyze data. At the same time, by removing empty rows and columns and optimizing the data structure, the efficiency of data conversion and the readability of Excel objects are improved, so that the method has a high application value in the field of file conversion, and is particularly suitable for work scenarios that require frequent processing of complex layout PDF files.
[0007] Preferably, the process of reading a PDF file to obtain text information and layout information includes: obtaining the total number of pages of the PDF file, loading page content page by page and returning page objects page by page, extracting text information from each page object, and determining the layout information of the text information in the page based on the bounding box and subject tags identified in the page object.
[0008] The above content can accurately extract the text information and layout information of each page by loading and processing the PDF file page by page. Using bounding boxes and subject tags to determine the location of the text helps to maintain the structure and format of the original file. This method is suitable for the conversion of complex files, ensuring the integrity and accuracy of the information, and facilitating subsequent editing and use of the data.
[0009] Preferably, the process of establishing a two-dimensional list includes: initializing an empty two-dimensional list; calculating the size information of the width and height of the PDF file based on the layout information of the PDF file; matching the width and height of the empty two-dimensional list with the size information of the PDF file to form a two-dimensional list adapted to the PDF file, and recording the coordinates of the list elements in the two-dimensional list.
[0010] The above content ensures accurate data correspondence during the conversion process by initializing a two-dimensional list that matches the size of the PDF file. The list size is adjusted according to the PDF layout information so that the coordinates of each element are consistent with the position in the original file, thereby effectively retaining the original format of the file and facilitating subsequent data processing and analysis.
[0011] Preferably, the process of establishing the two-dimensional list further includes: recording text information and position coordinates of pixel points according to size information of the PDF file; associating list elements of the two-dimensional list with pixel points of the PDF file to determine the coordinates of the list elements in the two-dimensional list.
[0012] The above content records the text information and position coordinates of the pixel points in the PDF file and accurately associates them with the elements of the two-dimensional list, ensuring that the converted content can accurately reflect the layout of the original file. This not only improves the accuracy of data migration, but also makes it easier to maintain the original visual presentation in the new format, making it easier for users to perform subsequent data management and analysis.
[0013] Preferably, the process of storing the text information in the XML file into a two-dimensional list according to the position coordinates includes: for text blocks: extracting the text coordinates of each text block from the XML file, associating the text coordinates with the coordinates of the list element according to the correspondence between the pixel points and the text blocks, and inserting the text blocks into the two-dimensional list; for non-text blocks: recording the edge coordinates of the non-text blocks, matching the coordinate group of the corresponding list element in the two-dimensional list, and inserting a placeholder in the area surrounded by the coordinate group.
[0014] The above content achieves accurate insertion of text information by accurately extracting the coordinates of text blocks in the XML file and associating them with the coordinates of two-dimensional list elements. At the same time, the edge coordinates of non-text blocks are used to locate and placeholders are inserted in the list, which completely retains the layout characteristics of the original file, ensures the accuracy and readability of the conversion results, and facilitates subsequent data editing and use.
[0015] Preferably, the process of storing the text information in the XML file into the two-dimensional list according to the position coordinates further includes: for the text block: the text coordinates of the text block are matched with the coordinate group of the list element in the two-dimensional list; if the area formed by the coordinate group of the list element covers a number of cells greater than 1, the text block is split, and the split text blocks are filled into relevant cells according to the corresponding coordinate group of the list element; for the non-text block: after performing image recognition on the non-text block, the recognition result is split to replace the corresponding placeholder, and the pixel points not replaced by the placeholder are processed.
[0016] The above content ensures the accurate layout of text information by accurately matching and splitting text blocks according to coordinates and filling them into multiple cells of the two-dimensional list. At the same time, image recognition is performed on non-text blocks and corresponding placeholders are replaced, ensuring that non-text elements such as pictures or tables can also maintain their original positions and integrity during the conversion process, thereby improving the overall quality and readability of the converted file.
[0017] Preferably, the process of processing pixels that are not replaced by placeholders includes: identifying the edge coordinate group of the placeholder, calculating the new edge coordinate group of the remaining placeholder after replacing the placeholder, and clearing the pixels within the covered area according to the new edge coordinate group; placeholders include but are not limited to tags or strings representing non-text blocks.
[0018] The above content effectively ensures the neatness and accuracy of the converted file by identifying and calculating the edge coordinates of the placeholders, accurately processing the unreplaced parts, and clearing unnecessary pixels. This not only removes redundant information, but also maintains the clear presentation of non-text blocks such as pictures or charts, enhancing the professionalism and readability of the final output file.
[0019] Preferably, the process of compressing the empty rows and columns in the list includes: traversing the two-dimensional list and deleting the empty rows and columns to generate a two-dimensional list without blank areas in the data structure.
[0020] The above content effectively eliminates blank areas in the data structure by traversing the two-dimensional list and removing empty rows and columns, reducing the demand for storage space, while improving the compactness and readability of the data, facilitating subsequent data processing and analysis.
[0021] Preferably, before writing the data in the two-dimensional list into the Excel object, the method also includes: filtering set cells in the two-dimensional list; setting cells to correspond to set text information in the PDF file, the set text information including but not limited to titles and comments; and adjusting the format of the corresponding set cells according to the corresponding style of the set text information in the PDF file.
[0022] Before writing the data to the Excel object, by filtering and formatting specific cells, it is ensured that important information such as titles and comments from the PDF file can be displayed in the correct style in Excel. This not only enhances the readability of the file, but also ensures the visual consistency of the converted content, making it easier for users to identify and use key information.
[0023] Preferably, the process of writing the data in the two-dimensional list into the Excel object includes: creating an Excel object, traversing the two-dimensional list, and writing the list elements of the two-dimensional list into the Excel object row by row.
[0024] The above content achieves efficient data migration from PDF to Excel by creating an Excel object and traversing the two-dimensional list to write the list elements line by line. This method ensures the integrity and order of the data, simplifies the operation process, and facilitates users to edit and analyze the converted data.
[0025] The beneficial effects of the present invention are as follows: 1. The file conversion method of the present invention retains the PDF file format. By adopting a unique PDF-Excel conversion method, the original text structure in the PDF file is effectively retained, so that after the user converts the file into an Excel table, the original typesetting and logical order can still be maintained, which is especially important for professionals who need to perform complex data analysis; this feature simplifies the data sorting process, so that the user can directly process and analyze the converted data without spending extra time to reorganize the data, thereby significantly improving work efficiency.
[0026] 2. The file conversion method of the present invention retains the PDF file format and supports data conversion in non-tabular form, which greatly broadens its applicable scenarios; both text descriptions and list information can be accurately converted into Excel format to meet the needs of different fields; it not only increases the flexibility of data conversion, but also greatly improves the accuracy and speed of the conversion process, reduces the need for manual correction, ensures the consistency and reliability of data, and thus helps users complete work tasks more efficiently. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 This is a flow chart of a file conversion method retaining the PDF file format according to the third embodiment of the present invention. DETAILED DESCRIPTION
[0028] The technical solution of the present invention is further specifically described below through embodiments and in conjunction with the accompanying drawings.
[0029] Embodiment 1: This embodiment provides a file conversion method that retains the PDF file format, aiming to overcome the defects of the existing PDF format conversion method through technical innovation, and ensure that the data in the PDF file can be presented in Excel format according to its original text structure.
[0030] The specific steps of the method are as follows: Step 1: Read the PDF file and convert it into an XML file.
[0031] Specifically, the PDF file is read using the PDF parsing library, and the text and layout information in the PDF file are converted into XML format. After conversion to XML format, the text and layout information can be more easily parsed, making the data easier to process and convert.
[0032] Step 2: Generate an empty two-dimensional list based on the pixels of the PDF. Each pixel represents a list element to store PDF information.
[0033] Specifically, the size and resolution of the PDF file are analyzed, and a two-dimensional list matching the size of the PDF file is created, with each pixel position corresponding to a list element. Such a two-dimensional list can accurately map every pixel in the PDF file, ensuring that there will be no position deviation in the subsequent data filling.
[0034] Step 3: Store the XML information into the corresponding position of the two-dimensional list according to the pixel position.
[0035] Specifically, the text information and its position coordinates are extracted from the XML file, and the text information is filled into the corresponding two-dimensional list position. Through coordinate matching, it can be ensured that the position of the text information remains unchanged during the conversion process, thereby maintaining the original layout of the file.
[0036] Step 4: Compress the empty rows and columns of the two-dimensional list until there are no empty rows and columns in the two-dimensional list.
[0037] Specifically, remove blank rows and columns in the two-dimensional list, optimize the data structure, and reduce invalid space. Compressing blank rows and columns can improve the compactness of data, reduce storage requirements, and improve the readability and aesthetics of Excel objects.
[0038] Step 5: Write the two-dimensional list data into Excel.
[0039] Specifically, use the Excel write library to convert the two-dimensional list data into an Excel object, save the file, and complete the conversion process. Write the processed data into the Excel object to facilitate users to edit, analyze, and share data.
[0040] Embodiment 2: This embodiment provides a file conversion method that retains the PDF file format. Based on the embodiment 1, the method is substituted into an actual scenario. The specific contents are as follows: A PDF file is provided, which contains a sales data table with 10 rows and 5 columns, showing the sales of different products. The first row of the table is the title row, which contains fields such as "Product Name", "Unit Price", "Quantity", "Sales" and "Remarks". Now we need to convert this table into Excel format for data analysis and editing.
[0041] A data analyst at a retail company received a PDF file containing sales data. In order to facilitate sales trend analysis and report writing, the analyst hopes to convert the table data in this PDF file into Excel format.
[0042] The specific process of conversion is: Step 1: First read the PDF file and convert it into an XML file.
[0043] Use the PDF parsing library to read the PDF file and extract the table data. In this example, the parsing library will identify a table with 10 rows and 5 columns, and convert the data of each row and column and their position coordinates into XML format. For example, the header rows "Product Name", "Unit Price", "Quantity", "Sales", and "Remarks" will be recorded with their coordinate information in the PDF file.
[0044] Step 2: Generate an empty two-dimensional list based on the pixels of the PDF. Each pixel corresponds to a list element in the two-dimensional list. The list elements are used to store the text information in the PDF file.
[0045] Analyze the size and resolution of the PDF file and create a 2D list that matches the size of the PDF file. For example, if the actual size of the table in the PDF file is 800 pixels wide and 600 pixels high, create a 800x600 2D list. Each cell corresponds to a pixel or a group of pixels in the PDF file.
[0046] Step 3: Store the text information of the XML file into the corresponding position of the two-dimensional list according to the position of the pixel points in the PDF file.
[0047] Extract the table data and its position coordinates from the XML file and fill them into the corresponding positions in the two-dimensional list. For example, the coordinates of the title row "Product Name" may be (100, 50), then find the position at the coordinates (100, 50) in the two-dimensional list and fill in "Product Name".
[0048] Step 4: Compress the empty rows and columns of the two-dimensional list until there are no empty rows and columns in the two-dimensional list.
[0049] Check for blank rows and columns in a two-dimensional list and remove them. In this example, if there are any blank rows or columns in the two-dimensional list that are not occupied by table data, they are deleted to ensure that there will be no blank rows or columns in the final generated Excel object, improving the compactness of the table and the accuracy when filling the Excel object.
[0050] Step 5: Write the data in the two-dimensional list into the Excel object.
[0051] Use the Excel Write Library to convert the data in the two-dimensional list into Excel object format and save the file. At this point, the sales data table will be displayed in the form of an Excel table, and users can directly edit and analyze the data in Excel.
[0052] Through the above steps, even if the PDF file contains complex table data, it can be successfully converted into Excel format and maintain the original layout and data structure. This method not only improves the accuracy of data conversion, but also greatly enhances the practicality and editability of the converted file, which is very suitable for work scenarios that need to frequently process PDF files with tables.
[0053] Embodiment 3: This embodiment provides a method for converting a file in PDF format. Figure 1 The content shown further optimizes the extraction and processing process of text information and layout information based on Example 1.
[0054] Read the PDF file to obtain text information and layout information, obtain the position coordinates of the pixel points corresponding to the text information, and generate an XML file through the position coordinates and layout information. Specifically, it includes: obtaining the total number of pages in the PDF file and traversing each page, loading the page content page by page and returning the page object page by page, extracting the text information in each page object, and determining the layout information of the text information in the page based on the bounding box and subject tags identified in the page object. This method ensures the integrity of the text information and can accurately reflect the layout of the text on the page.
[0055] Get the size information of the PDF file according to the layout information, and build a two-dimensional list according to the size information. Initialize an empty two-dimensional list; calculate the size information of the width and height of the PDF file according to the layout information of the PDF file; match the width and height of the empty two-dimensional list with the size information of the PDF file to form a two-dimensional list adapted to the PDF file, and record the coordinates of the list elements in the two-dimensional list. By matching the size information of the PDF file, it is ensured that the size of the two-dimensional list is completely consistent with the PDF file, thereby ensuring accurate filling of data.
[0056] The text information and position coordinates of the pixel points are recorded according to the size information of the PDF file; the list elements of the two-dimensional list are associated with the pixel points of the PDF file to determine the coordinates of the list elements in the two-dimensional list. Through the coordinate association, it is ensured that the information of each pixel point can be accurately mapped to the corresponding position in the two-dimensional list.
[0057] Parse the XML file and store the text information in the XML file into a two-dimensional list according to the position coordinates: For text blocks: extract the text coordinates of each text block from the XML file, associate the text coordinates with the coordinates of the list elements according to the correspondence between the pixel points and the text blocks, and insert the text blocks into the two-dimensional list. The text coordinates of the text block correspond to the coordinate group of the list elements in the two-dimensional list. If the number of cells covered by the area formed by the coordinate group of the list elements is greater than 1, split the text block, and fill the relevant cells with the split text blocks according to the corresponding coordinate group of the list elements. Coordinate matching and text block splitting ensure that long text or text that spans cells can be correctly distributed in multiple cells.
[0058] For non-text blocks: record the edge coordinates of the non-text blocks, match the coordinate group of the corresponding list elements in the two-dimensional list, and insert placeholders in the area surrounded by the coordinate group. After image recognition of the non-text blocks, split the recognition results and replace the corresponding placeholders. Through image recognition and placeholder replacement, the position and integrity of non-text elements such as pictures or charts are maintained.
[0059] Process the pixels of the placeholders that have not been replaced. Identify the edge coordinate group of the placeholder, calculate the new edge coordinate group of the remaining placeholders after replacing the placeholders, and clear the pixels in the area covered by the new edge coordinate group; placeholders include but are not limited to tags or strings representing non-text blocks.
[0060] Compress the empty rows and columns in the list, traverse the two-dimensional list and delete the empty rows and columns, and finally generate a two-dimensional list without blank areas in the data structure. Before creating the Excel object and writing the data, filter the set cells in the two-dimensional list; set the cells to correspond to the set text information in the PDF file, and the set text information includes but is not limited to titles and comments; adjust the format of the corresponding set cells according to the corresponding style of the set text information in the PDF file. By clearing the unreplaced placeholders, the neatness and accuracy of the final conversion result are ensured.
[0061] Create an Excel object, traverse the two-dimensional list, and write the list elements of the two-dimensional list into the Excel object row by row. Writing the processed data into the Excel object can facilitate users to edit, analyze and share data.
[0062] In summary, this embodiment provides a document type conversion method that retains the PDF file format, and ensures that the converted Excel file can accurately reflect the layout and content of the original document by optimizing the extraction and processing process of text information and layout information. The method reads the PDF file page by page and generates an XML file, establishes a two-dimensional list that matches the PDF size, and stores the text information in the list according to the position coordinates, while processing non-text blocks and replacing placeholders, and finally generates a two-dimensional list without blank areas and writes it into an Excel object, thereby achieving data integrity and format accuracy, and facilitating users to edit and analyze data.
[0063] Embodiment 4: This embodiment provides a file conversion method that retains the PDF file format. An example is substituted based on the method in Embodiment 3 to further explain the extraction and processing process of text information and layout information.
[0064] Suppose there is a PDF file that contains a market research report. The report contains a product comparison table with 15 rows and 5 columns, showing the characteristics of different products. The first row of the table is the title row, which contains fields such as "Product Model", "Price", "Weight", "Function" and "Evaluation". Now you need to convert this table into Excel format for data analysis and editing.
[0065] First, extract text information and layout information. Get the total number of pages in the PDF file and traverse each page, load the page content page by page and return the page object page by page, extract the text information in each page object, and determine the layout information of the text information in the page based on the bounding box and subject tags identified in the page object. For example, identify the titles such as "Product Model" and "Price" in the table and record their position coordinates. This method ensures the integrity of the text information and can accurately reflect the layout of the text on the page.
[0066] Establish a two-dimensional list. Obtain the size information of the PDF file according to the layout information, and establish a two-dimensional list according to the size information. Initialize an empty two-dimensional list; calculate the size information of the width and height of the PDF file according to the layout information of the PDF file; match the width and height of the empty two-dimensional list with the size information of the PDF file to form a two-dimensional list adapted to the PDF file, and record the coordinates of the list elements in the two-dimensional list. By matching the size information of the PDF file, it is ensured that the size of the two-dimensional list is completely consistent with the PDF file, thereby ensuring accurate filling of data.
[0067] Associate pixels with list elements. Record the text information and position coordinates of the pixels according to the size information of the PDF file; associate the list elements of the two-dimensional list with the pixels of the PDF file to determine the coordinates of the list elements in the two-dimensional list. Through coordinate association, it is ensured that the information of each pixel can be accurately mapped to the corresponding position in the two-dimensional list.
[0068] Parse an XML file and store it into a two-dimensional list.
[0069] For text blocks: extract the text coordinates of each text block from the XML file, associate the text coordinates with the coordinates of the list element based on the correspondence between the pixel points and the text block, and insert the text block into the two-dimensional list. For example, if the coordinates of the text block "Product Model" are (100, 100), then insert "Product Model" at the corresponding position (100, 100) in the two-dimensional list. If a text block covers multiple cells, split it. Coordinate matching and text block splitting ensure that long text or text that spans cells can be correctly distributed in multiple cells.
[0070] For non-text blocks: record the edge coordinates of the non-text blocks, match the coordinate group of the corresponding list elements in the two-dimensional list, and insert placeholders in the area surrounded by the coordinate group. For example, product images in a table will be identified and corresponding placeholders will be inserted. Coordinate matching and text block splitting ensure that long text or text that spans cells can be correctly distributed in multiple cells.
[0071] Process the pixels of the placeholders that have not been replaced. Identify the edge coordinate group of the placeholder, calculate the new edge coordinate group of the remaining placeholders after replacing the placeholders, and clear the pixels in the area covered by them according to the new edge coordinate group. By clearing the placeholders that have not been replaced, the neatness and accuracy of the final conversion result are ensured.
[0072] Compress the empty rows and columns in the list, traverse the two-dimensional list and delete the empty rows and columns, and finally generate a two-dimensional list without blank areas in the data structure. Before creating an Excel object and writing data, filter the set cells in the two-dimensional list; set the cells to correspond to the set text information in the PDF file, and the set text information includes but is not limited to titles and comments; adjust the format of the corresponding set cells according to the corresponding style of the set text information in the PDF file. Create an Excel object, traverse the two-dimensional list, and write the list elements of the two-dimensional list into the Excel object row by row.
[0073] Through the above steps, even if the PDF file contains complex table data, it can be successfully converted into Excel format and maintain the original layout and data structure. This method not only improves the accuracy of data conversion, but also greatly enhances the practicality and editability of the converted file, which is very suitable for work scenarios that need to frequently process PDF files with tables.
[0074] It should be understood that the embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. In addition, it should be understood that after reading the content taught by the present invention, those skilled in the art can make various changes or modifications to the present invention, and these equivalent forms also fall within the scope limited by the appended claims of the application.
Claims
1. A file conversion method retaining the PDF file format, characterized in that: include: Read the PDF file to obtain text information and layout information, obtain the position coordinates of the pixel points corresponding to the text information, and generate an XML file based on the position coordinates and layout information; Obtain size information of the PDF file according to the layout information, establish a two-dimensional list based on the size information, parse the XML file, and store the text information in the XML file into the two-dimensional list; Compress empty rows and columns in a list and write the data in a two-dimensional list into an Excel object.
2. A method for converting a file while preserving the PDF file format according to claim 1, characterized in that: The process of reading a PDF file to obtain text information and layout information includes: Get the total number of pages in the PDF file, load the page content page by page and return the page objects page by page, extract the text information in each page object, and determine the layout information of the text information in the page based on the bounding box and subject tags identified in the page object.
3. The method for converting a file in PDF format according to claim 1, characterized in that: The process of building a two-dimensional list includes: Initialize an empty two-dimensional list; Calculate the size information of the width and height of the PDF file according to the layout information of the PDF file; The width and height of the empty two-dimensional list are matched with the size information of the PDF file to form a two-dimensional list adapted to the PDF file, and the coordinates of the list elements in the two-dimensional list are recorded.
4. The method for converting a file in PDF format according to claim 3, characterized in that: The process of building a two-dimensional list further includes: Record the text information and position coordinates of the pixel points according to the size information of the PDF file; The list elements of the two-dimensional list are associated with the pixel points of the PDF file to determine the coordinates of the list elements in the two-dimensional list.
5. The method for converting a file in PDF format according to claim 1, characterized in that: The process of storing the text information in the XML file into a two-dimensional list according to the position coordinates includes: For text blocks: extract the text coordinates of each text block from the XML file, associate the text coordinates with the coordinates of the list elements according to the correspondence between the pixel points and the text blocks, and insert the text blocks into the two-dimensional list; For non-text blocks: record the edge coordinates of the non-text blocks, match the coordinate group of the corresponding list elements in the two-dimensional list, and insert a placeholder in the area surrounded by the coordinate group.
6. A method for converting a file while retaining the PDF file format according to claim 5, characterized in that: The process of storing the text information in the XML file into the two-dimensional list according to the position coordinates further includes: For a text block: match the text coordinates of the text block with the coordinate groups of the list elements in the two-dimensional list. If the number of cells covered by the area formed by the coordinate groups of the list elements is greater than 1, split the text block and fill the relevant cells with the split text blocks according to the coordinate groups of the corresponding list elements. For non-text blocks: After performing image recognition on the non-text blocks, split the recognition results to replace the corresponding placeholders, and process the pixels that are not replaced by the placeholders.
7. A method for converting a file while preserving the PDF file format according to claim 6, characterized in that: The process of handling pixels that are not replaced by placeholders includes: Identify the edge coordinate group of the placeholder, calculate the new edge coordinate group of the remaining placeholder after replacing the placeholder, and clear the pixels in the covered area according to the new edge coordinate group; the placeholder includes but is not limited to a mark or character string representing a non-text block.
8. The method for converting a file in PDF format according to claim 1, characterized in that: The process of compressing empty rows and columns in a list includes: Traverse the two-dimensional list and remove empty rows and columns to generate a two-dimensional list with no white space in the data structure.
9. The method for converting a file in PDF format according to claim 1, characterized in that: Before writing the data in the two-dimensional list to the Excel object, also include: Filter set cells in a two-dimensional list; Set the cell to correspond to the set text information in the PDF file, and the set text information includes but is not limited to titles and comments; Adjust the format of the corresponding set cell according to the corresponding style of the set text information in the PDF file.
10. A method for converting a file while preserving the PDF file format according to claim 1 or 9, characterized in that: The process of writing data from a two-dimensional list to an Excel object includes: Create an Excel object, traverse the two-dimensional list, and write the list elements of the two-dimensional list into the Excel object row by row.