Portable file format document processing method, device, electronic device and storage medium
By performing optical character recognition, coordinate conversion and character writing back on PDF documents in the form of pictures, the problem of the inability to copy, paste and select picture PDF documents is solved, and the editability and operation convenience of the document are achieved.
Patent Information
- Application Number
- CN202410578897.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-10
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2044-05-10
AI Technical Summary
PDF documents in the form of pictures cannot be copied, pasted, and selected, which causes inconvenience to users.
Through optical character recognition (OCR), PDF documents in the form of pictures are identified, coordinate information is converted, target font library is determined, and the identified characters are written back to the PDF document to form an editable document.
This allows users to easily copy, paste, and select PDF documents, improving the usability of PDF documents in picture form and the accuracy of operation results.
Smart Images

Figure CN118550891B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to a portable file format document processing method, device, electronic device and storage medium in the fields of natural language processing and computer vision. Background Art
[0002] Portable Document Format (PDF) is an electronic file format that is independent of the operating system platform. Due to its platform-independent nature, PDF documents have become an ideal document format for electronic document storage and dissemination in the years of booming mobile Internet, and have been increasingly widely used. For PDF documents in the form of images such as scanned or photocopied versions, it is usually impossible to copy, paste, or select like regular PDF documents, which brings great inconvenience to users. Summary of the invention
[0003] The present invention provides a portable file format document processing method, device, electronic device and storage medium.
[0004] A method for processing a portable document format, comprising:
[0005] Performing optical character recognition on a portable document format document in the form of an image to obtain each recognized target result and first coordinate information of each target result, wherein each target result includes: a character or a character segment consisting of at least two consecutive characters;
[0006] For each target result, convert the first coordinate information into corresponding portable file format coordinates, and use the portable file format coordinates as second coordinate information;
[0007] Determine the target character library used for writing back according to the characters in each target result;
[0008] According to the second coordinate information and the target character library, the characters in each target result are written back to the portable document format document to obtain the required target document.
[0009] A portable file format document processing device comprises: an identification module, a conversion module, a determination module and a write-back module;
[0010] The recognition module is used to perform optical character recognition on a portable document format document in the form of an image, and obtain each recognized target result and first coordinate information of each target result, wherein each target result includes: a character or a character segment consisting of at least two consecutive characters;
[0011] The conversion module is used to convert the first coordinate information into corresponding portable file format coordinates for each target result, and use the portable file format coordinates as second coordinate information;
[0012] The determination module is used to determine the target character library used for writing back according to the characters in each target result;
[0013] The write-back module is used to write back the characters in each target result to the portable document format document according to the second coordinate information and the target character library to obtain the required target document.
[0014] An electronic device, comprising:
[0015] at least one processor; and
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the method described above.
[0018] A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the method as described above.
[0019] A computer program product comprises a computer program / instruction, wherein the computer program / instruction implements the method described above when executed by a processor.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0022] Figure 1 This is a flowchart of an embodiment of the PDF document processing method disclosed in the present invention;
[0023] Figure 2 A schematic diagram of performing a swiping operation on a target document as described in the present disclosure;
[0024] Figure 3 This is a schematic diagram of the page column division described in the present disclosure;
[0025] Figure 4 This is a schematic diagram of the winding situation described in the present disclosure;
[0026] Figure 5 It is a schematic diagram of the composition structure of the first embodiment 500 of the PDF document processing device described in the present disclosure;
[0027] Figure 6 Schematic diagram of the structure of the second embodiment 600 of the PDF document processing device described in the present disclosure;
[0028] Figure 7 A schematic block diagram of an electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0029] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0030] In addition, it should be understood that the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0031] Figure 1 Flow chart of the PDF document processing method embodiment of the present disclosure. Figure 1 As shown, the following specific implementation methods are included.
[0032] In step 101, optical character recognition (OCR) is performed on a PDF document in the form of an image to obtain each recognized target result and first coordinate information of each target result. Each target result includes: a character or a character segment consisting of at least two consecutive characters.
[0033] In step 102, for each target result, the first coordinate information is converted into a corresponding PDF coordinate, and the PDF coordinate is used as the second coordinate information.
[0034] In step 103, a target character library for writing back is determined according to the characters in each target result.
[0035] In step 104, the characters in each target result are written back into the PDF document according to the second coordinate information and the target font library to obtain the desired target document.
[0036] It can be seen that by adopting the scheme described in the above method embodiment, the characters in the PDF document in the image form can be restored to the standard characters in the PDF document through operations such as OCR recognition, coordinate conversion, target font library generation and character write-back, so that the user can conveniently perform various operations on the PDF document, such as copying and pasting and selecting, thereby improving the usability of the PDF document in the image form and improving the accuracy of the operation results.
[0037] After performing OCR recognition on a PDF document, the recognized target results and the first coordinate information of each target result can be obtained. In practical applications, each target result may include only one character, which can be returned at the granularity of each character, or it may be returned in the form of character fragments. Accordingly, a line of content may return several target results. The first coordinate information refers to the coordinates returned by OCR recognition, which usually takes the upper left corner of the page as the origin. By default, the PDF document takes the lower left corner of the page as the origin, so coordinate conversion is required. In addition, the PDF document (page) itself may have rotation angles, such as 0 degrees, 90 degrees, 180 degrees, and 270 degrees, and different rotation angles may correspond to different coordinate conversion methods.
[0038] Accordingly, in some embodiments of the present disclosure, for each target result, the method of converting the first coordinate information into the corresponding PDF coordinates may include: determining the rotation angle of the PDF document, and for each target result, converting the first coordinate information into the corresponding PDF coordinates according to the coordinate conversion method corresponding to the rotation angle.
[0039] Specifically, in some embodiments of the present disclosure, for any target result, the method of converting its first coordinate information into the second coordinate information may include: in response to determining that the rotation angle is 0 degrees, using the x-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and using the difference between H and the y-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information, where H represents the page height of the PDF document; in response to determining that the rotation angle is 90 degrees, using the y-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and using the x-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information; in response to determining that the rotation angle is 180 degrees, using the difference between W and the x-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and using the y-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information, where W represents the page width of the portable document format document; in response to determining that the rotation angle is 270 degrees, using the difference between H and the y-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and using the difference between W and the x-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information.
[0040] For any target result, the first coordinate information generally includes: coordinate information of four vertices (upper left vertex, lower left vertex, upper right vertex and lower right vertex) of the rectangular box containing the target result, and the coordinate information of each vertex includes the x-axis coordinate and the y-axis coordinate.
[0041] Assume that the coordinates of the upper left vertex in the first coordinate information of a target result are (xocr, yocr), xocr represents the x-axis coordinate, yocr represents the y-axis coordinate, the page width of the PDF document is W, the page height is H, and the rotation angle is θ (which may be 0 degrees, 90 degrees, 180 degrees or 270 degrees), then the converted PDF coordinates (xpdf, ypdf) can be calculated as follows:
[0042] The rotation angle is 0 degrees (ie θ = 0 degrees):
[0043] xpdf=xocr;
[0044] ypdf=H-yocr;
[0045] The rotation angle is 90 degrees (ie θ = 90 degrees):
[0046] xpdf=yocr;
[0047] ypdf=xocr;
[0048] The rotation angle is 180 degrees (ie θ = 180 degrees):
[0049] xpdf=W-xocr;
[0050] ypdf=yocr;
[0051] The rotation angle is 270 degrees (ie θ = 270 degrees):
[0052] xpdf=H-yocr;
[0053] ypdf=W-xocr.
[0054] Among them, xpdf represents the x-axis coordinate in PDF coordinates, and ypdf represents the y-axis coordinate in PDF coordinates. It can be seen that when the rotation angle is 90 degrees and 270 degrees, the width and height of the page exchange roles when calculated.
[0055] Through the above processing, the required coordinate conversion results can be obtained efficiently and accurately, thereby improving the accuracy of subsequent character writing, etc.
[0056] In addition, the PDF format specification defines 14 standard fonts, which can be used in any PDF reader that complies with the specification. However, these 14 standard fonts are usually for non-Chinese (i.e. Western) languages, so Chinese fonts also need to be defined.
[0057] Accordingly, in some embodiments of the present disclosure, the Chinese font corresponding to the Chinese characters in each target result may be determined, and the target character library may be determined based on the Chinese font and the Chinese characters in each target result.
[0058] Specifically, in some embodiments of the present disclosure, an original character library corresponding to the Chinese font can be obtained, and the original character library can be trimmed to obtain a target character library, which is a subset of the original character library, and the target character library includes: glyph codes corresponding to all Chinese characters included in each target result.
[0059] For example, the Chinese font may be Source Han Sans, and the original font library is the open source Source Han Sans font library.
[0060] Considering that the original font library is usually large, if the original font library is used directly, it will affect the speed of subsequent character writing back, etc. Therefore, the font library can be cropped, that is, the original font library can be cropped to obtain a smaller target font library, thereby improving the speed of subsequent character writing back and improving processing efficiency, etc.
[0061] In practical applications, font processing tools (FontTools) can be introduced to achieve font library cutting with the help of FontTools. For example, the following definition can be made: subset_font(input_font_path, output_font_path, unicode_chars), where the input parameter (input_font_path) is the original font library, that is, the original font file, the output (output_font_path) is the cut target font library, and the character encoding (unicode_chars) is used to indicate which Chinese characters need to be retained in the target font library.
[0062] For example, assuming that the original character library includes glyph codes corresponding to 20,000 Chinese characters, but all the Chinese characters included in each target result are only 500 of these 20,000 Chinese characters, then a target character library corresponding to these 500 Chinese characters can be generated, and the corresponding character encoding is the character encoding of these 500 Chinese characters.
[0063] After the OCR recognition, coordinate conversion and font cropping described above, the character write-back operation can be performed, that is, the characters in each target result can be written back to the PDF document according to the second coordinate information and the target font to obtain the desired target document.
[0064] For example, the open source PDF rendering component library (PDFium) can be initialized, and subsequent operations can be completed based on PDFium, namely, opening a PDF document (the PDF document in the form of a picture as described in the present disclosure), and loading each page in the PDF document, and then writing the characters in each target result back to the corresponding page according to the second coordinate information and the target font library, and then saving the new document to obtain the desired target document.
[0065] In addition, in some embodiments of the present disclosure, after the characters in each target result are written back to the corresponding page, the object attribute of each written back character may be set to invisible (FPDF_TEXTRENDERMODE_INVISIBLE).
[0066] In this way, for the user, the PDF document seen is still the same as before being processed in the manner described in the present disclosure, but the user can perform operations such as copying and pasting, selecting, searching and retrieving like operating a regular PDF document.
[0067] Figure 2 Schematic diagram of the target document selection operation described in the present disclosure. Figure 2 As shown, users can easily select part of the content (gray part), which is very flexible and convenient.
[0068] in addition, Figure 3 This is a schematic diagram of the page column division described in the present disclosure, such as Figure 3 As shown, if the pages in the PDF document are divided into columns ( Figure 2 In the example, there are two columns in the document, and there may be more columns in the document), then OCR recognition cannot be returned in the order of the document context. For example, suppose Figure 3 The left column of the two columns shown includes 20 lines in total, and the right column also includes 20 lines. In theory, the target result corresponding to the content of the second line (line 2) in the left column should be returned after the target result corresponding to the content of the first line (line 1) in the left column is returned. However, in practice, the target result corresponding to the content of the first line in the right column may be returned. Therefore, after obtaining each target result and the first coordinate information of each target result through OCR recognition, data reorganization can be performed.
[0069] In some embodiments of the present disclosure, data reorganization refers to grouping each target result into rows to obtain grouped text rows, and grouping each text row into segments to obtain grouped text segments.
[0070] In other words, text lines and text segments can be reorganized based on the OCR recognition results, which can facilitate the user's subsequent operations. For example, when the user clicks in the target document, he can directly select a paragraph (text segment). In addition, when there are columns in the target document, if the user performs a swiping operation, different paragraphs can be better distinguished. Furthermore, when the target document is used as the data source for the input large model, the reorganized text lines and text segments can enable the large model to better understand the content of the target document, thereby making the generated answers more accurate.
[0071] The specific implementation of group row processing and group segment processing is described below.
[0072] 1) Group row processing
[0073] In some embodiments of the present disclosure, each initial row can be determined based on the first coordinate information of each target result, each initial row includes at least one target result, each target result belongs to an initial row, and for each initial row, each character in the initial row can be grouped according to the spacing between each character included therein, and then each text row can be determined according to the grouping results of each initial row.
[0074] Through the above processing, each text line can be obtained, and can be used as the basis for subsequent segmentation processing to obtain the required text segments.
[0075] In some embodiments of the present disclosure, the method for determining each initial row may include: based on the return order of each target result during OCR recognition, taking the target result returned first as the result to be processed, and performing the following first processing: adding the result to be processed to a newly created initial row; in accordance with the return order from first to last, selecting target results that meet the following requirements from the target results not added to any initial row: the difference between its y-axis coordinate and the y-axis coordinate of the result to be processed is less than a first value, and adding the selected target results to the newly created initial row, the first value is equal to the product of the character height in the result to be processed and the first coefficient, the first coefficient is greater than 0 and less than 1; taking the target result returned first among the target results not added to any initial row as the result to be processed, and repeating the first processing, wherein the first coordinate information includes the x-axis coordinate and the y-axis coordinate.
[0076] For example, assuming that there are 50 target results in total, which are numbered as target result 1 to target result 50 in the order of return, then target result 1 can be first taken as the result to be processed and added to a newly created initial row such as initial row 1. Then, target results 2 to target results 50 can be traversed in turn, and for each traversed target result, it can be determined whether it meets the requirement of "the difference between its y-axis coordinate and the y-axis coordinate of the result to be processed is less than the first value". If so, the target result can be added to initial row 1. Assuming that after the traversal is completed, target result 2 and target result 4 are added to initial row 1, then initial row 1 includes target result 1, target result 2 and target result 4. Then, the target result returned first among the target results that have not been added to any initial row can be taken as the result to be processed, that is, target result 3 can be taken as the result to be processed and added to a newly created initial row such as initial row 2. Then, target results 5 to target results 50 can be traversed in turn. Subsequent processing can refer to the above description and will not be repeated here.
[0077] Generally speaking, the character heights of the characters in the same target result are the same. In addition, the specific value of the first coefficient can be determined according to actual needs, such as 1 / 5. If the difference between the y-axis coordinate in a target result and the y-axis coordinate in the result to be processed is less than 1 / 5 of the character height in the result to be processed, the target result can be determined to be a target result that meets the requirements.
[0078] In addition, it should be noted that when determining the difference, the y-axis coordinate of the target result and the y-axis coordinate of the result to be processed need to correspond to the y-axis coordinate of the same vertex, such as both being the y-axis coordinate of the lower left vertex.
[0079] Through the above method, the preliminary classification of each target result can be achieved based on the first coordinate information of each target result, thereby laying a good foundation for subsequent processing.
[0080] Furthermore, for each initial row, the characters in the initial row may be grouped according to the spacing between the characters included therein.
[0081] In some embodiments of the present disclosure, for any initial row, in response to determining based on the first coordinate information that the character spacing between any two adjacent characters in the initial row is greater than a second value, the two adjacent characters can be used as separator characters, respectively, and the first character and the last character in the initial row can be used as separator characters, and then every two adjacent separator characters and the characters between the two adjacent separator characters can be used to form a group, respectively, and the second value is equal to the product of the average character spacing in the initial row and M, where M is a positive integer greater than one.
[0082] The two adjacent characters used as separator characters usually refer to characters located in two different target results, such as the last character in the previous target result and the first character in the next target result. The specific value of M can be determined according to actual needs, such as 3. That is, if the word spacing between two adjacent characters is greater than 3 times the average word spacing in the initial row, then the two adjacent characters can be used as separator characters.
[0083] Assuming that an initial row includes 30 characters, which are numbered from character 1 to character 30 in order from front to back, and assuming that character 1, character 10, character 11, character 16, character 17 and character 30 are all separator characters, then the following groups can be obtained: a group consisting of characters 1 to character 10, a group consisting of characters 11 to character 16, and a group consisting of characters 17 to character 30.
[0084] Through the above processing, logical grouping of each initial line can be achieved, thereby improving the efficiency of subsequent text line generation, etc.
[0085] Furthermore, each text line may be determined according to the grouping result of each initial line.
[0086] In some embodiments of the present disclosure, for any initial line, in response to determining that the initial line includes only one grouping result, the grouping result can be treated as a text line; in response to determining that the initial line includes at least two grouping results, at least one text line can be determined by analyzing the relationship between the at least two grouping results, each text line includes at least one grouping result, and each grouping result belongs to a text line.
[0087] For any initial line, if it only includes one grouping result, then the grouping result can be directly used as a text line, which is very simple and convenient. However, if it includes two or more grouping results, these grouping results need to be further analyzed in order to form one or more text lines based on these grouping results.
[0088] In some embodiments of the present disclosure, for any initial row, the first grouping result in the initial row can be used as a retained result. In response to selecting a grouping result that belongs to a different column in the page from the retained result from the grouping results other than the first grouping result, for the selected grouping results, the grouping results belonging to the same column can be used to form a text row. In response to determining that there are other grouping results, which are grouping results other than the retained results and the selected grouping results, and determining that the other grouping results and the retained results meet the content continuity requirement, the retained results and the other grouping results can be used to form a text row. In response to determining that there are no other grouping results, the retained results can be used to form a text row.
[0089] When there are columns in the page, taking two columns as an example, the y-axis coordinates of the same position in the left and right columns are usually the same or similar. For example, the y-axis coordinates of the first line in the left column and the first line in the right column are usually the same or similar, and other lines are similar. Then the target result corresponding to the first line of content in the left column and the target result corresponding to the first line of content in the right column are likely to be divided into the same initial line, but due to the large character spacing between the two columns, the target results corresponding to the two columns are usually divided into different grouping results.
[0090] In addition, assuming that a certain initial row includes three grouping results, namely grouping result 1, grouping result 2 and grouping result 3, then grouping result 1 can be used as a retained result, and grouping results belonging to different columns in the page from grouping result 1 can be determined from grouping results 2 and grouping results 3. Assuming that the page is divided into two columns, grouping result 3 belongs to the grouping result corresponding to the right column, then grouping result 3 can be used as a text line. Further, it can be determined whether grouping results 1 and grouping results 2 meet the content continuity requirement. If so, grouping results 1 and grouping results 2 can be used to form a text line. In addition, assuming that grouping results 2 and grouping results 3 both belong to the grouping results corresponding to the right column in the two columns, and grouping results 2 and grouping results 3 meet the content continuity requirement, then grouping results 2 and grouping results 3 can be used to form a text line. In this case, grouping result 1 will be used as a text line. In addition, assuming that in the three-column case, grouping results 1, grouping results 2 and grouping results 3 respectively belong to the grouping results corresponding to different columns, then grouping results 1, grouping results 2 and grouping results 3 can be used as a text line respectively.
[0091] For any initial row, there is no restriction on how to determine the grouping results corresponding to different columns. For example, considering that the x-axis coordinates of the grouping results in the same column are relatively close and are all within a certain range, the number of columns in the page and the column to which each grouping result belongs can be determined by comparing and analyzing the x-axis coordinates of the grouping results in each initial row.
[0092] In addition, there is no restriction on how to determine whether two grouping results in the same initial row meet the content continuity requirement. For example, the context semantics in the two grouping results can be analyzed to determine whether the content continuity requirement is met, or a pre-trained evaluation model can be used to score the content continuity between the two grouping results. If the score is greater than a threshold, it can be considered that the content continuity requirement is met.
[0093] Assuming that the above grouping results 1 and 2 meet the content continuity requirement, then a text line can be formed using grouping results 1 and 2. The content in a text line is divided into two or more grouping results, which is usually caused by wrapping. Figure 4 Schematic diagram of the winding situation described in the present disclosure. Figure 4 As shown, taking the second row as an example, the words "this kind of dog in the world" and "dog breed IQ ranking" are separated due to wrapping, but they actually belong to the same row. Figure 4 The pictures shown in may be pictures corresponding to "**dog breed".
[0094] After the above processing, text lines can be obtained one by one. Based on these text lines, further segmentation processing can be performed to obtain the composed text segments, thereby achieving the ultimate data reorganization purpose.
[0095] 2) Segment processing
[0096] In some embodiments of the present disclosure, the following processing can be performed for each column: sort the text lines in the column from top to bottom according to the first coordinate information, divide the text lines into at least one data block according to the line spacing between the sorted text lines, and perform paragraph recognition on each data block to obtain a recognized text segment.
[0097] For example, assuming that a column includes 30 text lines, after processing in the above manner, they may form one data block or multiple data blocks, each of which includes at least one text line, and each of the 30 text lines belongs to one data block.
[0098] It can be seen that in the above processing method, block processing can be first performed based on text lines to obtain data blocks composed of text lines, and then the required text segments can be obtained by performing paragraph recognition on the data blocks, thereby improving the processing efficiency and improving the accuracy of the processing results through multi-step processing.
[0099] In some embodiments of the present disclosure, the method of dividing each text line into at least one data block may include: taking the text line that is at the first position after sorting as the text line to be processed, and performing the following second processing: in response to determining that at least three consecutive text lines starting from the text line to be processed meet the following conditions: the line spacing between every two adjacent text lines is the same, using the at least three consecutive text lines to form a data block, and taking the first text line after the data block as the text line to be processed, and repeating the second processing; otherwise, marking the text line to be processed as a reserved text line, and taking the first text line after the reserved text line as the text line to be processed, and repeating the second processing; further, in response to determining that all text lines have been processed, the completed processing includes: being formed into data blocks or being marked as reserved text lines, and using the reserved text lines between every two adjacent data blocks to form a data block.
[0100] For example, assuming that a column includes 30 text lines, which are text line 1 to text line 30 in order from top to bottom, then text line 1 can be first used as the text line to be processed, and assuming that the line spacing between every two adjacent text lines from text line 1 to text line 4 is the same, then these four text lines can be used to form a data block, then text line 5 can be used as the text line to be processed, and assuming that text line 5 is marked as a reserved text line, then text line 6 can be used as the text line to be processed, and assuming that text line 6 is also marked as a reserved text line, then text line 7 can be used as the text line to be processed. lines, and assuming that the line spacing between every two adjacent text lines from text line 7 to text line 14 is the same, then these 8 text lines can be used to form a data block. Further, assuming that text line 15 is marked as a reserved text line, and assuming that text lines 16 to text lines 30 form a data block, then a total of 5 data blocks can be obtained, namely data block 1 composed of text lines 1 to text lines 4, data block 2 composed of text lines 5 to text lines 6, data block 3 composed of text lines 7 to text lines 14, data block 4 composed of text lines 15, and data block 5 composed of text lines 16 to text lines 30.
[0101] For each data block, paragraph recognition can be performed on it respectively to obtain the recognized text segment. In some embodiments of the present disclosure, for any data block, the first text line in the data block can be used as the text line to be recognized and the paragraph head text line, and the following third processing is performed: the paragraph end recognition is performed on the text line to be recognized; in response to determining that the text line to be recognized is recognized as a non-paragraph end text line, the next text line adjacent to the text line to be recognized is used as the text line to be recognized, and the third processing is repeated; in response to determining that the text line to be recognized is recognized as a paragraph end text line, a text segment is formed using text lines starting from the paragraph head text line to the paragraph end text line, and the next text line adjacent to the text line to be recognized is used as the text line to be recognized and the paragraph head text line, and the third processing is repeated.
[0102] For example, assuming that a data block includes 15 text lines, namely text line 1 to text line 15, first take text line 1 as the first text line of the paragraph. Assuming that text line 1 is also recognized as the last text line of the paragraph, then text line 1 can be used to form a text segment. Afterwards, assuming that text line 7 is recognized as the last text line of the paragraph, then text line 2 to text line 7 can be used to form a text segment. Afterwards, assuming that text line 15 is recognized as the last text line of the paragraph, then text lines 8 to text lines 15 can be used to form a text segment.
[0103] Through the above processing, each data block can be divided into one or more text segments, thereby completing the data reorganization process, and then based on the data reorganization results, it can better support the user's operation on the target document and enable the large model to better understand the content in the target document.
[0104] In some embodiments of the present disclosure, the method of performing paragraph end recognition on a text line to be recognized may include one of the following or any combination: 1) in response to determining that the distance between the last character of the text line to be recognized and the right side line of the page is greater than a first threshold, determining the text line to be recognized as a paragraph end text line; 2) in response to determining that the last character of the text line to be recognized is a predetermined terminator, determining the text line to be recognized as a paragraph end text line; 3) performing paragraph beginning recognition on the next text line adjacent to the text line to be recognized, and in response to determining that the next adjacent text line is recognized as a paragraph beginning text line, determining the text line to be recognized as a paragraph end text line.
[0105] In actual applications, when the text line to be recognized is identified as the end of a paragraph by any of the above methods 1), 2) and 3), the text line to be recognized is finally determined to be the end of a paragraph. Alternatively, when the text line to be recognized is identified as the end of a paragraph by any two of the methods, the text line to be recognized is finally determined to be the end of a paragraph. Alternatively, when the text line to be recognized is identified as the end of a paragraph by all three methods, the text line to be recognized is finally determined to be the end of a paragraph. This is very flexible and convenient.
[0106] Among them, method 1) adopts a position judgment method. Compared with each non-paragraph end text line, the distance between the last character in the paragraph end text and the right line of the page is usually larger. Therefore, by reasonably setting the value of the first threshold and comparing the distance with the first threshold, it can be determined whether the text line to be identified is a paragraph end text line.
[0107] Method 2) uses a punctuation judgment method. If the last character of the text line to be recognized is determined to be a terminator, such as a period, question mark, exclamation mark or other terminator, the text line to be recognized can be determined as a paragraph end text line.
[0108] Method 3) adopts a context judgment method. If it is determined that the next text line adjacent to the text line to be recognized is a paragraph head text line, then the text line to be recognized can be determined as a paragraph end text line.
[0109] Preferably, two or all of the above three methods may be combined to finally determine whether the text line to be identified is a paragraph end text line, so as to improve the accuracy of the processing result.
[0110] In some embodiments of the present disclosure, the method of identifying the beginning of a paragraph for any text line may include one of the following or any combination: 1) in response to determining that the text line has a first-word indent, determining the text line as a paragraph-beginning text line; 2) in response to determining that the difference between the character height in the text line and the character height in the adjacent previous text line is greater than a second threshold, determining the text line as a paragraph-beginning text line; 3) in response to determining that the difference between the first line spacing and the second line spacing is greater than a third threshold, determining the text line as a paragraph-beginning text line, the first line spacing being the line spacing between the text line and the adjacent previous text line, and the second line spacing being the line spacing between the text line and the adjacent next text line.
[0111] In actual applications, for any text line, when any of the above methods 1), 2) and 3) is used to identify the text line as the beginning of a paragraph, the text line can be finally determined to be the beginning of a paragraph. Alternatively, when any two of the methods are used to identify the text line as the beginning of a paragraph, the text line can be finally determined to be the beginning of a paragraph. Alternatively, when all three methods are used to identify the text line as the beginning of a paragraph, the text line can be finally determined to be the beginning of a paragraph. This is very flexible and convenient.
[0112] Among them, method 1) adopts the first word indentation judgment method. If it is determined that compared with other text lines, the text line has an obvious first word indentation, then the text line can be determined as the first text line of the paragraph.
[0113] Method 2) uses a character height judgment method. Generally speaking, the character heights in each text line in the same paragraph are the same or have very small differences. Therefore, if it is determined that the difference between the character height in the text line and the character height in the adjacent previous text line is greater than the second threshold, then the text line can be determined as the paragraph head text line. The specific value of the second threshold can be determined according to actual needs.
[0114] Method 3) adopts the line spacing judgment method. Generally speaking, the line spacing between text lines in the same paragraph is the same or the difference is very small. Therefore, if it is determined that the difference between the first line spacing between the text line and the adjacent previous text line and the second line spacing between the text line and the adjacent next text line is greater than the third threshold, then the text line can be determined as the paragraph head text line. The specific value of the third threshold can be determined according to actual needs.
[0115] Preferably, two or all of the above three methods may be combined to finally determine whether the text line is a paragraph start text line, so as to improve the accuracy of the processing result.
[0116] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are expressed as a series of action combinations, but those skilled in the art should be aware that the present disclosure is not limited by the described order of actions, because according to the present disclosure, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present disclosure.
[0117] The above is an introduction to the method embodiment. The following is a further explanation of the scheme disclosed in the present invention through an apparatus embodiment.
[0118] Figure 5 FIG. 5 is a schematic diagram of the structure of the first embodiment 500 of the PDF document processing device described in the present disclosure. Figure 5 As shown, it includes: an identification module 501, a conversion module 502, a determination module 503 and a write-back module 504.
[0119] The recognition module 501 is used to perform OCR recognition on the PDF document in the form of an image, and obtain each recognized target result and the first coordinate information of each target result. Each target result includes: a character or a character segment composed of at least two consecutive characters.
[0120] The conversion module 502 is used to convert the first coordinate information into corresponding PDF coordinates for each target result, and use the PDF coordinates as the second coordinate information.
[0121] The determination module 503 is used to determine the target character library used for writing back according to the characters in each target result.
[0122] The writing-back module 504 is used to write the characters in each target result back to the PDF document according to the second coordinate information and the target font library to obtain the required target document.
[0123] By adopting the scheme described in the above-mentioned device embodiment, the characters in the PDF document in the image form can be restored to the standard characters in the PDF document through operations such as OCR recognition, coordinate conversion, target font library generation and character write-back, so that the user can conveniently perform various operations on the PDF document, such as copying and pasting and selecting, thereby improving the usability of the PDF document in the image form and improving the accuracy of the operation results.
[0124] After the recognition module 501 performs OCR recognition on the PDF document in the form of an image and obtains each recognized target result and the first coordinate information of each target result, the conversion module 502 can convert the first coordinate information into corresponding PDF coordinates for each target result, and can use the PDF coordinates as second coordinate information.
[0125] In some embodiments of the present disclosure, the conversion module 502 may convert the first coordinate information into corresponding PDF coordinates for each target result, which may include: determining the rotation angle of the PDF document, and converting the first coordinate information into corresponding PDF coordinates for each target result according to the coordinate conversion method corresponding to the rotation angle.
[0126] Specifically, in some embodiments of the present disclosure, the conversion module 502 converts the first coordinate information of any target result into the second coordinate information in a manner that may include: in response to determining that the rotation angle is 0 degrees, taking the x-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and taking the difference between H and the y-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information, where H represents the page height of the PDF document; in response to determining that the rotation angle is 90 degrees, taking the y-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and taking the x-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information; in response to determining that the rotation angle is 180 degrees, taking the difference between W and the x-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and taking the y-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information, where W represents the page width of the portable document format document; in response to determining that the rotation angle is 270 degrees, taking the difference between H and the y-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and taking the difference between W and the x-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information.
[0127] In addition, the determination module 503 can determine the target font library used for writing back according to the characters in each target result. In some embodiments of the present disclosure, the determination module 503 can determine the Chinese font corresponding to the Chinese characters in each target result, and can determine the target font library according to the Chinese font and the Chinese characters in each target result.
[0128] Specifically, in some embodiments of the present disclosure, the determination module 503 can obtain the original character library corresponding to the Chinese font, and can crop the original character library to obtain a target character library, which is a subset of the original character library, and the target character library includes: the glyph codes corresponding to all Chinese characters included in each target result.
[0129] Furthermore, the writing-back module 504 may write back the characters in each target result into the PDF document according to the second coordinate information and the target character library to obtain the desired target document.
[0130] In some embodiments of the present disclosure, after the write-back module 504 writes back the characters in each target result to the corresponding page, the object attribute of each written-back character may be set to be invisible.
[0131] Figure 6 FIG. 6 is a schematic diagram of the structure of the second embodiment 600 of the PDF document processing device described in the present disclosure. Figure 6 As shown, it includes: an identification module 501, a conversion module 502, a determination module 503, a write-back module 504 and a reorganization module 505.
[0132] The identification module 501, the conversion module 502, the determination module 503 and the write-back module 504 are Figure 5 The same is true in the illustrated embodiment and will not be described in detail.
[0133] The reorganization module 505 is used to group the target results into lines after the target results are identified to obtain grouped text lines, and to group the text lines into segments to obtain grouped text segments.
[0134] In some embodiments of the present disclosure, the reorganization module 505 can determine each initial row based on the first coordinate information of each target result, each initial row includes at least one target result, each target result belongs to an initial row, and for each initial row, the characters in the initial row can be grouped according to the character spacing of each character included therein, and then each text row can be determined according to the grouping results of each initial row.
[0135] In some embodiments of the present disclosure, the manner in which the reorganization module 505 determines each initial row may include: based on the return order of each target result during OCR recognition, taking the target result returned first as the result to be processed, and performing the following first processing: adding the result to be processed to a newly created initial row; in accordance with the return order from first to last, selecting target results that meet the following requirements from the target results not added to any initial row: the difference between its y-axis coordinate and the y-axis coordinate of the result to be processed is less than a first value, and adding the selected target results to the newly created initial row, the first value is equal to the product of the character height in the result to be processed and the first coefficient, the first coefficient is greater than 0 and less than 1; taking the target result returned first among the target results not added to any initial row as the result to be processed, and repeating the first processing, wherein the first coordinate information includes the x-axis coordinate and the y-axis coordinate.
[0136] Further, for each initial row, the reorganization module 505 may group the characters in the initial row according to the character spacing of the characters included therein. In some embodiments of the present disclosure, for any initial row, in response to determining that the character spacing between any two adjacent characters in the initial row is greater than a second value according to the first coordinate information, the reorganization module 505 may use the two adjacent characters as separator characters respectively, and may use the first character and the last character in the initial row as separator characters, and then may use each two adjacent separator characters and the characters between the two adjacent separator characters to form a group, respectively, and the second value is equal to the product of the average character spacing in the initial row and M, where M is a positive integer greater than one.
[0137] The reorganization module 505 may also determine each text line according to the grouping results of each initial line. In some embodiments of the present disclosure, for any initial line, in response to determining that the initial line includes only one grouping result, the reorganization module 505 may treat the grouping result as a text line, and in response to determining that the initial line includes at least two grouping results, at least one text line may be determined by analyzing the relationship between the at least two grouping results, each text line includes at least one grouping result, and each grouping result belongs to a text line.
[0138] In some embodiments of the present disclosure, the reorganization module 505 may, for any initial row, use the first grouping result in the initial row as the retained result; in response to selecting a grouping result that belongs to a different column in the page from the retained result from the grouping results other than the first grouping result, for the selected grouping results, use the grouping results that belong to the same column to form a text row; in response to determining that there are other grouping results, which are grouping results other than the retained results and the selected grouping results, and determining that the other grouping results meet the content continuity requirement with the retained results, use the retained results and the other grouping results to form a text row; in response to determining that there are no other grouping results, use the retained results to form a text row.
[0139] In some embodiments of the present disclosure, the reorganization module 505 may also perform the following processing for each column: sort the text lines in the column from top to bottom according to the first coordinate information, divide the text lines into at least one data block according to the line spacing between the sorted text lines, and perform paragraph recognition on each data block to obtain recognized text segments.
[0140] In some embodiments of the present disclosure, the way in which the reorganization module 505 divides each text line into at least one data block may include: taking the text line that is at the first position after sorting as the text line to be processed, and performing the following second processing: in response to determining that at least three consecutive text lines starting from the text line to be processed meet the following conditions: the line spacing between every two adjacent text lines is the same, using the at least three consecutive text lines to form a data block, and taking the first text line after the data block as the text line to be processed, and repeating the second processing; otherwise, marking the text line to be processed as a reserved text line, and taking the first text line after the reserved text line as the text line to be processed, and repeating the second processing; further, in response to determining that all text lines have been processed, the completed processing includes: being formed into data blocks or being marked as reserved text lines, and using the reserved text lines between every two adjacent data blocks to form a data block.
[0141] For each data block, the reorganization module 505 can also perform paragraph recognition on it respectively to obtain the recognized text segment. In some embodiments of the present disclosure, for any data block, the reorganization module 505 can use the first text line in the data block as the text line to be recognized and the paragraph head text line, and can perform the following third processing: perform paragraph end recognition on the text line to be recognized; in response to determining that the text line to be recognized is recognized as a non-paragraph end text line, use the next text line adjacent to the text line to be recognized as the text line to be recognized, and repeat the third processing; in response to determining that the text line to be recognized is recognized as a paragraph end text line, use the text lines starting from the paragraph head text line to the paragraph end text line to form a text segment, and use the next text line adjacent to the text line to be recognized as the text line to be recognized and the paragraph head text line, and repeat the third processing.
[0142] In some embodiments of the present disclosure, the way in which the reorganization module 505 performs paragraph end recognition on the text line to be recognized may include one of the following or any combination: in response to determining that the distance between the last character of the text line to be recognized and the right side line of the page is greater than a first threshold, the text line to be recognized is determined as a paragraph end text line; in response to determining that the last character of the text line to be recognized is a predetermined terminator, the text line to be recognized is determined as a paragraph end text line; performing paragraph beginning recognition on the next text line adjacent to the text line to be recognized, and in response to determining that the next adjacent text line is recognized as a paragraph beginning text line, determining the text line to be recognized as a paragraph end text line.
[0143] In addition, in some embodiments of the present disclosure, the way in which the reorganization module 505 identifies the beginning of a paragraph for any text line may include one of the following or any combination: in response to determining that the text line has a first-word indent, determining the text line as a paragraph-beginning text line; in response to determining that the difference between the character height in the text line and the character height in the adjacent previous text line is greater than a second threshold, determining the text line as a paragraph-beginning text line; in response to determining that the difference between the first line spacing and the second line spacing is greater than a third threshold, determining the text line as a paragraph-beginning text line, the first line spacing being the line spacing between the text line and the adjacent previous text line, and the second line spacing being the line spacing between the text line and the adjacent next text line.
[0144] Figure 5 and Figure 6 The specific working process of the illustrated device embodiment can refer to the relevant description in the aforementioned method embodiment and will not be described in detail.
[0145] The scheme disclosed in the present invention can be applied to the field of artificial intelligence, especially to the fields of natural language processing and computer vision. Artificial intelligence is a discipline that studies how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It has both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing. Artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0146] In addition, the PDF documents and the like in the embodiments described in this disclosure are not intended for a specific user and do not reflect the personal information of a specific user. In the technical solution of this disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good customs.
[0147] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0148] Figure 7 A schematic block diagram of an electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0149] like Figure 7 As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0150] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0151] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above, such as the methods described in the present disclosure. For example, in some embodiments, the methods described in the present disclosure may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of the method described in the present disclosure may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to perform the method described in the present disclosure in any other appropriate manner (e.g., by means of firmware).
[0152] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0153] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0154] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0155] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0156] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0157] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0158] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0159] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for processing a portable document format, comprising: Performing optical character recognition on a portable document format document in the form of an image to obtain each recognized target result and first coordinate information of each target result, wherein each target result includes: a character or a character segment consisting of at least two consecutive characters; For each target result, convert the first coordinate information into corresponding portable file format coordinates, and use the portable file format coordinates as second coordinate information; Determining a target font library for writing back according to the characters in each target result, including: determining a Chinese font corresponding to the Chinese characters in each target result; obtaining an original font library corresponding to the Chinese font; using a font processing tool to cut the original font library to obtain the target font library, the target font library is a subset of the original font library, and the target font library includes: glyph codes corresponding to all Chinese characters included in each target result; According to the second coordinate information and the target character library, the characters in each target result are written back to the portable document format document to obtain the required target document.
2. The method according to claim 1, wherein: The converting the first coordinate information into corresponding portable file format coordinates for each target result includes: Determining a rotation angle of the portable document format document; For each target result, the first coordinate information is converted into corresponding portable file format coordinates according to the coordinate conversion method corresponding to the rotation angle.
3. The method according to claim 2, wherein: The step of converting the first coordinate information into corresponding portable file format coordinates according to the coordinate conversion method corresponding to the rotation angle includes: In response to determining that the rotation angle is 0 degrees, taking the x-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and taking the difference between H and the y-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information, where H represents the page height of the portable document format document; In response to determining that the rotation angle is 90 degrees, using the y-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and using the x-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information; In response to determining that the rotation angle is 180 degrees, taking the difference between W and the x-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and taking the y-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information, W representing the page width of the portable document format document; In response to determining that the rotation angle is 270 degrees, the difference between H and the y-axis coordinate in the first coordinate information is used as the x-axis coordinate in the second coordinate information, and the difference between W and the x-axis coordinate in the first coordinate information is used as the y-axis coordinate in the second coordinate information.
4. The method according to claim 1, further comprising: After writing back the characters in each target result to the portable document format document, the object attribute of each written back character is set to be invisible.
5. The method according to any one of claims 1 to 4, further comprising: After obtaining the identified target results and the first coordinate information of each target result, each target result is grouped into rows to obtain grouped text rows, and each text row is grouped into segments to obtain grouped text segments.
6. The method according to claim 5, wherein: The target results are grouped to obtain text lines including: Based on the first coordinate information of each target result, initial rows are determined, each initial row includes at least one target result, and each target result belongs to an initial row; For each initial row, grouping the characters in the initial row according to the spacing between the characters included therein; Each text line is determined according to the grouping result of each initial line.
7. The method according to claim 6, wherein: The determining of each initial row based on the first coordinate information of each target result includes: Based on the return order of each target result during the optical character recognition, the target result returned first is used as the result to be processed, and the following first processing is performed: the result to be processed is added to a newly created initial row; in accordance with the return order from first to last, target results that meet the following requirements are selected in sequence from the target results not added to any initial row: the difference between its y-axis coordinate and the y-axis coordinate of the result to be processed is less than a first value, and the selected target results are added to the newly created initial row, the first value is equal to the product of the character height in the result to be processed and a first coefficient, the first coefficient is greater than 0 and less than 1; the target result returned first among the target results not added to any initial row is used as the result to be processed, and the first processing is repeated, wherein the first coordinate information includes an x-axis coordinate and a y-axis coordinate.
8. The method according to claim 6, wherein: For each initial row, grouping the characters in the initial row according to the spacing between the characters respectively comprises: For any initial row, in response to determining according to the first coordinate information that the character spacing between any two adjacent characters in the initial row is greater than a second value, the two adjacent characters are used as separator characters respectively, and the first character and the last character in the initial row are used as the separator characters, and every two adjacent separator characters and the characters between two adjacent separator characters are used to form a group, and the second value is equal to the product of the average character spacing in the initial row and M, where M is a positive integer greater than one.
9. The method according to claim 6, wherein: Determining each text line according to the grouping results of each initial line includes: For any initial line, in response to determining that the initial line includes only one grouping result, treating the grouping result as a text line; In response to determining that the initial row includes at least two grouping results, at least one text row is determined by analyzing the relationship between the at least two grouping results, each text row includes at least one grouping result, and each grouping result belongs to a text row.
10. The method according to claim 9, wherein: The determining, by analyzing the relationship between the at least two grouping results, at least one text line comprises: The first grouping result in the initial row is used as the retained result; In response to selecting a group result belonging to a different column in the page from the retained result from the group results other than the first group result, for the selected group results, using the group results belonging to the same column to form a text line; In response to determining that there are other grouping results, the other grouping results are grouping results other than the retained results and the selected grouping results, and determining that the other grouping results and the retained results meet the content continuity requirements, the retained results and the other grouping results are used to form a text line; in response to determining that there are no other grouping results, the retained results are used to form a text line.
11. The method according to claim 10, wherein: The text lines are grouped into segments to obtain the following text segments: For each column, the following processing is performed respectively: according to the first coordinate information, the text lines in the column are sorted in order from top to bottom; according to the line spacing between the sorted text lines, each text line is divided into at least one data block; for each data block, paragraph recognition is performed respectively, and an identified text segment is obtained.
12. The method according to claim 11, wherein: The dividing each text line into at least one data block comprises: The text line that is at the first position after sorting is used as the text line to be processed, and the following second processing is performed: in response to determining that at least three consecutive text lines starting from the text line to be processed meet the following conditions: the line spacing between every two adjacent text lines is the same, the at least three consecutive text lines are used to form a data block, and the first text line after the data block is used as the text line to be processed, and the second processing is repeatedly performed; otherwise, the text line to be processed is marked as a reserved text line, and the first text line after the reserved text line is used as the text line to be processed, and the second processing is repeatedly performed; In response to determining that all text lines have completed processing, the completed processing includes: being formed into data blocks or being marked as the reserved text lines, and forming a data block using the reserved text lines located between every two adjacent data blocks.
13. The method according to claim 11, wherein: For each data block, paragraph recognition is performed on it respectively, and the recognized text segments include: The first text line in the data block is used as the text line to be recognized and the beginning text line of a paragraph, and the following third processing is performed: the end of the paragraph is recognized for the text line to be recognized; in response to determining that the text line to be recognized is recognized as a non-end of paragraph text line, the next text line adjacent to the text line to be recognized is used as the text line to be recognized, and the third processing is repeated; in response to determining that the text line to be recognized is recognized as the end of paragraph text line, a text segment is formed using text lines starting from the beginning text line of the paragraph and ending at the end text line of the paragraph, and the next text line adjacent to the text line to be recognized is used as the text line to be recognized and the beginning text line of the paragraph, and the third processing is repeated.
14. The method according to claim 13, wherein: The step of identifying the end of the text line to be identified includes one or any combination of the following: In response to determining that the distance between the last character of the to-be-recognized text line and the right line of the page is greater than a first threshold, determining the to-be-recognized text line as the paragraph end text line; In response to determining that the last character of the text line to be recognized is a predetermined end character, determining the text line to be recognized as the paragraph end text line; The next text line adjacent to the text line to be recognized is recognized as a paragraph start text line, and in response to determining that the next adjacent text line is recognized as a paragraph start text line, the text line to be recognized is determined as the paragraph end text line.
15. The method according to claim 14, wherein: The methods for identifying the beginning of a paragraph of any text line include one or any combination of the following: In response to determining that the text line has a first word indent, determining the text line as the paragraph head text line; In response to determining that the difference between the height of characters in the text line and the height of characters in an adjacent previous text line is greater than a second threshold, determining the text line as the paragraph head text line; In response to determining that the difference between the first line spacing and the second line spacing is greater than a third threshold, the text line is determined to be the paragraph head text line, the first line spacing being the line spacing between the text line and an adjacent previous text line, and the second line spacing being the line spacing between the text line and an adjacent next text line.
16. A portable file format document processing device, comprising: Recognition module, conversion module, determination module and write-back module; The recognition module is used to perform optical character recognition on a portable document format document in the form of an image, and obtain each recognized target result and first coordinate information of each target result, wherein each target result includes: a character or a character segment consisting of at least two consecutive characters; The conversion module is used to convert the first coordinate information into corresponding portable file format coordinates for each target result, and use the portable file format coordinates as second coordinate information; The determination module is used to determine the target character library used for writing back according to the characters in each target result, including: determining the Chinese font corresponding to the Chinese characters in each target result; obtaining the original character library corresponding to the Chinese font; using a font processing tool to cut the original character library to obtain the target character library, the target character library is a subset of the original character library, and the target character library includes: glyph codes corresponding to all Chinese characters included in each target result; The write-back module is used to write back the characters in each target result to the portable document format document according to the second coordinate information and the target character library to obtain the required target document.
17. The device according to claim 16, wherein: The conversion module determines the rotation angle of the portable document format document, and for each target result, converts the first coordinate information into corresponding portable document format coordinates according to the coordinate conversion method corresponding to the rotation angle.
18. The device according to claim 17, wherein: In response to determining that the rotation angle is 0 degrees, the conversion module uses the x-axis coordinate in the first coordinate information as the x-axis coordinate in the second coordinate information, and uses the difference between H and the y-axis coordinate in the first coordinate information as the y-axis coordinate in the second coordinate information, where H represents the page height of the portable document format document. In response to determining that the rotation angle is 90 degrees, the y-axis coordinate in the first coordinate information is used as the x-axis coordinate in the second coordinate information, and the x-axis coordinate in the first coordinate information is used as the y-axis coordinate in the second coordinate information. In response to determining that the rotation angle is 180 degrees, the difference between W and the x-axis coordinate in the first coordinate information is used as the x-axis coordinate in the second coordinate information, and the y-axis coordinate in the first coordinate information is used as the y-axis coordinate in the second coordinate information, where W represents the page width of the portable document format document. In response to determining that the rotation angle is 270 degrees, the difference between H and the y-axis coordinate in the first coordinate information is used as the x-axis coordinate in the second coordinate information, and the difference between W and the x-axis coordinate in the first coordinate information is used as the y-axis coordinate in the second coordinate information.
19. The device according to claim 16, wherein: The write-back module is further used for setting the object attributes of each written-back character to be invisible after writing the characters in each target result back to the portable document format document.
20. The device according to any one of claims 16 to 19, further comprising: The reorganization module is used to group the target results into lines to obtain the composed text lines, and to group the text lines into segments to obtain the composed text segments.
21. The device according to claim 20, wherein: The reorganization module determines each initial row based on the first coordinate information of each target result, each initial row includes at least one target result, each target result belongs to an initial row, and for each initial row, the characters in the initial row are grouped according to the character spacing of each character included therein, and each text row is determined according to the grouping results of each initial row.
22. The device according to claim 21, wherein The reorganization module takes the first returned target result as the result to be processed based on the return order of each target result during the optical character recognition, and performs the following first processing: adding the result to be processed to a newly created initial row; In the order of return from first to last, target results that meet the following requirements are selected from the target results that have not been added to any initial row: the difference between their y-axis coordinates and the y-axis coordinates of the result to be processed is less than a first value, and the selected target results are added to the newly created initial row, the first value is equal to the product of the character height in the result to be processed and a first coefficient, and the first coefficient is greater than 0 and less than 1; the target result that is returned first among the target results that have not been added to any initial row is used as the result to be processed, and the first processing is repeated, wherein the first coordinate information includes x-axis coordinates and y-axis coordinates.
23. The device according to claim 21, wherein For any initial row, in response to determining according to the first coordinate information that the word spacing between any two adjacent characters in the initial row is greater than a second value, the reorganization module uses the two adjacent characters as separator characters respectively, and uses the first character and the last character in the initial row as the separator characters, and uses every two adjacent separator characters and the characters between the two adjacent separator characters to form a group, wherein the second value is equal to the product of the average word spacing in the initial row and M, where M is a positive integer greater than one.
24. The device according to claim 21, wherein For any initial line, in response to determining that the initial line includes only one grouping result, the reorganization module treats the grouping result as a text line; in response to determining that the initial line includes at least two grouping results, at least one text line is determined by analyzing the relationship between the at least two grouping results, each text line includes at least one grouping result, and each grouping result belongs to a text line.
25. The device according to claim 24, wherein: In response to determining that the initial row includes at least two grouping results, the reorganization module uses the first grouping result in the initial row as the retained result; in response to selecting a grouping result that belongs to a different column in the page from the retained result from the grouping results other than the first grouping result, for the selected grouping results, respectively use the grouping results belonging to the same column to form a text row; in response to determining that there are other grouping results, the other grouping results are grouping results other than the retained result and the selected grouping results, and determining that the other grouping results and the retained result meet the content continuity requirements, use the retained result and the other grouping results to form a text row; in response to determining that the other grouping results do not exist, use the retained results to form a text row.
26. The device according to claim 25, wherein The reorganization module performs the following processing for each column: sorts the text lines in the column from top to bottom according to the first coordinate information, divides the text lines into at least one data block according to the line spacing between the sorted text lines, and performs paragraph recognition on each data block to obtain recognized text segments.
27. The device according to claim 26, wherein: The reorganization module uses the text line that is at the first position after sorting as the text line to be processed, and performs the following second processing: in response to determining that at least three consecutive text lines starting from the text line to be processed meet the following conditions: the line spacing between every two adjacent text lines is the same, the at least three consecutive text lines are used to form a data block, and the first text line after the data block is used as the text line to be processed, and the second processing is repeatedly performed; otherwise, the text line to be processed is marked as a reserved text line, and the first text line after the reserved text line is used as the text line to be processed, and the second processing is repeatedly performed; In response to determining that all text lines have completed processing, the completed processing includes: being formed into data blocks or being marked as the reserved text lines, and forming a data block using the reserved text lines located between every two adjacent data blocks.
28. The device according to claim 26, wherein For any data block, the reorganization module takes the first text line in the data block as the text line to be recognized and the paragraph start text line, and performs the following third processing: performing paragraph end recognition on the text line to be recognized; in response to determining that the text line to be recognized is recognized as a non-paragraph end text line, taking the next text line adjacent to the text line to be recognized as the text line to be recognized, and repeating the third processing; in response to determining that the text line to be recognized is recognized as a paragraph end text line, using the text lines starting from the paragraph start text line and ending at the paragraph end text line to form a text segment, taking the next text line adjacent to the text line to be recognized as the text line to be recognized and the paragraph start text line, and repeating the third processing.
29. The device according to claim 28, wherein The manner in which the reorganization module performs paragraph end recognition on the text line to be recognized includes one of the following or any combination: in response to determining that the distance between the last character of the text line to be recognized and the right side line of the page is greater than a first threshold, determining the text line to be recognized as the paragraph end text line; in response to determining that the last character of the text line to be recognized is a predetermined terminator, determining the text line to be recognized as the paragraph end text line; performing paragraph beginning recognition on the next text line adjacent to the text line to be recognized, and in response to determining that the next adjacent text line is recognized as a paragraph beginning text line, determining the text line to be recognized as the paragraph end text line.
30. The device according to claim 29, wherein: The manner in which the reorganization module identifies the beginning of a paragraph for any text line includes one of the following or any combination: in response to determining that the text line has a first word indent, determining the text line as the beginning of a paragraph; in response to determining that the difference between the character height in the text line and the character height in an adjacent previous text line is greater than a second threshold, determining the text line as the beginning of a paragraph; in response to determining that the difference between a first line spacing and a second line spacing is greater than a third threshold, determining the text line as the beginning of a paragraph, the first line spacing being the line spacing between the text line and the adjacent previous text line, and the second line spacing being the line spacing between the text line and the adjacent next text line.
31. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 15.
32. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to make a computer execute the method according to any one of claims 1 to 15.
33. A computer program product, comprising a computer program / instructions, which implement the method according to any one of claims 1 to 15 when executed by a processor.
Citation Information
Patent Citations
Construction method and construction device of double-layer portable document format (PDF) file
CN102968407A