Document processing method and apparatus, device, and storage medium
By obtaining the drawing instruction set of the target document to determine character style information and generating structured data, the problem of slow OCR processing speed is solved, and document processing efficiency is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING QIHOOD TECHNOLOGY CO LTD
- Filing Date
- 2024-12-17
- Publication Date
- 2026-06-19
AI Technical Summary
Existing technologies are slow in OCR processing when handling documents that cannot be edited online, such as PDF documents, which affects document processing efficiency.
By acquiring the drawing instruction set of the target document, the style information of each character in the document is determined, and structured data is generated based on this style information, avoiding complex pattern matching and algorithm calculation processing.
It improves document processing speed and efficiency, and enables the rapid generation of structured data.
Smart Images

Figure CN122242442A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a document processing method, apparatus, device, and storage medium. Background Technology
[0002] By recognizing text styles in a document, such as bold, highlighting, and italics, information of varying importance can be distinguished, helping users to identify and understand key content more quickly.
[0003] Currently, for documents that do not support online editing, such as PDF documents, image documents, and scanned documents, Optical Character Recognition (OCR) is generally used to process these documents, outputting structured data composed of text patterns to facilitate online editing of key content. However, OCR processing involves complex pattern matching and algorithm calculations. If hardware resources are insufficient, the processing speed will be relatively slow, affecting document processing efficiency.
[0004] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention
[0005] The main purpose of this application is to provide a document processing method, apparatus, device, and storage medium, which aims to solve the technical problem that the processing speed of the prior art is relatively slow, affecting the efficiency of document processing.
[0006] To achieve the above objectives, this application provides a document processing method, the method comprising:
[0007] Obtain the drawing instruction set of the target document;
[0008] The style information of each character in the target document is determined according to the drawing instruction set;
[0009] The structured data corresponding to the target document is generated based on the style information described above.
[0010] In one embodiment, the target document is a target PDF document, and the step of determining the style information of each character in the target document according to the drawing instruction set includes:
[0011] The color information of each character in the target PDF document is determined according to the drawing instruction set;
[0012] The font information of each character is determined by a preset parsing library;
[0013] The color information and font information are obtained as the style information of each character.
[0014] In one embodiment, the step of determining the color information of each character in the target PDF document according to the drawing instruction set includes:
[0015] Obtain the color instructions from the drawing instruction set;
[0016] The color value corresponding to each character is determined according to the color instruction;
[0017] Obtain each of the aforementioned color values as the color information of the corresponding character.
[0018] In one embodiment, the step of generating structured data corresponding to the target document based on each of the style information includes:
[0019] Obtain the text instructions from the drawing instruction set;
[0020] Determine a character array containing each of the characters in the target PDF document based on the text instructions;
[0021] The corresponding color information and font information are configured for each character in the character array to obtain the structured data of the target PDF document.
[0022] In one embodiment, the step of determining a character array containing each character in the target PDF document based on the text instruction includes:
[0023] Retrieve each character from the target PDF document according to the text instructions;
[0024] Determine the display order of each character in the target PDF document;
[0025] Each character is added to the same array according to the display order to obtain a character array.
[0026] In one embodiment, the step of determining the font information of each character using a preset parsing library includes:
[0027] The font name of each character is determined using the preset parsing library;
[0028] Determine whether each font name conforms to a preset rule, wherein the preset rule is that the font name consists of multiple keywords, and the keywords in the same position in different font names are of the same type;
[0029] The font information of the characters corresponding to each font name is determined based on the judgment result.
[0030] In one embodiment, the step of determining the font information of the characters corresponding to each font name based on the determination result includes:
[0031] When a first font name that conforms to the preset rule exists, the keyword in the first font name at a preset position is obtained as a style feature;
[0032] Obtain a preset font library containing multiple reference font information;
[0033] The style features are matched with the baseline font information in the preset font library;
[0034] The baseline font information matching the style features is obtained as the font information of the character corresponding to the first font name.
[0035] In one embodiment, the step of determining the font information of the characters corresponding to each font name based on the determination result further includes:
[0036] When a second font name that does not conform to the preset rules exists, it is determined whether the second font name contains any baseline font information in the preset font library;
[0037] When any reference font information is included, the included reference font information is used as the font information of the character corresponding to the second font name.
[0038] In one embodiment, after the step of generating structured data corresponding to the target document based on each of the style information, the method further includes:
[0039] The structured data is converted into corresponding page tags;
[0040] Obtain the target text language;
[0041] When the text language of the target document is not the target text language, the text language of each character in the page tag is converted to the target text language to obtain the translated page tag;
[0042] The translated page tags are displayed on the front-end page.
[0043] Furthermore, to achieve the above objectives, this application also proposes a document processing apparatus, the apparatus comprising:
[0044] The data acquisition module is used to acquire the drawing instruction set of the target document;
[0045] The style determination module is used to determine the style information of each character in the target document according to the drawing instruction set;
[0046] The data generation module is used to generate structured data corresponding to the target document based on the style information.
[0047] In one embodiment, the target document is a target PDF document, and the style determination module is further configured to determine the color information of each character in the target PDF document according to the drawing instruction set;
[0048] The style determination module is also used to determine the font information of each character through a preset parsing library;
[0049] The style determination module is further configured to obtain each of the color information and each of the font information as style information for each of the characters.
[0050] In one embodiment, the style determination module is further configured to obtain color instructions from the drawing instruction set;
[0051] The style determination module is further configured to determine the color value corresponding to each character according to the color instruction;
[0052] The style determination module is also used to obtain each of the color values as the color information of the corresponding character.
[0053] In one embodiment, the data generation module is further configured to acquire text instructions from the drawing instruction set;
[0054] The data generation module is further configured to determine a character array containing each of the characters in the target PDF document based on the text instructions;
[0055] The data generation module is also used to configure corresponding color information and corresponding font information for each character in the character array to obtain the structured data of the target PDF document.
[0056] In one embodiment, the data generation module is further configured to obtain each character in the target PDF document according to the text instruction;
[0057] The data generation module is also used to determine the display order of each character in the target PDF document;
[0058] The data generation module is further configured to add each of the characters to the same array according to the display order to obtain a character array.
[0059] In one embodiment, the style determination module is further configured to determine the font name of each character using the preset parsing library;
[0060] The style determination module is used to determine whether each font name conforms to a preset rule. The preset rule is that the font name consists of multiple keywords, and the keywords in the same position in different font names are of the same type.
[0061] The style determination module is used to determine the font information of the characters corresponding to each font name based on the determination result.
[0062] In one embodiment, the style determination module is further configured to, when there is a first font name that conforms to the preset rule, obtain the keyword in the first font name at a preset position as a style feature;
[0063] The style determination module is also used to obtain a preset font library including multiple reference font information, wherein the preset font library contains multiple reference font information;
[0064] The style determination module is further configured to match the style features with the baseline font information in the preset font library;
[0065] The style determination module is further configured to obtain the baseline font information matching the style features as the font information of the character corresponding to the first font name.
[0066] In one embodiment, the style determination module is further configured to determine whether the second font name contains any baseline font information in the preset font library when there is a second font name that does not conform to the preset rule;
[0067] The style determination module is further configured to, when containing any reference font information, use the contained reference font information as the font information of the character corresponding to the second font name.
[0068] In one embodiment, the data generation module is further configured to convert the structured data into corresponding page tags;
[0069] The data generation module is also used to acquire the target text language;
[0070] The data generation module is further configured to convert the text language of each character in the page tag into the target text language when the text language of the target document is not the target text language, so as to obtain the translated page tag;
[0071] The data generation module is also used to display the translated page tags on the front-end page.
[0072] In addition, to achieve the above objectives, this application also proposes a document processing device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the document processing method as described above.
[0073] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and which, when executed by a processor, implements the steps of the document processing method described above.
[0074] One or more technical solutions proposed in this application have at least the following technical effects:
[0075] This application obtains the drawing instruction set of the target document; determines the style information of each character in the target document based on the drawing instruction set; and generates structured data corresponding to the target document based on the style information. Since this application determines the style information through the drawing instruction set and then generates structured data of the target document based on that style information, compared to existing OCR processing methods, this application can output structured data through the drawing instruction set without involving complex pattern matching and algorithm calculations, effectively improving document processing speed and thus improving document processing efficiency. Attached Figure Description
[0076] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0077] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0078] Figure 1 This is a flowchart illustrating the first embodiment of the document processing method of this application;
[0079] Figure 2 This is a flowchart illustrating the second embodiment of the document processing method of this application;
[0080] Figure 3 This is a schematic diagram illustrating the extraction of color information according to the second embodiment of this application;
[0081] Figure 4 This is an example diagram illustrating the generation of structured data according to the second embodiment of this application;
[0082] Figure 5 This is a flowchart illustrating the third embodiment of the document processing method of this application;
[0083] Figure 6 This is a schematic diagram of the module structure of the document processing device of this application;
[0084] Figure 7This is a schematic diagram of the structure of a document processing device suitable for implementing the embodiments of this application.
[0085] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0086] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0087] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0088] The main solution of this application embodiment is: to obtain the drawing instruction set of the target document; to determine the style information of each character in the target document according to the drawing instruction set; and to generate the structured data corresponding to the target document according to the style information.
[0089] Because existing OCR processing methods involve complex pattern matching and algorithm calculations, insufficient hardware resources can lead to relatively slow processing speeds, affecting document processing efficiency.
[0090] This application provides a solution that, after determining style information through a drawing instruction set, generates structured data of the target document based on the style information. Therefore, compared with existing OCR processing methods, this application can output structured data through a drawing instruction set without involving complex pattern matching and algorithm calculations, effectively improving document processing speed and thus improving document processing efficiency.
[0091] It should be noted that the executing entity in this application embodiment can be a computing service device with document processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device or document processing device capable of performing the above functions. The following description uses a document processing device as an example to illustrate this embodiment and the subsequent embodiments.
[0092] Based on this, embodiments of this application provide a document processing method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the document processing method of this application.
[0093] In this embodiment, the document processing method includes: steps S10 to S30:
[0094] Step S10: Obtain the drawing instruction set of the target document.
[0095] It should be noted that the above drawing instruction set can be a collection of drawing instructions in the target file that describe the drawing operations of page content. Each drawing instruction in the drawing instruction set defines how to render text, graphics and images on the target PDF page.
[0096] Understandably, the target document mentioned above can be a document that cannot be edited online, such as a PDF document, an image document, or a scanned document.
[0097] In practice, the target document can be uploaded to the document processing device by the user, or it can be selected by the user from the local documents on the document processing device. After obtaining the target document, the document processing device can parse the target document and obtain the drawing instruction set composed of the drawing instructions in its content stream.
[0098] Step S20: Determine the style information of each character in the target document according to the drawing instruction set.
[0099] It should be noted that the above style information can be a series of attributes describing the appearance of text, graphics and images in the target document, including at least font, size, color, bold or italic, etc.
[0100] In a specific implementation, the document processing device can extract drawing instructions related to the style information of characters from the drawing instruction set. For example, / F1 18Tf means selecting font F1 and setting its size to 18. By parsing the extracted drawing instructions, the style information of each character in the target document can be obtained.
[0101] Step S30: Generate structured data corresponding to the target document based on the style information.
[0102] In a specific implementation, the aforementioned document processing device can extract drawing instructions related to text display from the drawing instruction set, extract each character according to the drawing instructions related to text display, form text content consistent with the target document, associate the extracted characters with corresponding style information (such as font, size, color, bold, italic, etc.), and then integrate the associated data into a structured data format, such as a JSON object, to obtain structured data containing text content and style information.
[0103] In one possible implementation, steps S40 to S70 may be included after step S30:
[0104] Step S40: Convert the structured data into corresponding page tags.
[0105] In its implementation, the aforementioned document processing device can determine each character in the structured data, and then create corresponding HTML elements (such as...) based on the style information corresponding to each character. 、 、 (etc.), use CSS style properties to apply the corresponding style information to obtain the page tags for each character.
[0106] Step S50: Obtain the target text language.
[0107] It should be noted that the target text language mentioned above can be the language displayed on the front-end page for page tags.
[0108] In a specific implementation, multiple text languages can be pre-configured for the document processing device. The document processing device can display a language list containing each text language to the user. The user can perform a selection operation on each text language, triggering a text language selection instruction. The document processing device can respond to the text language selection instruction and select the target text language specified by the user from the language list.
[0109] Step S60: When the text language of the target document is not the target text language, the text language of each character in the page tag is converted into the target text language to obtain the translated page tag.
[0110] In a specific implementation, the document processing device can detect whether the text language of the target document is the target text language. If it is not the target text language, it can translate the text language of each character in the page tag into the target text language through the built-in translation engine or the machine translation application programming interface (API) to obtain the translated page tag.
[0111] Step S70: Display the translated page tags on the front-end page.
[0112] In practice, the aforementioned document processing device can embed the translated page tags into the corresponding positions on the front-end page for display, so that users can view or edit the translated content.
[0113] In addition, when the target document's text language is the target text language, page tags can be directly displayed on the front-end page.
[0114] Furthermore, when the user does not perform the operation of selecting each text language, the document processing device can select the text language that is consistent with the text language of the target document from the language list as the target text language, and then directly display the page tags on the front-end page, thereby realizing the intuitive display of the text content corresponding to the target document.
[0115] This embodiment obtains the drawing instruction set of the target document; determines the style information of each character in the target document based on the drawing instruction set; and generates structured data corresponding to the target document based on the style information. Since this embodiment determines the style information through the drawing instruction set and then generates structured data of the target document based on that style information, compared to existing OCR processing methods, this embodiment can output structured data through the drawing instruction set without involving complex pattern matching and algorithm calculations, effectively improving document processing speed and thus improving document processing efficiency.
[0116] Based on the first embodiment of this application, a second embodiment of this application is proposed. In the second embodiment, content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 2 , Figure 2 This is a flowchart illustrating the second embodiment of the document processing method of this application.
[0117] In this embodiment, the target document is a target PDF document, and step S20 may include steps S201 to S203:
[0118] Step S201: Determine the color information of each character in the target PDF document according to the drawing instruction set.
[0119] It should be noted that the color information mentioned above refers to the color attributes used to display characters in the target PDF document.
[0120] In a specific implementation, the document processing device can extract drawing instructions that begin with color-related operators from the drawing instruction set, such as drawing instructions that begin with operators like RG (set RGB color) and G (set grayscale color). Then, by parsing the extracted drawing instructions, the color information of each character in the target PDF document can be obtained.
[0121] In one possible implementation, step S201 may include steps S2011 to S2013:
[0122] Step S2011: Obtain the color instructions from the drawing instruction set.
[0123] In a specific implementation, the aforementioned document processing device can use drawing instructions that begin with color-related operators in the drawing instruction set as color instructions.
[0124] Step S2012: Determine the color value corresponding to each character according to the color instruction.
[0125] In a specific implementation, the document processing device described above can extract the color instruction corresponding to each character, and then extract the parameter carried in the color instruction, which is the color value corresponding to that character.
[0126] like Figure 3 As shown, Figure 3 The illustration shows the extraction of color information according to the second embodiment of this application. Taking setFill RGB Color as a color instruction as an example, the document processing device can obtain the document content of the target PDF and the drawing instruction set, traverse the drawing instruction set, and extract each set Fill RGB Color. set Fill RGB Color[0, 0, 0] carries RGB parameters, that is, the color value is [0, 0, 0], and the corresponding color information is black. set Fill RGB Color[196, 18, 48] carries RGB parameters, that is, the color value is [196, 18, 48], and the corresponding color information is dark red.
[0127] Step S2013: Obtain each color value as the color information of the corresponding character.
[0128] In practice, the document processing device can determine the corresponding color value of each character according to the color instruction corresponding to each character, and use the color value of each character as its color information.
[0129] Step S202: Determine the font information of each character using a preset parsing library.
[0130] It should be noted that the aforementioned preset parsing library can be an open-source JavaScript library for rendering and displaying the target PDF document, such as PDF.js.
[0131] Understandably, the above font information can be information related to the font used for characters in the target PDF document, including the font used, font weight, italics, etc.
[0132] In a specific implementation, the document processing device can use the preset parsing library to access the text content of the target PDF document, and then extract the font information of each character from the text content.
[0133] Step S203: Obtain the color information and font information of each character as style information of each character.
[0134] In a practical implementation, the aforementioned document processing device can use the color and font information of each character as the style information of the corresponding character.
[0135] In one feasible implementation, step S30 may include steps S301 to S303:
[0136] Step S301: Obtain the text instructions from the drawing instruction set.
[0137] It should be noted that the above text commands can be commands used to display text in the target PDF document, such as the showText command. This text command defines how characters are displayed in the target PDF file, including the position, font, and size of the text.
[0138] In a practical implementation, the aforementioned document processing device can extract text instructions related to text display operations from the drawing instruction set.
[0139] Step S302: Determine a character array containing each of the characters in the target PDF document according to the text instruction.
[0140] In a specific implementation, the document processing device described above can extract the characters corresponding to each text instruction, and then add each character to the same array to obtain a character array containing each character.
[0141] In one feasible implementation, step S302 may include steps S3021 to S3023:
[0142] Step S3021: Obtain each character in the target PDF document according to the text instruction.
[0143] In its implementation, the aforementioned document processing device can traverse each text instruction in the target PDF document and extract the characters corresponding to each text instruction.
[0144] Step S3022: Determine the display order of each character in the target PDF document.
[0145] In a specific implementation, the document processing device can determine the position of the corresponding character in the target PDF document according to the text instruction, and then determine the display order of each character in the target PDF document according to the position of each character in the target PDF document. For example, in the page of the target PDF document, the character in the left position of the same line is displayed first, while the character in the right position is displayed first.
[0146] Step S3023: Add each of the characters to the same array according to the display order to obtain a character array.
[0147] In a specific implementation, the document processing device can add each character to the same array in the order of their display, so that the resulting character array can contain the display implementation of each character, thereby enabling the character array to represent the continuous text content of the target PDF document.
[0148] Step S303: Configure corresponding color information and corresponding font information for each character in the character array to obtain the structured data of the target PDF document.
[0149] In a specific implementation, the document processing device described above can configure the corresponding color information and font information for each character according to the display order of each character in the character array, thereby obtaining the structured data of the target PDF document. This structured data can contain the text content of the target PDF document, the display order of each character, the color information of each character, and the font information of each character, thus effectively improving the generation accuracy of the structured data.
[0150] For example, refer to Figure 4 However, this does not limit the scope of this solution. Figure 4 This is an example diagram illustrating the generation of structured data according to the second embodiment of this application. Figure 4 In this example, we'll use `set Fill RGB Color` for color commands and `show Text` for text commands. After starting to process the target PDF document, a stack can be initialized to manage the drawing state. This stack will be used to save and restore the drawing state, such as the current color and font. Simultaneously, a character array is initialized. Then, the drawing command set in the target PDF document's content stream is traversed, and the operation type of each drawing command is determined to ascertain its function. For `save` type drawing commands, the drawing state (including color, font, position, etc.) of the corresponding character is saved onto the stack (push). For `reset` type drawing commands, the previously saved drawing state of the corresponding character is restored from the stack (pop). For `set Fill RGB Color` type color commands, the drawing state of the corresponding character is set to the color specified by the color command. For `show Text` type text commands, the character corresponding to the text command is extracted, and the character and its corresponding drawing state (such as font, color, etc.) are saved to the initialized character array. When the drawing instruction set has not been traversed, the step of determining the operation type of each drawing instruction is repeated until the traversal is completed, resulting in structured data containing the text content and style information corresponding to each character.
[0151] This embodiment determines the color information of each character in the target PDF document according to a drawing instruction set; determines the font information of each character using a preset parsing library; and obtains the color information and font information as style information for each character, thereby accurately extracting style information containing color and font information. Furthermore, this embodiment also obtains text instructions from the drawing instruction set; determines a character array containing each character in the target PDF document based on the text instructions; and configures corresponding color and font information for each character in the character array to obtain structured data of the target PDF document. This allows for accurate configuration of corresponding color and font information for each character through the character array, thereby improving the generation accuracy of structured data.
[0152] Based on the first and second embodiments of this application, a third embodiment of this application is proposed. In this third embodiment, content that is the same as or similar to the first and second embodiments described above can be referred to the above description and will not be repeated hereafter. Based on this, please refer to... Figure 5 , Figure 5 This is a flowchart illustrating the third embodiment of the document processing method of this application.
[0153] In this embodiment, step S202 may include steps S2021 to S2023:
[0154] Step S2021: Determine the font name of each character using the preset parsing library.
[0155] In a specific implementation, the document processing device can use the preset parsing library to access the text content of the target PDF document, then extract the font information of each character from the text content, and determine the font name in each font information.
[0156] Step S2022: Determine whether each font name conforms to a preset rule. The preset rule is that the font name consists of multiple keywords, and the keywords in the same position in different font names are of the same type.
[0157] It should be noted that the above preset rules can be pre-built rules. Font names that conform to the preset rules are in the form of id + name + suffix. That is, different font names that conform to the preset rules can be broken down into the form of id + name + suffix. id, name, and suffix can be the types of keywords.
[0158] In a specific implementation, the document processing device can traverse the font name of each character and determine whether each font name conforms to a preset rule. For example, it can determine whether the font name of each character can be split into the form of id + name + suffix.
[0159] Step S2023: Determine the font information of the characters corresponding to each font name based on the determination result.
[0160] In specific implementation, the document processing device can adopt different strategies based on whether the font name conforms to preset rules. For example, when any font name is detected to conform to preset rules, its font information can be determined based on the keywords in different positions that constitute the font name; when any font name is detected to not conform to preset rules, its font information can be determined based on the word segments that constitute the font name.
[0161] In one feasible implementation, step S2023 may include steps A21 to A24:
[0162] Step A21: When a first font name that conforms to the preset rule exists, the keyword in the first font name at a preset position is obtained as a style feature.
[0163] It should be noted that the above-mentioned preset position can be a pre-set or specified position. For example, when the font name that conforms to the preset rules is id + name + suffix, the preset position can be the position corresponding to the suffix.
[0164] In a specific implementation, the document processing device can use a font name that conforms to a preset rule as the first font name, determine each keyword that constitutes the first font name, and select the keyword at a preset position as the style feature.
[0165] Step A22: Obtain a preset font library containing multiple reference font information.
[0166] It should be noted that the above-mentioned reference font information may be pre-configured or calibrated information used to characterize the corresponding font. For example, Bold represents bold, Italic represents italic, and Light represents light font.
[0167] In a specific implementation, the document processing device can obtain a preset font library containing multiple reference font information when determining each first font name, so as to identify the font information of each first font name through the preset font library.
[0168] Step A23: Match the style features with the reference font information in the preset font library.
[0169] In a specific implementation, the document processing device can match the style features of the first font name with the reference font information in the preset font library, that is, determine whether the style features of the first font name are consistent with any reference font information.
[0170] Step A24: Obtain the baseline font information matching the style features as the font information of the character corresponding to the first font name.
[0171] In a specific implementation, when the document processing device detects that the style feature of the first font name is consistent with any reference font information, it uses the reference font information as the reference font information for style feature matching, and then uses the matched reference font information as the font information of the character corresponding to the first font name.
[0172] In another feasible implementation, step S2023 may further include steps B21 to B22:
[0173] Step B21: When there is a second font name that does not conform to the preset rule, determine whether the second font name contains any benchmark font information in the preset font library.
[0174] In specific implementation, the baseline font information in the aforementioned preset font library can be constructed by collecting documents in multiple different languages and based on the font rules of documents in different languages. This allows the baseline font information to also be applicable to font names with other specific rules outside of the preset rules. For example, HTK or XBSK can represent bold. In order to increase scalability, the baseline font information of the preset font library can be continuously updated according to newly emerging fonts or instructions, so that the preset font library can adapt to more scenarios.
[0175] Based on this, the document processing device can use a font name that does not conform to the preset rules as a second font name, and then match the second font name with the reference font information in the preset font library to determine whether the second font name contains any reference font information.
[0176] Step B22: When any reference font information is included, the included reference font information is used as the font information of the character corresponding to the second font name.
[0177] In a specific implementation, when the document processing device detects that the second font name contains any reference font information, it uses that reference font information as the font information of the character corresponding to the second font name.
[0178] In this embodiment, for a first font name that conforms to the preset rules, the keyword in the first font name at a preset position is used as a style feature. The style feature is then matched with the reference font information in the preset font library, and the matched reference font information is used as the font information of the character corresponding to the first font name. For a second font name that does not conform to the preset rules, it is determined whether the second font name contains any reference font information in the preset font library. Any reference font information contained therein is used as the font information of the character corresponding to the second font name, thereby effectively improving the recognition accuracy of font information.
[0179] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the document processing method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.
[0180] This application also provides a document processing apparatus, please refer to... Figure 6 , Figure 6 This is a schematic diagram of the module structure of the document processing device of this application. The document processing device includes:
[0181] The data acquisition module 10 is used to acquire the drawing instruction set of the target document;
[0182] The style determination module 20 is used to determine the style information of each character in the target PDF document according to the drawing instruction set;
[0183] The data generation module 30 is used to generate structured data corresponding to the target document based on the style information.
[0184] The document processing apparatus provided in this application, employing the document processing method in the above embodiments, can solve the technical problem of relatively slow processing speed in the prior art, which affects document processing efficiency. Compared with the prior art, the beneficial effects of the document processing apparatus provided in this application are the same as those of the document processing method provided in the above embodiments, and other technical features in the document processing apparatus are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0185] In one implementation, the target document is a target PDF document, and the style determination module 20 is further configured to determine the color information of each character in the target PDF document according to the drawing instruction set;
[0186] The style determination module 20 is also used to determine the font information of each character through a preset parsing library;
[0187] The style determination module 20 is further configured to acquire each of the color information and each of the font information as style information for each of the characters.
[0188] In one implementation, the style determination module 20 is further configured to acquire color instructions from the drawing instruction set;
[0189] The style determination module 20 is further configured to determine the color value corresponding to each character according to the color instruction;
[0190] The style determination module 20 is also used to obtain each of the color values as the color information of the corresponding character.
[0191] In one implementation, the data generation module 30 is also used to acquire text instructions from the drawing instruction set;
[0192] The data generation module 30 is further configured to determine a character array containing each of the characters in the target PDF document according to the text instruction;
[0193] The data generation module 30 is also used to configure corresponding color information and corresponding font information for each character in the character array to obtain the structured data of the target PDF document.
[0194] In one implementation, the data generation module 30 is further configured to obtain each character in the target PDF document according to the text instruction;
[0195] The data generation module 30 is also used to determine the display order of each character in the target PDF document;
[0196] The data generation module 30 is further configured to add each of the characters to the same array according to the display order to obtain a character array.
[0197] In one implementation, the style determination module 20 is further configured to determine the font name of each character using the preset parsing library;
[0198] The style determination module 20 is used to determine whether each font name conforms to a preset rule. The preset rule is that the font name consists of multiple keywords, and the keywords in the same position in different font names are of the same type.
[0199] The style determination module 20 is used to determine the font information of the characters corresponding to each font name based on the determination result.
[0200] In one implementation, the style determination module 20 is further configured to, when there is a first font name that conforms to the preset rule, obtain the keyword in the first font name at a preset position as a style feature;
[0201] The style determination module 20 is also used to obtain a preset font library including multiple reference font information, wherein the preset font library contains multiple reference font information;
[0202] The style determination module 20 is further configured to match the style features with the reference font information in the preset font library;
[0203] The style determination module 20 is further configured to obtain the baseline font information of the style feature matching as the font information of the character corresponding to the first font name.
[0204] In one implementation, the style determination module 20 is further configured to determine whether the second font name contains any reference font information in the preset font library when there is a second font name that does not conform to the preset rule;
[0205] The style determination module 20 is further configured to, when containing any reference font information, use the contained reference font information as the font information of the character corresponding to the second font name.
[0206] In one implementation, the data generation module 30 is further configured to convert the structured data into corresponding page tags;
[0207] The data generation module 30 is also used to acquire the target text language;
[0208] The data generation module 30 is further configured to convert the text language of each character in the page tag into the target text language when the text language of the target document is not the target text language, so as to obtain the translated page tag;
[0209] The data generation module 30 is also used to display the translated page tags on the front-end page.
[0210] This application provides a document processing device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the document processing method in Embodiment 1 above.
[0211] The following is for reference. Figure 7 , Figure 7 This is a schematic diagram of the structure of a document processing device suitable for implementing the embodiments of this application. The document processing device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 7 The document processing device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0212] like Figure 7 As shown, the document processing device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the document processing device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touchscreen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1003 including, for example, magnetic tape, hard disk, etc.; and communication devices 1009. The communication device 1009 allows the document processing device to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows document processing devices with various systems, it should be understood that it is not required to implement or possess all of the systems shown. More or fewer systems may be implemented alternatively.
[0213] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0214] The document processing device provided in this application, employing the document processing method in the above embodiments, can solve the technical problem of relatively slow processing speed in the prior art, which affects document processing efficiency. Compared with the prior art, the beneficial effects of the document processing device provided in this application are the same as those of the document processing method provided in the above embodiments, and other technical features in this document processing device are the same as those disclosed in the method of the previous embodiment, and will not be repeated here.
[0215] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0216] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0217] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the document processing method in the above embodiments.
[0218] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0219] The aforementioned computer-readable storage medium may be included in a document processing device or may exist independently without being assembled into a document processing device.
[0220] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by a document processing device, cause the document processing device to: acquire a drawing instruction set of a target PDF document; determine style information of each character in the target PDF document based on the drawing instruction set; and generate structured data corresponding to the target PDF document based on the style information.
[0221] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0222] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0223] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0224] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described document processing method. This solves the technical problem of relatively slow processing speed in the prior art, which affects document processing efficiency. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the document processing method provided in the above embodiments, and will not be repeated here.
[0225] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A document processing method, characterized in that, The method includes: Obtain the drawing instruction set of the target document; The style information of each character in the target document is determined according to the drawing instruction set; The structured data corresponding to the target document is generated based on the style information described above.
2. The document processing method as described in claim 1, characterized in that, The target document is a target PDF document, and the step of determining the style information of each character in the target document according to the drawing instruction set includes: The color information of each character in the target PDF document is determined according to the drawing instruction set; The font information of each character is determined by a preset parsing library; The color information and font information are obtained as the style information of each character.
3. The document processing method as described in claim 2, characterized in that, The step of determining the color information of each character in the target PDF document according to the drawing instruction set includes: Obtain the color instruction from the drawing instruction set; The color value corresponding to each character is determined according to the color instruction; Obtain each of the aforementioned color values as the color information of the corresponding character.
4. The document processing method as described in claim 3, characterized in that, The step of generating structured data corresponding to the target document based on each of the style information includes: Obtain the text instructions from the drawing instruction set; Determine a character array containing each of the characters in the target PDF document based on the text instructions; The corresponding color information and font information are configured for each character in the character array to obtain the structured data of the target PDF document.
5. The document processing method as described in claim 4, characterized in that, The step of determining the character array containing each character in the target PDF document according to the text instruction includes: Retrieve each character from the target PDF document according to the text instructions; Determine the display order of each character in the target PDF document; Each character is added to the same array according to the display order to obtain a character array.
6. The document processing method according to any one of claims 2 to 5, characterized in that, The step of determining the font information of each character using a preset parsing library includes: The font name of each character is determined using the preset parsing library; Determine whether each font name conforms to a preset rule, wherein the preset rule is that the font name consists of multiple keywords, and the keywords in the same position in different font names are of the same type; The font information of the characters corresponding to each font name is determined based on the judgment result.
7. The document processing method as described in claim 6, characterized in that, The step of determining the font information of the characters corresponding to each font name based on the determination result includes: When a first font name that conforms to the preset rule exists, the keyword in the first font name at a preset position is obtained as a style feature; Obtain a preset font library containing multiple reference font information; The style features are matched with the baseline font information in the preset font library; The baseline font information matching the style features is obtained as the font information of the character corresponding to the first font name.
8. A document processing apparatus, characterized in that, The device includes: The data acquisition module is used to acquire the drawing instruction set of the target document; The style determination module is used to determine the style information of each character in the target document according to the drawing instruction set; The data generation module is used to generate structured data corresponding to the target document based on the style information.
9. A document processing device, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the document processing method as described in any one of claims 1 to 7.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the document processing method as described in any one of claims 1 to 7.