PDF file conversion method, device, computer equipment and readable storage medium
The method enhances PDF file transcription accuracy by identifying and aligning text, tables, and images in PDF files, addressing layout discrepancies through regularization and splicing, resulting in precise typesetting in the target file format.
Patent Information
- Application Number
- CN202210182334.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-25
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2042-02-25
AI Technical Summary
PDF file transcription often results in low typesetting accuracy due to discrepancies in layout between the original PDF file and the transcribed file format.
A method involving the identification of target objects (text, tables, and images) in a PDF file, applying regularization rules to their position information, splicing them based on preset rules, and typesetting them to generate a target file in a preset format, using a device comprising modules for acquisition, regularization, splicing, and generation.
Improves the correctness of the layout and typesetting of transcribed PDF files by aligning and arranging text, tables, and images accurately in the target file format.
Smart Images

Figure CN114548054B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of file format transcription, and in particular to a PDF file transcription method, device, computer equipment and readable storage medium. Background Art
[0002] PDF files are compressed text formats that can be used to contain formatted text, tables, images and other file contents. They are often used for text scanning and archiving of books, and the final file content exists in the form of pictures.
[0003] In daily use, the file content in a PDF file often needs to be transcribed into a file format such as word or txt. However, after the PDF file is transcribed, the layout of the file content in the transcribed file is easily different from the layout of the file content in the PDF file, resulting in a technical problem of low typesetting accuracy after PDF file transcription. Summary of the invention
[0004] The main purpose of this application is to provide a PDF file transcription method, device, computer equipment and readable storage medium, aiming to improve the correctness of the layout of the PDF file after transcription.
[0005] In a first aspect, the present application provides a PDF file transcription method, the PDF file transcription method comprising the following steps:
[0006] Acquire a PDF file, identify a target object in the PDF file, and obtain first position information of the target object, where the target object includes at least one of the following: text, table, and image;
[0007] Regularizing the first position information based on a preset regularization rule to obtain second position information of the target object;
[0008] Based on a preset splicing rule, and according to the second position information, the target object is spliced to obtain third position information of the target object;
[0009] The target object is typeset according to the third position information to generate a target file in a preset format.
[0010] In a second aspect, the present application further provides a PDF file conversion device, the PDF file conversion device comprising:
[0011] A PDF file acquisition module, used to acquire a PDF file, identify a target object in the PDF file, and obtain first position information of the target object, wherein the target object includes at least one of the following: text, table, and image;
[0012] A regularization processing module, used to regularize the first position information based on a preset regularization rule to obtain second position information of the target object;
[0013] A splicing processing module, configured to perform splicing processing on the target object based on a preset splicing rule and the second position information to obtain third position information of the target object;
[0014] The target file generation module is used to typeset the target object according to the third position information to generate a target file in a preset format.
[0015] In a third aspect, the present application further provides a computer device, the computer device comprising a memory and a processor;
[0016] The memory is used to store computer programs;
[0017] The processor is used to execute the computer program and implement the PDF file conversion method as described above when executing the computer program.
[0018] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the PDF file conversion method as described above are implemented.
[0019] The present application provides a PDF file transcription method, apparatus, computer equipment and readable storage medium, the method comprising: acquiring a PDF file, identifying a target object in the PDF file, and obtaining first position information of the target object, wherein the target object comprises at least one of the following: text, a table, and an image; regularizing the first position information based on a preset regularization rule to obtain second position information of the target object; splicing the target object based on the second position information based on a preset splicing rule to obtain third position information of the target object; typeset the target object based on the third position information to generate a target file in a preset format, thereby improving the correctness of the typesetting of the PDF file after transcription. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0021] Figure 1 A flowchart of a PDF file transcription method provided in an embodiment of the present application;
[0022] Figure 2 An application scenario diagram of a PDF file transcription method provided in one embodiment of the present application;
[0023] Figure 3 A text diagram related to an embodiment of the present application;
[0024] Figure 4 A text diagram related to another embodiment of the present application;
[0025] Figure 5 This is a schematic diagram of a table related to another embodiment of the present application;
[0026] Figure 6 A schematic block diagram of a PDF file conversion device provided in an embodiment of the present application;
[0027] Figure 7 A schematic block diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0029] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.
[0030] The embodiments of the present application provide a PDF file transcription method, device, computer equipment and readable storage medium. Among them, the PDF file transcription method can be applied to a terminal device, which can be an electronic device such as a mobile phone, a tablet computer, a laptop computer, a desktop computer, etc. It can also be applied to a server, which can be a separate server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0031] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0032] See also Figure 1 , Figure 1 A flowchart of a PDF file conversion method provided in an embodiment of the present application is provided. The PDF file conversion method can be used in a terminal device, and of course can also be used in a server.
[0033] The terminal device may include at least one of the following: a mobile phone, a tablet computer, a laptop computer, a desktop computer; the server may be a stand-alone server or a cloud server that provides cloud computing services.
[0034] See also Figure 2 , Figure 2 An application scenario diagram of a PDF file transcription method provided in one embodiment of the present application.
[0035] like Figure 2 As shown, the PDF file can be obtained by the server from the terminal device, and the target file in a preset format is obtained according to the PDF file transcription method, and the target file in the preset format is sent to the terminal device. The target file in the preset format can be stored in the server or the terminal device, which is not limited here.
[0036] like Figure 1 As shown, the PDF file transcription method includes steps S101 to S104.
[0037] Step S101: Obtain a PDF file, identify a target object in the PDF file, and obtain first position information of the target object, where the target object includes at least one of the following: text, table, and image.
[0038] For example, text, tables, and images in a PDF file may be recognized by using OCR technology, pdfplumber, and the like.
[0039] In some embodiments, when recognizing text in a PDF file, the recognized text is text fragments. It is understandable that text fragments mean that the recognized text in the PDF file does not retain paragraph information, but recognizes multiple lines of text in the PDF file from top to bottom and from left to right. For example, during the recognition process of the same line of text, the text fragments and punctuation fragments in the text may be separated.
[0040] In some embodiments, when identifying a table in a PDF file, the table identified is generally a fully-enclosed frame type table. It is understandable that a table includes a fully-enclosed frame type table or a non-fully-enclosed frame type table, and a non-fully-enclosed frame type table cannot be identified, that is, incomplete recognition of the frame of the table is likely to cause typesetting errors when the PDF file is converted into a file of another format. Exemplarily, a line recognition algorithm can be superimposed to identify the lines included in the PDF file.
[0041] In some embodiments, when recognizing an image in a PDF file, if the image includes text, the text in the image will be recognized as text fragments accordingly; if the image includes a table, the lines included in the PDF file will be recognized accordingly.
[0042] Step S102: regularize the first position information based on a preset regularization rule to obtain second position information of the target object.
[0043] Optionally, regularizing the first position information based on a preset regularization rule to obtain second position information of the target object includes:
[0044] When the target object is text, adjacent text segments and punctuation segments in the same line of text are obtained, wherein the end horizontal coordinate of the text segment is smaller than the start horizontal coordinate of the punctuation segment;
[0045] If the absolute value of the difference between the starting abscissa of the punctuation mark segment and the ending abscissa of the punctuation mark segment is not equal to the preset width, determining the target starting abscissa of the punctuation mark segment according to the first preset tolerance value, the preset width, the starting abscissa of the punctuation mark segment, the ending abscissa of the punctuation mark segment, and the ending abscissa of the text segment, and determining the target ending abscissa of the punctuation mark segment according to the target starting abscissa of the punctuation mark segment and the preset width;
[0046] If the absolute value of the difference between the starting vertical coordinate of the punctuation segment and the ending vertical coordinate of the punctuation segment is not equal to the preset height, the target starting vertical coordinate of the punctuation segment is determined according to the first preset tolerance value, the preset height, the starting vertical coordinate of the punctuation segment, the ending vertical coordinate of the punctuation segment and the starting vertical coordinate of the text segment, and the target ending vertical coordinate of the punctuation segment is determined according to the target starting vertical coordinate of the punctuation segment and the preset height.
[0047] Exemplarily, the preset width may include a width corresponding to the font size of the text in the text segment.
[0048] In some embodiments, Figure 3As shown, the width of the punctuation mark segment 1 is not equal to the preset width. For example, the preset width is h, the starting horizontal coordinate of the punctuation mark segment 1 is x0, and the ending horizontal coordinate of the punctuation mark segment 1 is x1. The first preset tolerance value is set to 0.5 times the preset width, that is, the first preset tolerance value is 0.5h. It can be understood that the absolute value of the difference between the starting horizontal coordinate x0 of the punctuation mark segment 1 and the ending horizontal coordinate x1 of the punctuation mark segment 1 is equivalent to the width of the punctuation mark segment 1. The first preset tolerance value is equivalent to the maximum tolerable difference between the preset width and the width of the punctuation mark segment 1, which is equivalent to h-(x1-x0)<0.5h or (x1-x0)-h<0.5h, that is, 0.5h<(x1-x0)<1.5h.
[0049] According to the first preset tolerance value and the starting horizontal coordinate of the punctuation mark segment 1, a first value range of the target starting horizontal coordinate of the punctuation mark segment 1 is determined to be (x0-0.5h, x0+0.5h].
[0050] According to the preset width, the starting horizontal coordinate x0 of the punctuation mark segment 1 and the ending horizontal coordinate x1 of the punctuation mark segment 1, the second value range of the target starting horizontal coordinate of the punctuation mark segment 1 is determined, so that the overlapping part of the first value range and the second value range of the target starting horizontal coordinate of the punctuation mark segment 1 can be determined.
[0051] For example, when the width of the punctuation mark segment 1 is less than the preset width h, the terminal horizontal coordinate x1 of the punctuation mark segment 1 is fixed, that is, the target terminal horizontal coordinate of the punctuation mark segment 1 is equal to the terminal horizontal coordinate x1 of the punctuation mark segment 1. If the width of the punctuation mark segment 1 is equal to the preset width, the target starting horizontal coordinate of the punctuation mark segment 1 is x1-h; the starting horizontal coordinate x0 of the punctuation mark segment 1 is fixed, that is, the target starting horizontal coordinate of the punctuation mark segment 1 is equal to the starting horizontal coordinate x0 of the punctuation mark segment 1. If the width of the punctuation mark segment 1 is equal to the preset width, the target terminal horizontal coordinate of the punctuation mark segment 1 is x0+h, then the second value range of the target starting horizontal coordinate of the punctuation mark segment 1 is (x1-h, x0]. It can be understood that according to 0.5h<(x1-x0)<1.5h, it can be determined that the overlapping part between the first value range and the second value range of the target starting horizontal coordinate of the punctuation mark segment 1 is (x1-h, x0].
[0052] Similarly, when the width of the punctuation mark segment 1 is greater than the preset width h, it can be determined that the overlapping portion between the first value range and the second value range of the target starting horizontal coordinate of the punctuation mark segment 1 is (x0, x1-h].
[0053] In some embodiments, in the overlapping part between the first value range and the second value range of the target starting horizontal coordinate of the punctuation segment 1, the horizontal coordinate with the smallest distance from the ending coordinate of the text segment 1 is selected as the target starting horizontal coordinate of the punctuation segment 1, and the target ending horizontal coordinate of the punctuation segment is determined based on the target starting horizontal coordinate of the punctuation segment 1 and a preset width.
[0054] Understandable, such as Figure 4 As shown, by regularizing the starting horizontal coordinate and the ending horizontal coordinate of the punctuation mark segment 1, the target starting horizontal coordinate and the target ending horizontal coordinate of the punctuation mark segment 1 are obtained, so that the width of the punctuation mark segment 1 is equal to the preset width, which is beneficial to improve the correctness of the layout of the text segment and the punctuation mark segment after the PDF file is transcribed.
[0055] Exemplarily, the preset height may include a height corresponding to the font size of the text in the text segment.
[0056] In some embodiments, Figure 3 As shown, the height of the punctuation mark segment 1 is not equal to the preset height. It can be understood that the absolute value of the difference between the starting vertical coordinate of the punctuation mark segment 1 and the ending vertical coordinate of the punctuation mark segment 1 is equivalent to the height of the punctuation mark segment 1. The target starting vertical coordinate of the punctuation mark segment 1 is determined according to the first preset tolerance value, the preset height, the starting vertical coordinate of the punctuation mark segment 1, the ending vertical coordinate of the punctuation mark segment 1 and the starting vertical coordinate of the text segment 1.
[0057] Understandable, such as Figure 4 As shown, by regularizing the starting ordinate and the ending ordinate of the punctuation mark segment 1, the target starting ordinate and the target ending ordinate of the punctuation mark segment 1 are obtained, so that the height of the punctuation mark segment 1 is equal to the preset height, which is beneficial to improve the correctness of the layout of the text segment and the punctuation mark segment after the PDF file is transcribed.
[0058] Optionally, regularizing the first position information based on a preset regularization rule to obtain second position information of the target object includes:
[0059] When the target object is a table, determining a plurality of table horizontal lines on the table and a first horizontal line length of each of the table horizontal lines;
[0060] Determine the standard table horizontal line and the standard table horizontal line length according to the first horizontal line length of each table horizontal line;
[0061] If the length of the first horizontal line of the table is not equal to the length of the standard horizontal line of the table, determining the length of the second horizontal line of the table according to the second preset tolerance value, the length of the first horizontal line of the table and the length of the standard horizontal line of the table;
[0062] According to the starting horizontal coordinate of the standard table horizontal line, determine the target starting horizontal coordinate of the table horizontal line;
[0063] The target ending horizontal coordinate of the table horizontal line is determined according to the target starting horizontal coordinate of the table horizontal line and the second horizontal line length of the table horizontal line.
[0064] In some embodiments, after identifying the lines included in the PDF file, the line can be determined to be a table line based on the existence of at least one intersection on the line. If the starting vertical coordinate of the table line is equal to the ending vertical coordinate, the table line is determined to be a table horizontal line. Similarly, multiple table horizontal lines on the table are determined, and the first horizontal line length of each table horizontal line is determined based on the starting horizontal coordinate and the ending horizontal coordinate of each table horizontal line. The maximum value of the first horizontal line length is selected as the standard table horizontal line length, and the table horizontal line corresponding to the standard table horizontal line length is determined as the standard table horizontal line.
[0065] In some embodiments, the standard horizontal line length is d, the first horizontal line length is d1, and the second preset tolerance value is 0.05 times the standard horizontal line length, that is, the second preset tolerance value is 0.05d. It can be understood that the second preset tolerance value is equivalent to the maximum tolerable difference between the standard horizontal line length and the first horizontal line length. Therefore, the second preset tolerance value can be intuitively expressed as d-d1<0.05d. It can be understood that the table horizontal line that needs to be regularized in length can be determined based on the second preset tolerance value, the first horizontal line length of the table horizontal line, and the standard table horizontal line length.
[0066] When the first horizontal line length of the table horizontal line d1≠d, and d-d1<0.05d, the value range of the second horizontal line length of the table horizontal line is determined to be (d1-0.05d, d1+0.05d] according to the second preset tolerance value and the first horizontal line length of the table horizontal line, and the horizontal line length with the smallest difference from the standard horizontal line length is selected as the second horizontal line length of the table horizontal line, and the target starting horizontal coordinate of the table horizontal line is determined according to the starting horizontal coordinate of the standard table horizontal line, and the target ending horizontal coordinate of the table horizontal line is determined according to the target starting horizontal coordinate of the table horizontal line and the second horizontal line length of the table horizontal line, so that the length of the table horizontal line is equal to the standard table horizontal line length, which is beneficial to improve the correctness of the table line layout after the PDF file is transcribed.
[0067] In some embodiments, after obtaining multiple table horizontal lines, they can also be grouped according to the starting horizontal coordinates of each table horizontal line. For example, the multiple table horizontal lines include a first table horizontal line and a second table horizontal line. If the difference between the starting horizontal coordinate of the first table horizontal line and the starting horizontal coordinate of the second table horizontal line is greater than a preset table horizontal line starting horizontal coordinate difference threshold, then the first table horizontal line and the second table horizontal line are very likely to be table horizontal lines in different tables. The first table horizontal line and the second table horizontal line are divided into different table horizontal line groups. It can be understood that the standard table horizontal lines and the lengths of the standard table horizontal lines corresponding to the table horizontal lines in different tables may be different. According to different table horizontal line groups, the standard table horizontal lines and the lengths of the standard table horizontal lines in each table horizontal line group are determined, so that the lengths of each table horizontal line in each table horizontal line group are equal to the lengths of the standard table horizontal lines.
[0068] Optionally, regularizing the first position information based on a preset regularization rule to obtain second position information of the target object includes:
[0069] When the target object is a table, determining a plurality of table vertical lines on the table and a first vertical line length of each table vertical line;
[0070] Determine the standard table vertical line and the standard table vertical line length according to the first vertical line length of each table vertical line;
[0071] If the first vertical line length of the table vertical line is not equal to the standard table vertical line length, determining the second vertical line length of the table vertical line according to the second preset tolerance value, the first vertical line length of the table vertical line and the standard table vertical line length;
[0072] According to the starting ordinate of the standard table vertical line, the target starting ordinate of the plurality of table vertical lines is determined;
[0073] The target ending vertical coordinate of the table vertical line is determined according to the target starting vertical coordinate of the table vertical line and the second vertical line length of the table vertical line.
[0074] It can be understood that after determining the table line from the lines included in the PDF file, if the starting horizontal coordinate of the table line is equal to the ending horizontal coordinate, then the table line is determined to be a table vertical line, and so on, multiple table vertical lines on the table are determined, and the first vertical line length of each table vertical line is determined according to the starting vertical coordinate and the ending vertical coordinate of each table vertical line, the maximum value of the first vertical line length is selected as the standard table vertical line length, and the table vertical line corresponding to the standard table vertical line length is determined to be the standard table vertical line, if the first vertical line length of the table vertical line is not equal to the standard table vertical line length, the second vertical line length of the table vertical line is determined according to the second preset tolerance value, the first vertical line length of the table vertical line and the standard table vertical line length, the target starting horizontal coordinate of the table vertical line is determined according to the starting vertical coordinate of the standard table vertical line, and the target ending vertical coordinate of the table vertical line is determined according to the target starting horizontal coordinate of the table vertical line and the second vertical line length of the table vertical line, so that the length of the table vertical line is equal to the standard table vertical line length, which is beneficial to improve the correctness of the table line typesetting after the PDF file is transcribed.
[0075] Step S103: Based on a preset splicing rule and according to the second position information, the target object is spliced to obtain third position information of the target object.
[0076] Optionally, based on a preset splicing rule and according to the second position information, the target object is spliced to obtain the third position information of the target object, including:
[0077] Obtaining a first text segment and a second text segment adjacent to each other in the same line of text, wherein the end horizontal coordinate of the first text segment is smaller than the start horizontal coordinate of the second text segment;
[0078] If the absolute value of the difference between the ending horizontal coordinate of the first text segment and the starting horizontal coordinate of the second text segment is less than the first horizontal coordinate difference threshold, the target starting horizontal coordinate of the second text segment is determined according to the ending horizontal coordinate of the first text segment.
[0079] In some embodiments, for a first text segment and a second text segment adjacent to each other in the same line of text, if the ending horizontal coordinate of the first text segment is smaller than the starting horizontal coordinate of the second text segment, and the horizontal coordinate difference between the ending horizontal coordinate of the first text segment and the starting horizontal coordinate of the second text segment is smaller than a first horizontal coordinate difference threshold, the ending horizontal coordinate of the first text segment is determined as the target starting horizontal coordinate of the second text segment, thereby splicing the first text segment and the second text into one text segment. It can be understood that after completing the splicing of adjacent text segments in the same line of text, a line of text is equivalent to one text segment.
[0080] Optionally, based on a preset splicing rule and according to the second position information, the target object is spliced to obtain the third position information of the target object, further comprising:
[0081] Obtaining a third text segment and a fourth text segment of adjacent lines, wherein the end vertical coordinate of the third text segment is smaller than the start vertical coordinate of the fourth text segment;
[0082] If the absolute value of the difference between the starting horizontal coordinate of the third text segment and the starting horizontal coordinate of the fourth text segment is greater than the second horizontal coordinate difference threshold, determining the target number of spaces between the third text segment and the fourth text segment according to the starting horizontal coordinate of the third text segment, the starting horizontal coordinate of the fourth text segment and the preset width;
[0083] Determining a standard space width between the third text segment and the fourth text segment according to the target number of spaces and a preset width;
[0084] The target starting horizontal coordinate of the fourth text segment is determined according to the starting horizontal coordinate of the third text segment and the standard space width.
[0085] In some embodiments, for the third text segment and the fourth text segment in adjacent lines of text, if the ending ordinate of the third text segment is less than the starting ordinate of the fourth text segment, and the absolute value of the difference between the starting horizontal coordinate of the third text segment and the starting horizontal coordinate of the fourth text segment is greater than the second horizontal coordinate difference threshold, the target number of spaces between the third text segment and the fourth text segment can be determined based on the ratio of the absolute value of the difference between the starting horizontal coordinate of the third text segment and the starting horizontal coordinate of the fourth text segment to the preset width. It can be understood that when the ratio is a non-integer, the ratio can be rounded using a preset rounding standard to determine the target number of spaces between the third text segment and the fourth text segment, thereby padding the spaces of the third text segment and the fourth text segment.
[0086] In some embodiments, if the absolute value of the difference between the starting horizontal coordinate of the third text segment and the starting horizontal coordinate of the fourth text segment is less than a second horizontal coordinate difference threshold, the target starting horizontal coordinate of the fourth text segment can be determined based on the starting horizontal coordinate of the third text segment, thereby aligning the third text segment and the fourth text segment. It can be understood that this is equivalent to aligning the third text segment and the fourth text segment to the left based on the starting horizontal coordinate of the third text segment.
[0087] In some embodiments, if the absolute value of the difference between the terminal horizontal coordinate of the third text segment and the terminal horizontal coordinate of the fourth text segment is less than the second horizontal coordinate difference threshold, the target terminal horizontal coordinate of the fourth text segment can be determined according to the terminal horizontal coordinate of the third text segment, thereby aligning the third text segment and the fourth text segment. It can be understood that this is equivalent to aligning the third text segment and the fourth text segment to the right according to the terminal horizontal coordinate of the third text segment.
[0088] It is understandable that splicing text fragments can help improve the accuracy of text layout after PDF file transcription.
[0089] Optionally, based on a preset splicing rule and according to the second position information, the target object is spliced to obtain the third position information of the target object, further comprising:
[0090] When the target object is a table, multiple intersection points between multiple table horizontal lines and multiple table vertical lines are obtained;
[0091] Determine a plurality of table rectangles according to a plurality of intersection points between a plurality of table horizontal lines and a plurality of table vertical lines;
[0092] Among the plurality of table rectangles, obtaining a first table rectangle and a second table rectangle that are adjacent to each other;
[0093] When the starting ordinate of the first table rectangle is equal to the starting ordinate of the second table rectangle, the ending ordinate of the first table rectangle is equal to the ending ordinate of the second table rectangle, and the ending abscissa of the first table rectangle is equal to the starting abscissa of the second table rectangle: determining a target table according to the first table rectangle and the second table rectangle, determining a target starting abscissa of the target table according to the starting abscissa of the first table rectangle, and determining a target ending abscissa of the target table according to the ending abscissa of the second table rectangle;
[0094] When the starting abscissa of the first table rectangle is equal to the starting abscissa of the second table rectangle, the ending abscissa of the first table rectangle is equal to the ending abscissa of the second table rectangle, and the ending ordinate of the first table rectangle is equal to the starting ordinate of the second table rectangle: a target table is determined based on the first table rectangle and the second table rectangle, a target starting ordinate of the target table is determined based on the starting ordinate of the first table rectangle, and a target ending ordinate of the target table is determined based on the ending ordinate of the second table rectangle.
[0095] In some embodiments, Figure 5As shown, multiple intersections between multiple table horizontal lines and multiple table vertical lines are obtained, such as intersection A, intersection B, intersection C, and intersection D, wherein the horizontal coordinate of intersection A is equal to the horizontal coordinate of intersection B, the horizontal coordinate of intersection C is equal to the horizontal coordinate of intersection D, the vertical coordinate of intersection A is equal to the vertical coordinate of intersection C, and the vertical coordinate of intersection B is equal to the vertical coordinate of intersection D. According to intersection A, target point E is obtained, and target point E is located at the upper left of intersection A; according to intersection B, target point F is obtained, and target point F is located at the upper right of intersection B; according to intersection C, target point G is obtained, and target point G is located at the lower left of intersection C; according to intersection D, target point H is obtained, and target point H is located at the lower right of intersection D. If the abscissa of target point E is equal to the abscissa of target point F, the abscissa of target point G is equal to the abscissa of target point H, the ordinate of target point E is equal to the ordinate of target point G, and the ordinate of target point F is equal to the ordinate of target point H, then according to the target points E, F, G, H and the table lines where each target point is located, determine the table rectangle and the four vertices corresponding to the table rectangle, and so on, to obtain multiple table rectangles.
[0096] In some embodiments, based on the starting horizontal coordinate, ending horizontal coordinate, starting vertical coordinate and ending vertical coordinate of each table rectangle, it is determined whether the table rectangles can be horizontally or vertically spliced, and all table rectangles are traversed to obtain the position information corresponding to the target table in the PDF file.
[0097] It can be understood that obtaining a complete table based on multiple horizontal lines, multiple vertical lines and the intersections of multiple horizontal lines and multiple vertical lines is helpful to identify table rectangles with non-fully-enclosed borders, thereby helping to identify tables with non-fully-enclosed borders and improving the accuracy of table typesetting after PDF file transcription.
[0098] It can be understood that when the target object is an image, if the image includes text or a table, the text and the table in the image can be subjected to corresponding regularization and splicing processing, thereby improving the correctness of the image layout after the PDF file is transcribed.
[0099] Step S104: typeset the target object according to the third position information to generate a target file in a preset format.
[0100] In some embodiments, the position of the target object in the PDF file can be determined according to the position information of the target object, and the target objects are sorted from left to right and from top to bottom according to the position information of the target object to generate a target file in a preset format.
[0101] In some embodiments, if the target object is an image and the image includes text or a table, the position information of the image can be obtained, and the position information of the text and the table in the image can be obtained to determine the position of the text and the table in the image in the target file.
[0102] In some embodiments, when a PDF file is converted into a word file, the file is vertically assembled and output according to the position information of the text, table, and image, thereby retaining the typesetting information of the text, table, and image.
[0103] In some embodiments, when a PDF file is converted into a txt file, the text is directly output to the txt file in order from left to right and from top to bottom according to the position information, and the table is segmented according to the tab character, thereby retaining the layout information of the text and the table.
[0104] In some embodiments, when a PDF file is transcribed into other md formats or online formats, the transcription is performed into the corresponding format according to the location information of the text, table, and image.
[0105] Exemplarily, the target file in a preset format can be stored in a blockchain. The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0106] It can be understood that when the server needs to obtain a target file in a preset format, it can broadcast to the blockchain, thereby determining the storage node or storage address of the target file in the preset format, so as to obtain the target file in the preset format from the storage node or storage address.
[0107] The PDF file transcription method provided in the above embodiment obtains a PDF file, identifies a target object in the PDF file, obtains first position information of the target object, and the target object includes at least one of the following: text, table, image. Based on a preset regularization rule, the first position information is regularized to obtain second position information of the target object. Based on a preset splicing rule, the target object is spliced according to the second position information to obtain third position information of the target object. The target object is typeset according to the third position information to generate a target file in a preset format, thereby improving the correctness of the typesetting of the PDF file after transcription.
[0108] See also Figure 6 , Figure 6A schematic block diagram of a PDF file conversion device provided in an embodiment of the present application, the PDF file conversion device can be configured in a server or a terminal device to execute the aforementioned PDF file conversion method.
[0109] like Figure 6 As shown, the PDF file conversion device includes: a PDF file acquisition module 110, a regularization processing module 120, a splicing processing module 130, and a target file generation module 140.
[0110] The PDF file acquisition module 110 is used to acquire a PDF file, identify a target object in the PDF file, and obtain first position information of the target object, where the target object includes at least one of the following: text, table, and image.
[0111] The regularization processing module 120 is used to regularize the first position information based on a preset regularization rule to obtain the second position information of the target object.
[0112] The splicing processing module 130 is used to perform splicing processing on the target object based on a preset splicing rule and according to the second position information to obtain third position information of the target object.
[0113] The target file generating module 140 is used to typeset the target object according to the third position information to generate a target file in a preset format.
[0114] Exemplarily, the regularization processing module 120 includes: a punctuation mark segment acquisition submodule, a punctuation mark segment width regularization submodule, and a punctuation mark segment height regularization submodule.
[0115] The punctuation mark segment acquisition submodule is used to acquire adjacent text segments and punctuation mark segments in the same line of text when the target object is text, wherein the end horizontal coordinate of the text segment is smaller than the start horizontal coordinate of the punctuation mark segment.
[0116] The punctuation mark segment width regular submodule is used to determine the target starting horizontal coordinate of the punctuation mark segment according to a first preset tolerance value, the preset width, the starting horizontal coordinate of the punctuation mark segment, the ending horizontal coordinate of the punctuation mark segment and the ending horizontal coordinate of the text segment if the absolute value of the difference between the starting horizontal coordinate of the punctuation mark segment and the ending horizontal coordinate of the punctuation mark segment is not equal to the preset width; and determine the target ending horizontal coordinate of the punctuation mark segment according to the target starting horizontal coordinate of the punctuation mark segment and the preset width.
[0117] The punctuation mark fragment height regularization submodule is used to determine the target starting vertical coordinate of the punctuation mark fragment according to a first preset tolerance value, the preset height, the starting vertical coordinate of the punctuation mark fragment, the ending vertical coordinate of the punctuation mark fragment and the starting vertical coordinate of the text fragment if the absolute value of the difference between the starting vertical coordinate of the punctuation mark fragment and the ending vertical coordinate of the punctuation mark fragment is not equal to the preset height; and determine the target ending vertical coordinate of the punctuation mark fragment according to the target starting vertical coordinate of the punctuation mark fragment and the preset height.
[0118] Exemplarily, the regularization processing module 120 further includes: a table horizontal line determination submodule, a standard table horizontal line determination submodule, a second horizontal line length determination submodule, a table horizontal line target starting horizontal coordinate determination submodule, and a table horizontal line target ending horizontal coordinate determination submodule.
[0119] The table horizontal line determination submodule is used to determine a plurality of table horizontal lines on the table and a first horizontal line length of each of the table horizontal lines when the target object is a table.
[0120] The standard table horizontal line determination submodule is used to determine the standard table horizontal line and the standard table horizontal line length according to the first horizontal line length of each table horizontal line.
[0121] The second horizontal line length determination submodule is used to determine the second horizontal line length of the table horizontal line according to the second preset tolerance value, the first horizontal line length of the table horizontal line and the standard horizontal line length of the table horizontal line if the first horizontal line length of the table horizontal line is not equal to the standard horizontal line length of the table.
[0122] The table horizontal line target starting horizontal coordinate determining submodule is used to determine the target starting horizontal coordinates of the plurality of table horizontal lines according to the starting horizontal coordinates of the standard table horizontal lines.
[0123] The table horizontal line target ending horizontal coordinate determining submodule is used to determine the target ending horizontal coordinate of the table horizontal line according to the target starting horizontal coordinate of the table horizontal line and the second horizontal line length of the table horizontal line.
[0124] Exemplarily, the regularization processing module 120 further includes: a table vertical line determination submodule, a standard table vertical line determination submodule, a second vertical line length determination submodule, a table vertical line target start vertical coordinate determination submodule, and a table vertical line target end vertical coordinate determination submodule.
[0125] The table vertical line determination submodule is used to determine a plurality of table vertical lines on the table and a first vertical line length of each of the table vertical lines when the target object is a table.
[0126] The standard table vertical line determination submodule is used to determine the standard table vertical line and the standard table vertical line length according to the first vertical line length of each table vertical line.
[0127] The second vertical line length determination submodule is used to determine the second vertical line length of the table vertical line according to a second preset tolerance value, the first vertical line length of the table vertical line and the standard table vertical line length if the first vertical line length of the table vertical line is not equal to the standard table vertical line length.
[0128] The table vertical line target starting ordinate determination submodule is used to determine the target starting ordinates of the plurality of table vertical lines according to the starting ordinates of the standard table vertical lines.
[0129] The table vertical line target ending ordinate determination submodule is used to determine the target ending ordinate of the table vertical line according to the target starting ordinate of the table vertical line and the second vertical line length of the table vertical line.
[0130] Exemplarily, the splicing processing module 130 includes: a submodule for acquiring a horizontally spliced text segment and a submodule for determining a target starting horizontal coordinate of the horizontally spliced text segment.
[0131] The horizontally spliced text segment acquisition submodule is used to acquire a first text segment and a second text segment adjacent to each other in the same line of text, wherein the end horizontal coordinate of the first text segment is smaller than the start horizontal coordinate of the second text segment.
[0132] The submodule for determining the target starting horizontal coordinate of the horizontally spliced text segments is used to determine the target starting horizontal coordinate of the second text segment according to the ending horizontal coordinate of the first text segment if the absolute value of the difference between the ending horizontal coordinate of the first text segment and the starting horizontal coordinate of the second text segment is less than a first horizontal coordinate difference threshold.
[0133] Exemplarily, the splicing processing module 130 further includes: a vertically spliced text segment acquisition submodule, a target space number determination submodule, a standard space width determination submodule, and a vertically spliced text segment target start horizontal coordinate determination submodule.
[0134] The vertically spliced text segment acquisition submodule is used to acquire a third text segment and a fourth text segment of adjacent lines, wherein the end vertical coordinate of the third text segment is smaller than the start vertical coordinate of the fourth text segment.
[0135] A target space number determination submodule is used to determine the target space number between the third text segment and the fourth text segment based on the starting horizontal coordinate of the third text segment, the starting horizontal coordinate of the fourth text segment and the preset width if the absolute value of the difference between the starting horizontal coordinate of the third text segment and the starting horizontal coordinate of the fourth text segment is greater than a second horizontal coordinate difference threshold.
[0136] The standard space width determination submodule is used to determine the standard space width between the third text segment and the fourth text segment according to the target number of spaces and the preset width.
[0137] The submodule for determining the target starting horizontal coordinate of the vertically spliced text segments is used to determine the target starting horizontal coordinate of the fourth text segment according to the starting horizontal coordinate of the third text segment and the standard space width.
[0138] Exemplarily, the splicing processing module 130 further includes: an intersection acquisition submodule, a table rectangle determination submodule, an adjacent table rectangle acquisition submodule, a horizontal splicing table third position information determination submodule, and a vertical splicing table third position information determination submodule.
[0139] The intersection point acquisition submodule is used to acquire a plurality of intersection points between the plurality of table horizontal lines and the plurality of table vertical lines when the target object is a table.
[0140] The table rectangle determination submodule is used to determine a plurality of table rectangles according to a plurality of intersection points between the plurality of table horizontal lines and the plurality of table vertical lines.
[0141] The adjacent table rectangle acquisition submodule is used to acquire an adjacent first table rectangle and a second table rectangle from among the plurality of table rectangles.
[0142] The third position information determination submodule of the horizontally spliced table is used for: when the starting vertical coordinate of the first table rectangle is equal to the starting vertical coordinate of the second table rectangle, the ending vertical coordinate of the first table rectangle is equal to the ending vertical coordinate of the second table rectangle, and the ending horizontal coordinate of the first table rectangle is equal to the starting horizontal coordinate of the second table rectangle: determining a target table according to the first table rectangle and the second table rectangle, determining a target starting horizontal coordinate of the target table according to the starting horizontal coordinate of the first table rectangle, and determining a target ending horizontal coordinate of the target table according to the ending horizontal coordinate of the second table rectangle.
[0143] The third position information determination submodule of the vertically spliced table is used for determining a target table according to the first table rectangle and the second table rectangle, determining a target starting vertical coordinate of the target table according to the starting vertical coordinate of the first table rectangle, and determining a target ending vertical coordinate of the target table according to the ending vertical coordinate of the second table rectangle when the starting horizontal coordinate of the first table rectangle is equal to the starting horizontal coordinate of the second table rectangle, the ending horizontal coordinate of the first table rectangle is equal to the ending horizontal coordinate of the second table rectangle, and the ending vertical coordinate of the first table rectangle is equal to the starting vertical coordinate of the second table rectangle.
[0144] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0145] The method of the present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0146] Exemplarily, the above method and apparatus may be implemented in the form of a computer program, which may be run on a computer device.
[0147] See also Figure 7 , Figure 7 A schematic block diagram of the structure of a computer device provided in an embodiment of the present application. The computer device may be a server or a terminal device.
[0148] like Figure 7 As shown, the computer device includes a processor, a memory, and a network interface connected via a system bus, wherein the memory may include a storage medium and an internal memory.
[0149] The storage medium can store an operating system and a computer program. The computer program includes program instructions, and when the program instructions are executed, the processor can execute any PDF file conversion method.
[0150] The processor is used to provide computing and control capabilities and support the operation of the entire computer equipment.
[0151] The internal memory provides an environment for the operation of the computer program in the storage medium. When the computer program is executed by the processor, the processor can execute any PDF file conversion method.
[0152] The network interface is used for network communication, such as sending assigned tasks, etc. Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0153] It should be understood that the processor may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0154] In one embodiment, the processor is used to run a computer program stored in the memory to implement the following steps:
[0155] Acquire a PDF file, identify a target object in the PDF file, and obtain first position information of the target object, where the target object includes at least one of the following: text, table, and image;
[0156] Regularizing the first position information based on a preset regularization rule to obtain second position information of the target object;
[0157] Based on a preset splicing rule, and according to the second position information, the target object is spliced to obtain third position information of the target object;
[0158] The target object is typeset according to the third position information to generate a target file in a preset format.
[0159] In one embodiment, when the processor regularizes the first position information based on a preset regularization rule to obtain the second position information of the target object, it is used to implement:
[0160] When the target object is text, adjacent text segments and punctuation mark segments in the same line of text are obtained, wherein the end horizontal coordinate of the text segment is smaller than the start horizontal coordinate of the punctuation mark segment;
[0161] If the absolute value of the difference between the starting horizontal coordinate of the punctuation mark segment and the ending horizontal coordinate of the punctuation mark segment is not equal to the preset width, determining the target starting horizontal coordinate of the punctuation mark segment according to the first preset tolerance value, the preset width, the starting horizontal coordinate of the punctuation mark segment, the ending horizontal coordinate of the punctuation mark segment and the ending horizontal coordinate of the text segment, and determining the target ending horizontal coordinate of the punctuation mark segment according to the target starting horizontal coordinate of the punctuation mark segment and the preset width;
[0162] If the absolute value of the difference between the starting vertical coordinate of the punctuation mark segment and the ending vertical coordinate of the punctuation mark segment is not equal to the preset height, the target starting vertical coordinate of the punctuation mark segment is determined according to the first preset tolerance value, the preset height, the starting vertical coordinate of the punctuation mark segment, the ending vertical coordinate of the punctuation mark segment and the starting vertical coordinate of the text segment, and the target ending vertical coordinate of the punctuation mark segment is determined according to the target starting vertical coordinate of the punctuation mark segment and the preset height.
[0163] In one embodiment, when the processor implements the regularization of the first position information based on a preset regularization rule to obtain the second position information of the target object, it is used to implement:
[0164] When the target object is a table, determining a plurality of table horizontal lines on the table and a first horizontal line length of each of the table horizontal lines;
[0165] Determine the standard table horizontal line and the standard table horizontal line length according to the first horizontal line length of each table horizontal line;
[0166] If the first horizontal line length of the table horizontal line is not equal to the standard table horizontal line length, determining the second horizontal line length of the table horizontal line according to the second preset tolerance value, the first horizontal line length of the table horizontal line and the standard table horizontal line length;
[0167] Determining target starting horizontal coordinates of the plurality of table horizontal lines according to the starting horizontal coordinates of the standard table horizontal lines;
[0168] The target ending horizontal coordinate of the table horizontal line is determined according to the target starting horizontal coordinate of the table horizontal line and the second horizontal line length of the table horizontal line.
[0169] In one embodiment, when the processor implements the regularization of the first position information based on a preset regularization rule to obtain the second position information of the target object, it is used to implement:
[0170] When the target object is a table, determining a plurality of table vertical lines on the table and a first vertical line length of each of the table vertical lines;
[0171] Determine the standard table vertical line and the standard table vertical line length according to the first vertical line length of each table vertical line;
[0172] If the first vertical line length of the table vertical line is not equal to the standard table vertical line length, determining the second vertical line length of the table vertical line according to the second preset tolerance value, the first vertical line length of the table vertical line and the standard table vertical line length;
[0173] Determining target starting vertical coordinates of the plurality of table vertical lines according to the starting vertical coordinates of the standard table vertical lines;
[0174] The target ending vertical coordinate of the table vertical line is determined according to the target starting vertical coordinate of the table vertical line and the second vertical line length of the table vertical line.
[0175] In one embodiment, when the processor implements the splicing process based on the preset splicing rule and according to the second position information to obtain the third position information of the target object, it is used to implement:
[0176] Acquire a first text segment and a second text segment adjacent to each other in the same line of text, wherein the end horizontal coordinate of the first text segment is smaller than the start horizontal coordinate of the second text segment;
[0177] If the absolute value of the difference between the ending horizontal coordinate of the first text segment and the starting horizontal coordinate of the second text segment is less than a first horizontal coordinate difference threshold, the target starting horizontal coordinate of the second text segment is determined according to the ending horizontal coordinate of the first text segment.
[0178] In one embodiment, when the processor implements the splicing process based on the preset splicing rule and according to the second position information to obtain the third position information of the target object, it is used to implement:
[0179] Acquire a third text segment and a fourth text segment of adjacent rows, wherein the end vertical coordinate of the third text segment is smaller than the start vertical coordinate of the fourth text segment;
[0180] If the absolute value of the difference between the starting horizontal coordinate of the third text segment and the starting horizontal coordinate of the fourth text segment is greater than a second horizontal coordinate difference threshold, determining a target number of spaces between the third text segment and the fourth text segment according to the starting horizontal coordinate of the third text segment, the starting horizontal coordinate of the fourth text segment and the preset width;
[0181] determining a standard space width between the third text segment and the fourth text segment according to the target number of spaces and the preset width;
[0182] The target starting horizontal coordinate of the fourth text segment is determined according to the starting horizontal coordinate of the third text segment and the standard space width.
[0183] In one embodiment, when the processor implements the splicing process based on the preset splicing rule and according to the second position information to obtain the third position information of the target object, it is used to implement:
[0184] When the target object is a table, obtaining a plurality of intersection points between the plurality of table horizontal lines and the plurality of table vertical lines;
[0185] Determine a plurality of table rectangles according to a plurality of intersections between the plurality of table horizontal lines and the plurality of table vertical lines;
[0186] Among the plurality of table rectangles, obtaining a first table rectangle and a second table rectangle that are adjacent to each other;
[0187] When the starting ordinate of the first table rectangle is equal to the starting ordinate of the second table rectangle, the ending ordinate of the first table rectangle is equal to the ending ordinate of the second table rectangle, and the ending abscissa of the first table rectangle is equal to the starting abscissa of the second table rectangle: determining a target table according to the first table rectangle and the second table rectangle, determining a target starting abscissa of the target table according to the starting abscissa of the first table rectangle, and determining a target ending abscissa of the target table according to the ending abscissa of the second table rectangle;
[0188] When the starting abscissa of the first table rectangle is equal to the starting abscissa of the second table rectangle, the ending abscissa of the first table rectangle is equal to the ending abscissa of the second table rectangle, and the ending ordinate of the first table rectangle is equal to the starting ordinate of the second table rectangle: a target table is determined based on the first table rectangle and the second table rectangle, a target starting ordinate of the target table is determined based on the starting ordinate of the first table rectangle, and a target ending ordinate of the target table is determined based on the ending ordinate of the second table rectangle.
[0189] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the PDF file transcription described above can refer to the corresponding process in the aforementioned PDF file transcription method embodiment, and will not be repeated here.
[0190] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. The computer program includes program instructions. The method implemented when the program instructions are executed can refer to the various embodiments of the PDF file transcription method of the present application.
[0191] The computer-readable storage medium may be an internal storage unit of the computer device described in the foregoing embodiment, such as a hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc., equipped on the computer device.
[0192] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0193] It should also be understood that the term "and / or" used in the specification of this application and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, including these combinations. It should be noted that, in this article, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "including a..." does not exclude the presence of other identical elements in the process, method, article or system including the element.
[0194] The serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments. The above description is only a specific implementation mode of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A PDF file transcription method, characterized in that: include: Acquire a PDF file, identify a target object in the PDF file, and obtain first position information of the target object, where the target object includes at least one of the following: text, table, and image; Regularizing the first position information based on a preset regularization rule to obtain second position information of the target object; Based on a preset splicing rule, and according to the second position information, the target object is spliced to obtain third position information of the target object; Typesetting the target object according to the third position information to generate a target file in a preset format; The step of regularizing the first position information based on a preset regularization rule to obtain the second position information of the target object includes: When the target object is text, adjacent text segments and punctuation mark segments in the same line of text are obtained, wherein the end horizontal coordinate of the text segment is smaller than the start horizontal coordinate of the punctuation mark segment; If the absolute value of the difference between the starting horizontal coordinate of the punctuation mark segment and the ending horizontal coordinate of the punctuation mark segment is not equal to the preset width, determining the target starting horizontal coordinate of the punctuation mark segment according to the first preset tolerance value, the preset width, the starting horizontal coordinate of the punctuation mark segment, the ending horizontal coordinate of the punctuation mark segment and the ending horizontal coordinate of the text segment, and determining the target ending horizontal coordinate of the punctuation mark segment according to the target starting horizontal coordinate of the punctuation mark segment and the preset width; If the absolute value of the difference between the starting vertical coordinate of the punctuation mark segment and the ending vertical coordinate of the punctuation mark segment is not equal to the preset height, the target starting vertical coordinate of the punctuation mark segment is determined according to the first preset tolerance value, the preset height, the starting vertical coordinate of the punctuation mark segment, the ending vertical coordinate of the punctuation mark segment and the starting vertical coordinate of the text segment, and the target ending vertical coordinate of the punctuation mark segment is determined according to the target starting vertical coordinate of the punctuation mark segment and the preset height.
2. The PDF file transcription method according to claim 1, characterized in that: The step of regularizing the first position information based on a preset regularization rule to obtain the second position information of the target object includes: When the target object is a table, determining a plurality of table horizontal lines on the table and a first horizontal line length of each of the table horizontal lines; Determine the standard table horizontal line and the standard table horizontal line length according to the first horizontal line length of each table horizontal line; If the first horizontal line length of the table horizontal line is not equal to the standard table horizontal line length, determining the second horizontal line length of the table horizontal line according to the second preset tolerance value, the first horizontal line length of the table horizontal line and the standard table horizontal line length; Determining target starting horizontal coordinates of the plurality of table horizontal lines according to the starting horizontal coordinates of the standard table horizontal lines; The target ending horizontal coordinate of the table horizontal line is determined according to the target starting horizontal coordinate of the table horizontal line and the second horizontal line length of the table horizontal line.
3. The PDF file transcription method according to claim 1, characterized in that: The step of regularizing the first position information based on a preset regularization rule to obtain the second position information of the target object includes: When the target object is a table, determining a plurality of table vertical lines on the table and a first vertical line length of each of the table vertical lines; Determine the standard table vertical line and the standard table vertical line length according to the first vertical line length of each table vertical line; If the first vertical line length of the table vertical line is not equal to the standard table vertical line length, determining the second vertical line length of the table vertical line according to the second preset tolerance value, the first vertical line length of the table vertical line and the standard table vertical line length; Determining target starting vertical coordinates of the plurality of table vertical lines according to the starting vertical coordinates of the standard table vertical lines; The target ending vertical coordinate of the table vertical line is determined according to the target starting vertical coordinate of the table vertical line and the second vertical line length of the table vertical line.
4. The PDF file conversion method according to any one of claims 1 to 3, characterized in that: The step of performing splicing processing on the target object based on the preset splicing rule and according to the second position information to obtain the third position information of the target object includes: Acquire a first text segment and a second text segment adjacent to each other in the same line of text, wherein the end horizontal coordinate of the first text segment is smaller than the start horizontal coordinate of the second text segment; If the absolute value of the difference between the ending horizontal coordinate of the first text segment and the starting horizontal coordinate of the second text segment is less than a first horizontal coordinate difference threshold, the target starting horizontal coordinate of the second text segment is determined according to the ending horizontal coordinate of the first text segment.
5. The PDF file transcription method according to claim 4, characterized in that: The method of performing splicing processing on the target object based on the preset splicing rule and the second position information to obtain the third position information of the target object further includes: Acquire a third text segment and a fourth text segment of adjacent rows, wherein the end vertical coordinate of the third text segment is smaller than the start vertical coordinate of the fourth text segment; If the absolute value of the difference between the starting horizontal coordinate of the third text segment and the starting horizontal coordinate of the fourth text segment is greater than a second horizontal coordinate difference threshold, determining a target number of spaces between the third text segment and the fourth text segment according to the starting horizontal coordinate of the third text segment, the starting horizontal coordinate of the fourth text segment and a preset width; determining a standard space width between the third text segment and the fourth text segment according to the target number of spaces and the preset width; The target starting horizontal coordinate of the fourth text segment is determined according to the starting horizontal coordinate of the third text segment and the standard space width.
6. The PDF file conversion method according to any one of claims 1 to 3, characterized in that: The method of performing splicing processing on the target object based on the preset splicing rule and the second position information to obtain the third position information of the target object further includes: When the target object is a table, obtaining multiple intersection points between multiple table horizontal lines and multiple table vertical lines; Determine a plurality of table rectangles according to a plurality of intersections between the plurality of table horizontal lines and the plurality of table vertical lines; Among the plurality of table rectangles, obtaining a first table rectangle and a second table rectangle that are adjacent to each other; When the starting ordinate of the first table rectangle is equal to the starting ordinate of the second table rectangle, the ending ordinate of the first table rectangle is equal to the ending ordinate of the second table rectangle, and the ending abscissa of the first table rectangle is equal to the starting abscissa of the second table rectangle: determining a target table according to the first table rectangle and the second table rectangle, determining a target starting abscissa of the target table according to the starting abscissa of the first table rectangle, and determining a target ending abscissa of the target table according to the ending abscissa of the second table rectangle; When the starting abscissa of the first table rectangle is equal to the starting abscissa of the second table rectangle, the ending abscissa of the first table rectangle is equal to the ending abscissa of the second table rectangle, and the ending ordinate of the first table rectangle is equal to the starting ordinate of the second table rectangle: a target table is determined based on the first table rectangle and the second table rectangle, a target starting ordinate of the target table is determined based on the starting ordinate of the first table rectangle, and a target ending ordinate of the target table is determined based on the ending ordinate of the second table rectangle.
7. A PDF file conversion device, characterized in that: The device comprises: A PDF file acquisition module, used to acquire a PDF file, identify a target object in the PDF file, and obtain first position information of the target object, wherein the target object includes at least one of the following: text, table, and image; A regularization processing module, used to regularize the first position information based on a preset regularization rule to obtain second position information of the target object; A splicing processing module, configured to perform splicing processing on the target object based on a preset splicing rule and the second position information to obtain third position information of the target object; A target file generating module, used for typeset the target object according to the third position information to generate a target file in a preset format; The step of regularizing the first position information based on a preset regularization rule to obtain the second position information of the target object includes: When the target object is text, adjacent text segments and punctuation mark segments in the same line of text are obtained, wherein the end horizontal coordinate of the text segment is smaller than the start horizontal coordinate of the punctuation mark segment; If the absolute value of the difference between the starting horizontal coordinate of the punctuation mark segment and the ending horizontal coordinate of the punctuation mark segment is not equal to the preset width, determining the target starting horizontal coordinate of the punctuation mark segment according to the first preset tolerance value, the preset width, the starting horizontal coordinate of the punctuation mark segment, the ending horizontal coordinate of the punctuation mark segment and the ending horizontal coordinate of the text segment, and determining the target ending horizontal coordinate of the punctuation mark segment according to the target starting horizontal coordinate of the punctuation mark segment and the preset width; If the absolute value of the difference between the starting vertical coordinate of the punctuation mark segment and the ending vertical coordinate of the punctuation mark segment is not equal to the preset height, the target starting vertical coordinate of the punctuation mark segment is determined according to the first preset tolerance value, the preset height, the starting vertical coordinate of the punctuation mark segment, the ending vertical coordinate of the punctuation mark segment and the starting vertical coordinate of the text segment, and the target ending vertical coordinate of the punctuation mark segment is determined according to the target starting vertical coordinate of the punctuation mark segment and the preset height.
8. A computer device comprising a memory and a processor; The memory is used to store computer programs; It is characterized in that The processor is used to execute the computer program and implement the PDF file transcription method according to any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the PDF file conversion method according to any one of claims 1 to 6 are implemented.
