A method and apparatus for converting a picture to editable text while maintaining the layout
By converting images into JSON data and processing them into rich text objects and tables in an editable graphical interface, the problem of maintaining layout when converting images to editable text is solved, achieving accurate layout conversion and editing functions.
Patent Information
- Application Number
- CN202111148548.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-28
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2041-09-28
AI Technical Summary
Existing methods for converting images to editable text cannot preserve the original image layout, causing the converted text to lose its original formatting structure.
By converting images to JSON data, plain text, plain images, plain tables, and mixed-type data are transformed into editable rich text objects, images, and tables on an editable graphical interface, and then converted back to JSON data after editing, ensuring that the layout is preserved.
The converted editable text maintains the same layout, position, and size as the original image, and supports editing operations across rich text paragraphs.
Smart Images

Figure CN113850068B_ABST
Abstract
Description
Technical Field
[0001] This application relates to a method for converting an image into editable text. Background Technology
[0002] Existing methods for converting images into editable text generally use OCR (Optical Character Recognition) technology to extract text from images. However, the text extracted from images is not formatted, so the converted text cannot maintain the same layout as the original image. Summary of the Invention
[0003] The technical problem this application aims to solve is to provide a method for converting images into editable text, wherein the converted editable text maintains the same layout as the original image. To this end, this application also proposes an apparatus for converting images into editable text.
[0004] To address the aforementioned technical problems, this application proposes a method for converting images into editable text while maintaining layout, comprising the following steps: Step S10: Convert the image into first JSON data; the data type in the first JSON data includes plain text, plain image, plain table, or a combination of these types. Step S20: Convert the first JSON data into an editable graphical interface; wherein, the plain text, plain image, plain table, and mixed-type data in the first JSON data are respectively converted into plain text rich text objects, images, tables, and combo boxes on the editable graphical interface; the combo box contains multiple plain text, plain image, and / or plain table rich text objects. Step S30: Convert the edited graphical interface into second JSON data; wherein, each plain text rich text object, image, table, and combo box in the edited graphical interface is respectively converted into a corresponding plain text, plain image, plain table, or mixed-type model corresponding to the second JSON data object, and all models corresponding to the second JSON data object are combined to form the second JSON data. Step S40: Convert the second JSON data into editable text. The above method maintains the layout while converting the image into editable text.
[0005] Furthermore, in step S10, the data subtypes in the mixed-type data include any one or more of plain text, plain images, and plain tables. After conversion on the editable graphical interface output in step S20, the mixed-type data in the first JSON data can be edited across rich text paragraphs.
[0006] Furthermore, in step S20, for plain text data in the first JSON data, rich text objects containing the corresponding content are created on an editable graphical interface, with each paragraph as a unit.
[0007] Furthermore, in step S20, for the pure image type data in the first JSON data, an image with corresponding content is generated on the editable graphical interface. It is important to note that although there are also pure image rich text objects, here an image is generated on the editable graphical interface, not a pure image rich text object.
[0008] Furthermore, in step S20, for the pure table type data in the first JSON data, a blank view is first created on the editable graphical interface. Then, a table with corresponding content is drawn on the blank view based on the pure table in the first JSON data. Each cell of the drawn table corresponds to each cell object in the pure table type data of the first JSON data, and multiple cells form a complete table. It is important to note that although there are also pure table rich text objects, what is drawn on the editable graphical interface here is a table, not a pure table rich text object.
[0009] Further, in step S20, for mixed-type data in the first JSON data, a combo box is first created on the editable graphical interface. Then, within the combo box, rich text objects with corresponding content are generated based on whether the subtype of the mixed-type data is plain text, plain image, or plain table. For mixed-type data with plain text as the subtype, rich text paragraphs are also generated within the combo box, with each paragraph as a unit. All rich text objects belong to a specific rich text paragraph. The vertical position of each rich text paragraph is determined by the paragraph spacing field set in the paragraph spacing field of the mixed-type data in the first JSON data. The left and right positions of each rich text paragraph are determined by the paragraph indentation field of the mixed-type data in the first JSON data. It is important to note that in the combo box on the editable graphical interface, the mixed-type data in the first JSON data with plain text, plain image, and plain table as subtypes are respectively generated as plain text rich text objects, plain image rich text objects, and plain table rich text objects.
[0010] Furthermore, in step S30, the edited graphical interface may be the same as or different from the editable graphical interface output in step S20. This indicates that the editable graphical interface output in step S20 can be modified by the user, or the user may choose not to modify it.
[0011] Furthermore, in step S30, for each plain text rich text object, image, and table in the edited graphical interface, a corresponding model of the second JSON data object of the plain text, plain image, and plain table types is generated respectively.
[0012] Further, in step S30, for the combo box in the edited graphical interface, each rich text object in the combo box is traversed, and each rich text object is used to generate a sub-model corresponding to the second JSON data sub-object according to its type: text, image, or table. All the sub-models corresponding to the second JSON data sub-objects generated by all the rich text objects in a combo box are combined to form a model corresponding to the second JSON data object of the mixed type.
[0013] This application also proposes an apparatus for converting images into editable text while preserving layout, comprising a first conversion unit, a second conversion unit, a third conversion unit, and a fourth conversion unit. The first conversion unit converts the image into first JSON data; the data type in the first JSON data includes plain text, plain image, plain table, or a combination of these types. The second conversion unit converts the first JSON data into an editable graphical interface; wherein the plain text, plain image, plain table, and mixed-type data in the first JSON data are respectively converted into plain text rich text objects, images, tables, and combo boxes on the editable graphical interface; the combo boxes contain multiple plain text, plain image, and / or plain table rich text objects. The third conversion unit converts the edited graphical interface into second JSON data; wherein each plain text rich text object, image, table, and combo box in the edited graphical interface is converted into a corresponding plain text, plain image, plain table, or mixed-type model corresponding to the second JSON data object, and all models corresponding to the second JSON data object are combined to form the second JSON data. The fourth conversion unit converts the second JSON data into editable text. The above apparatus maintains the layout while converting the image into editable text.
[0014] The technical effect achieved by this application is that the editable text converted from the image maintains the same layout as the original image, that is, the position and size of the text, tables, pictures and other elements on the original image remain unchanged in the converted editable text. Attached Figure Description
[0015] Figure 1 This is a flowchart illustrating the method for converting an image into editable text while maintaining its layout, as proposed in this application.
[0016] Figure 2 This is a schematic diagram of the device proposed in this application for converting an image into editable text while maintaining its layout.
[0017] Figure 3 It is an illustration that includes text, pictures, and tables.
[0018] Figure 4 It is by Figure 3 A diagram illustrating the editable text obtained through conversion.
[0019] The following are the annotations in the figure: 10 is the first conversion unit, 20 is the second conversion unit, 30 is the third conversion unit, and 40 is the fourth conversion unit. Detailed Implementation
[0020] Please see Figure 1 The method for converting images into editable text while maintaining layout, as proposed in this application, includes the following steps.
[0021] Step S10: Convert the image into JSON data, referred to as the first JSON data. This is an existing technology and will not be elaborated upon here. The first JSON data contains a maximum of four data types: plain text, plain image, plain table, and mixed. Mixed type refers to any combination of plain text, plain image, and plain table. Mixed type data contains a maximum of three data subtypes: plain text, plain image, and plain table.
[0022] Step S20: Convert the first JSON data into an editable graphical interface. The editable graphical interface is provided to the user for inspection and editing. Specifically, plain text, plain image, and plain table data in the first JSON data are converted into plain text rich text objects, images, and tables respectively on the editable graphical interface. Rich text objects include plain text, plain images, and plain tables; only plain text rich text objects are used here. Mixed-type data in the first JSON data are converted into a combo box on the editable graphical interface, with multiple plain text, plain image, and / or plain table rich text objects; all three types of rich text objects are used here.
[0023] For the plain text in the first JSON data, rich text objects are created on an editable graphical interface, with each paragraph representing a different piece of plain text. The properties of these rich text objects, such as coordinates and font size, are set according to the paragraphs of the plain text in the first JSON data. Each rich text object is displayed as a rectangle on the editable graphical interface.
[0024] For the plain images in the first JSON data, a corresponding image is generated in an editable graphical interface, rather than a rich text object representing the image. The coordinates of the generated image are set based on the plain image in the first JSON data. Each generated image is presented as a rectangle in the editable graphical interface.
[0025] For the plain tables in the first JSON data, first create a blank view in the editable graphical interface, and then draw the corresponding tables on the blank view based on the plain tables in the first JSON data. Each cell of the drawn table corresponds to each cell object in the plain table type data in the first JSON data, and multiple cells form a complete table. Note that this is not generating rich text objects of plain tables. Each drawn table is presented as a rectangle in the editable graphical interface.
[0026] For mixed-type data in the first JSON dataset, a large rectangle, called a combo box, is first created on the editable graphical interface. Then, within the combo box, rich text objects are generated based on whether the subtype of the mixed-type data is plain text, plain image, or plain table. For mixed-type data with plain text as a subtype, rich text paragraphs are generated within the combo box, with different attributes (font, color, size, etc.) within each paragraph serving as different plain text rich text objects. For mixed-type data with plain image as a subtype, rich text objects for the plain image are generated within the combo box, and these plain image rich text objects belong to a specific rich text paragraph. For mixed-type data with plain table as a subtype, rich text objects for the plain table are generated within the combo box, and these plain table rich text objects belong to a specific rich text paragraph. The vertical position of each rich text paragraph is determined by the paragraph spacing set in the paragraph gap (paragraph_gap) field of the mixed-type data in the first JSON dataset. The left and right positions of each rich text paragraph are determined by the paragraph indentation fields (e.g., left indent_left, right indent_right) in the mixed-type data of the first JSON data. Each mixed-type data is presented as a combo box on the editable graphical interface, and each rich text object within the combo box is one of the following types: plain text, plain image, or plain table. When the user edits within the combo box, they can select all rich text objects within the combo box and perform cross-rich text paragraph editing operations such as merging rich text paragraphs, splitting rich text paragraphs, and automatically moving all text down when a line breaks.
[0027] Step S30: Convert the edited graphical interface into JSON data, referred to as the second JSON data. Specifically, each plain text rich text object, image, table, and combo box in the edited graphical interface is converted into a corresponding plain text, plain image, plain table, or mixed-type model corresponding to the second JSON data object. All models corresponding to the second JSON data object are combined to form the second JSON data. The edited graphical interface may be the same as or different from the editable graphical interface output in step S20.
[0028] For each plain text rich text object, image, and table in the edited graphical interface, generate a corresponding model of the second JSON data object in plain text, plain image, and plain table types, respectively.
[0029] For each combo box in the edited graphical interface, iterate through each rich text object within the combo box, and generate a corresponding sub-model for each rich text object based on its type (plain text, plain image, or plain table), representing the second JSON data sub-object. The value of each sub-model corresponding to the second JSON data sub-object is determined by the current attribute value of the rich text object. All the sub-models generated from all rich text objects within a combo box are combined to form a mixed-type model corresponding to the second JSON data object.
[0030] Step S40: Convert the second JSON data into editable text, such as a Word document. This is an existing technique and will not be elaborated upon here.
[0031] Please see Figure 2 The apparatus for converting images into editable text while maintaining layout, as proposed in this application, includes a first conversion unit 10, a second conversion unit 20, a third conversion unit 30, and a fourth conversion unit 40.
[0032] The first conversion unit 10 is used to convert the image into JSON data, referred to as the first JSON data. The first JSON data contains up to four data types: plain text, plain image, plain table, and mixed.
[0033] The second conversion unit 20 is used to convert the first JSON data into an editable graphical interface. Specifically, plain text, plain image, and plain table data in the first JSON data are converted into plain text rich text objects, images, and tables on the editable graphical interface, respectively. Mixed data in the first JSON data are converted into combo boxes on the editable graphical interface, and the combo boxes contain multiple plain text, plain image, and / or plain table rich text objects.
[0034] The third conversion unit 30 is used to convert the edited graphical interface into JSON data, referred to as the second JSON data. Specifically, each plain text rich text object, image, table, and combo box in the edited graphical interface is converted into a corresponding plain text, plain image, plain table, or mixed-type model corresponding to the second JSON data object. All models corresponding to the second JSON data object are combined to form the second JSON data.
[0035] The fourth conversion unit 40 is used to convert the second JSON data into editable text.
[0036] Please see Figure 3 and Figure 4 This application can Figure 3 The image shown contains text, pictures, and tables. Convert it to... Figure 4 The editable text shown, and the layout of the converted editable text ( Figure 4 ) and the layout of the original image ( Figure 3 This consistency is particularly suitable for checking the conversion effect and performing subsequent text processing operations. During the conversion process, the first JSON data of mixed types can be edited across rich text paragraphs on the editable graphical interface output in step S20, breaking through the limitations of existing technologies.
[0037] The above are merely preferred embodiments of this application and are not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for converting an image into editable text while preserving its layout, characterized in that, Includes the following steps; Step S10: Convert the image into first JSON data; the data type of the first JSON data includes plain text, plain image, plain table, or a combination of these; the mixed data type includes plain text, plain image, or plain table as one or more data subtypes. Step S20: Convert the first JSON data into an editable graphical interface; For plain text data in the first JSON data, create rich text objects of the corresponding content in paragraph form on an editable graphical interface. For pure image data in the first JSON data, generate corresponding images on an editable graphical interface; For the pure table type data in the first JSON data, first create a blank view on the editable graphical interface, and then draw the corresponding table content on the blank view based on the pure table in the first JSON data; For mixed-type data in the first JSON data, a combo box is first created on the editable graphical interface. Then, rich text objects with corresponding content are generated in the combo box according to whether the subtype of the mixed-type data is plain text, plain image, or plain table. When the user edits in the combo box, all rich text objects in the combo box can be selected to enable editing operations across rich text paragraphs. Step S30: Convert the edited graphical interface into second JSON data; For each plain text rich text object in the edited graphical interface, generate a model of the corresponding plain text type corresponding to the second JSON data object; For each image in the edited graphical interface, generate a corresponding pure image type model corresponding to the second JSON data object; For each table in the edited graphical interface, generate a corresponding pure table type model corresponding to the second JSON data object; For the combo boxes in the edited graphical interface, iterate through each rich text object in the combo box, and generate sub-models corresponding to the second JSON data sub-objects according to the type of text, image, or table. All the sub-models corresponding to the second JSON data sub-objects generated by all the rich text objects in a combo box are combined to form a model corresponding to the second JSON data object of the mixed type. The second JSON data is formed by combining all the models corresponding to the second JSON data object. Step S40: Convert the second JSON data into editable text.
2. The method for converting an image into editable text while maintaining its layout according to claim 1, characterized in that, In step S20, for plain text data in the first JSON data, the properties of the rich text object for plain text are set according to the paragraphs of plain text in the first JSON data.
3. The method for converting an image into editable text while maintaining its layout according to claim 1, characterized in that, In step S20, for pure image data in the first JSON data, the coordinates of the generated image are set according to the pure image in the first JSON data.
4. The method for converting an image into editable text while maintaining its layout according to claim 1, characterized in that, In step S20, for the pure table type data in the first JSON data, each cell of the drawn table corresponds to each cell object in the pure table type data in the first JSON data, and multiple cells form a complete table.
5. The method for converting an image into editable text while maintaining its layout according to claim 1, characterized in that, In step S20, for mixed-type data in the first JSON data, plain text subtype data is generated into rich text paragraphs in the combo box, with different attribute parts of the rich text paragraphs serving as different plain text rich text objects; plain image subtype data is generated into a plain image rich text object in the combo box, and this plain image rich text object belongs to a certain rich text paragraph; plain table subtype data is generated into a plain table rich text object in the combo box, and this plain table rich text object belongs to a certain rich text paragraph; the vertical position of each rich text paragraph is determined according to the paragraph spacing field in the mixed-type data in the first JSON data; the left and right positions of each rich text paragraph are determined according to the paragraph indentation field in the mixed-type data in the first JSON data.
6. The method for converting an image into editable text while maintaining its layout according to claim 1, characterized in that, In step S30, the edited graphical interface may be the same as or different from the editable graphical interface output in step S20.
7. The method for converting an image into editable text while maintaining its layout according to claim 1, characterized in that, In step S30, for the combo boxes in the edited graphical interface, the value of each sub-model corresponding to the second JSON data sub-object is determined by the current attribute value of the rich text object.
8. A device for converting an image into editable text while preserving its layout, characterized in that, It includes a first conversion unit, a second conversion unit, a third conversion unit, and a fourth conversion unit; The first conversion unit is used to convert the image into first JSON data; the data type of the first JSON data includes any one or more of plain text, plain image, plain table, and mixed data; the mixed data type includes any one or more of the data subtypes of plain text, plain image, and plain table. The second conversion unit is used to convert the first JSON data into an editable graphical interface. For plain text data in the first JSON data, rich text objects with corresponding content are created on the editable graphical interface, with paragraphs as the unit. For image data in the first JSON data, images with corresponding content are generated on the editable graphical interface. For table data in the first JSON data, a blank view is first created on the editable graphical interface, and then tables with corresponding content are drawn on the blank view based on the table data in the first JSON data. For mixed-type data in the first JSON data, a combo box is first created on the editable graphical interface, and then rich text objects with corresponding content are generated within the combo box based on whether the subtype of the mixed-type data is plain text, plain image, or plain table. When the user edits within the combo box, all rich text objects within the combo box can be selected to enable editing operations across rich text paragraphs. The third conversion unit is used to convert the edited graphical interface into second JSON data. For each plain text rich text object in the edited graphical interface, a corresponding plain text type model corresponding to the second JSON data object is generated. For each image in the edited graphical interface, a corresponding image type model corresponding to the second JSON data object is generated. For each table in the edited graphical interface, a corresponding table type model corresponding to the second JSON data object is generated. For each combo box in the edited graphical interface, each rich text object in the combo box is traversed, and each rich text object is used to generate corresponding plain text, plain image, or plain table sub-type models corresponding to the second JSON data sub-objects according to its type (text, image, or table). All the sub-models corresponding to the second JSON data sub-objects generated by all the rich text objects in a combo box are combined to form a model corresponding to the mixed type of second JSON data object. All the models corresponding to the second JSON data object are combined to form the second JSON data. The fourth conversion unit is used to convert the second JSON data into editable text.
Citation Information
Patent Citations
Rich text editing method and system
CN105843787A
Customs clearance data generation system and method based on image and text identification
CN108960054A
