HTML file generation method and device, electronic equipment and storage medium
By extracting primitives and primitive values from PDF files and generating text HTML elements, the problem of information loss when converting PDFs to HTML files is solved, improving the accuracy of HTML files and reducing resource consumption.
Patent Information
- Application Number
- CN202310566471.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-18
- Publication Date
- 2024-11-22
AI Technical Summary
Existing technologies for converting PDF files to HTML files are prone to information loss, resulting in poor accuracy of HTML files.
By obtaining primitives and primitive values from the PDF file, the target elements and their attributes are determined, text HTML elements are generated, and HTML files are generated using a pre-set template, thus avoiding resolution loss caused by rendering text information as images.
It reduces data loss in HTML files, improves the accuracy of HTML files, and reduces resource consumption and processing time.
Smart Images

Figure CN119005126A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic information technology, and more specifically, to an HTML file generation method, device, electronic device and storage medium. Background Art
[0002] Accessing web pages through a client has become one of the important means used when people search for information. Usually, the client receives an HTML (Hyper Text Markup Language) file returned by the server, and then the client loads the HTML file to access the web page.
[0003] Currently, it is possible to obtain a PDF (portable document format, a file entity of the ISO 32000 protocol and its derivative protocols) file containing web page information, render the PDF file into images by page, and then convert the rendered images to obtain an HTML file. However, using this method to convert PDF files is prone to information loss, resulting in poor accuracy of the obtained HTML file. Summary of the invention
[0004] In view of this, the embodiments of the present application propose an HTML file generation method, device, electronic device and storage medium.
[0005] In a first aspect, an embodiment of the present application provides a method for generating an HTML file, the method comprising: obtaining a PDF file to be processed; if the PDF file to be processed includes text information, obtaining primitives and primitive values of the primitives from the text information; determining a target element and element attributes of the target element based on the primitives and the primitive values of the primitives; the target element includes a text element and / or a graphic element; determining a text HTML element based on the target element and the element attributes of the target element; and generating an HTML file based on a preset template and the text HTML element.
[0006] In a second aspect, an embodiment of the present application provides an HTML file generation device, the device comprising: a first acquisition module, used to acquire a PDF file to be processed, the PDF file to be processed comprising text information and image information; a second acquisition module, used to acquire primitives and primitive values of primitives from the text information if the PDF file to be processed comprises text information; a first determination module, used to determine a target element and element attributes of the target element based on the primitive and the primitive value of the primitive; the target element comprises a text element and / or a graphic element; a second determination module, used to determine a text HTML element based on the target element and the element attributes of the target element; a generation module, used to generate an HTML file based on a preset template and a text HTML element.
[0007] Optionally, the first determination module is also used to obtain a first primitive and a second primitive from the primitive; the first primitive is a primitive of a first instruction category, and the second primitive is a primitive of a second instruction category; determine the target element according to the primitive value of the first primitive; and determine the element attribute of the target element according to the primitive value of the second primitive.
[0008] Optionally, the target element includes a text element; the first determination module is further used to obtain a second primitive corresponding to the text element from the second primitive as a text attribute primitive; obtain a symbol code from the primitive value of the text attribute primitive as a target symbol code for the text element; obtain a text style corresponding to the target symbol code of the text element from a text style library as a target text style of the text element; the text style library includes text styles corresponding to different symbol codes; obtain text posture information, text color and text size of the text element from the primitive value of the text attribute primitive; obtain text posture information, text color, text size and target text style as element attributes of the text element.
[0009] Optionally, the second determination module is also used to determine the bounding box of the text element based on the text posture information and text size of the text element; merge each text element according to the bounding box of each text element to obtain at least one text element string, each text element string including at least one text element; determine the HTML data of each text element string according to each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size and text color of each text element in each text element string; obtain and summarize the HTML data of each text element string to obtain a text HTML element.
[0010] Optionally, the second determination module is also used to determine the comparison results of each text element and the visible range of each text element; determine the text display style of each text element based on the comparison results; determine the HTML data of each text element string based on each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size, text color and text display style of each text element in each text element string.
[0011] Optionally, the text elements are arranged in sequence; the second determination module is also used to combine any two adjacent text elements if their bounding boxes overlap after translation along the target direction, so as to obtain at least one initial text element string; and adjust the spacing between any adjacent text elements in each initial text element string according to the placeholder to obtain the text element string corresponding to each initial text element string.
[0012] Optionally, the target element includes a graphic element, and the graphic element includes a line element and a fill element; the first determination module is also used to obtain a second primitive corresponding to the line element from the second primitive as a line attribute primitive; determine the line color, line shape, line width and line path of the line element according to the primitive value of the line attribute primitive as element attributes of the line element; obtain the second primitive corresponding to the fill element from the second primitive as a fill attribute primitive; determine the fill color, fill shape and fill path of the fill element according to the primitive value of the fill attribute primitive as element attributes of the fill element.
[0013] Optionally, the graphic elements include line elements, fill elements and table elements; the first determination module is further used to determine the element attributes of the line elements and the element attributes of the fill elements according to the primitive value of the second primitive; the element attributes of the line elements include the line shape of the line elements, and the element attributes of the fill elements include the fill area of the fill elements; if there are multiple intersecting straight line elements, the multiple intersecting straight line elements are merged to obtain a table element, and the bounding box of the table element is determined; the straight line element refers to a line element whose line shape is a straight line in the element attributes; if there is a target fill element, the element attributes of the target fill element and the element attributes of each straight line element in the table element are obtained as the element attributes of the table element; the target fill element refers to a fill element whose fill area matches the bounding box of the table element; if there is no target fill element, the element attributes of each straight line element in the table element are obtained as the element attributes of the table element.
[0014] Optionally, the second determination module is also used to determine the first tag according to the element attributes of the target fill element if the target element is a table element, determine the second tag according to the element attributes of each straight line element in the table element, add the first tag to the second tag as a subtag to obtain a third tag, and obtain a text HTML element according to the third tag; if the target element is a fill element, determine the fourth tag according to the element attributes of the fill element, and obtain a text HTML element according to the fourth tag; if the target element is a line element, determine the fifth tag according to the element attributes of the line element, and obtain a text HTML element according to the fifth tag.
[0015] Optionally, the generation module is further used to map the image information through a preset two-dimensional affine matrix to obtain an image HTML element if the PDF file to be processed also includes image information; and generate an HTML file according to a preset template, text HTML elements and image HTML elements.
[0016] Optionally, the generation module is also used to read the binary stream of the image information, obtain the reading result, map the reading result to the target space through a preset two-dimensional affine matrix, and obtain a mapping result; convert the mapping result into a preset format to obtain a conversion result; and determine the image HTML element according to the conversion result.
[0017] Optionally, the generation module is further used to determine the mapping result and the comparison result of the visible range corresponding to the image information; determine the image display style according to the comparison result; and obtain the image HTML element according to the conversion result and the image display style.
[0018] Optionally, the text HTML element includes an HTML tag and a cascading style sheet corresponding to the HTML tag; the generating module is further used to generate an HTML file according to a preset template, HTML tag and cascading style sheet.
[0019] In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory; one or more programs are stored in the memory and configured to be executed by the processor to implement the above method.
[0020] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a program code is stored, wherein the above method is executed when the program code is executed by a processor.
[0021] In a fifth aspect, an embodiment of the present application provides a computer program product or a computer program, the computer program product or the computer program including computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device performs the above method.
[0022] An embodiment of the present application provides an HTML file generation method, device, electronic device and storage medium. In the present application, when the text information included in the PDF file to be processed is processed, the primitives and primitive values of the primitives obtained in the text information are processed to generate text HTML elements, and then the HTML file is generated according to the text HTML elements and the preset template, thereby avoiding information loss caused by resolution loss when rendering the text information as an image, thereby greatly reducing the occurrence of data loss in the obtained HTML file and improving the accuracy of the HTML file. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0024] Figure 1 A schematic diagram showing an application scenario to which the embodiments of the present application are applicable;
[0025] Figure 2 A schematic diagram of the interaction process between a terminal and a server in an embodiment of the present application is shown;
[0026] Figure 3 A flowchart of a method for generating an HTML file proposed in one embodiment of the present application is shown;
[0027] Figure 4 A schematic diagram of the structure of a PDF file to be processed in an embodiment of the present application is shown;
[0028] Figure 5 A flowchart of a method for generating an HTML file proposed in another embodiment of the present application is shown;
[0029] Figure 6 A flowchart of a method for generating an HTML file proposed in another embodiment of the present application is shown;
[0030] Figure 7 A flowchart of a method for generating an HTML file proposed in another embodiment of the present application is shown;
[0031] Figure 8 A schematic diagram showing a processing process of a PDF file to be processed in an embodiment of the present application;
[0032] Fig. 9 A schematic diagram of the structure of a local file conversion system in an embodiment of the present application is shown;
[0033] Fig.10 A schematic diagram showing a process of reading a PDF file to be processed in an embodiment of the present application is shown;
[0034] Fig.11 A schematic diagram showing a text element extraction process in an embodiment of the present application;
[0035] Fig.12 A schematic diagram showing a process of extracting line elements in an embodiment of the present application is shown;
[0036] Fig.13 A schematic diagram showing a process of extracting a filling element in an embodiment of the present application is shown;
[0037] Fig.14 A schematic diagram showing a process of extracting table elements in an embodiment of the present application is shown;
[0038] Fig.15 A schematic diagram showing a process of obtaining a text HTML element corresponding to a text element in an embodiment of the present application is shown;
[0039] Fig.16 A schematic diagram of a process of obtaining text HTML elements corresponding to a line element, a fill element, and a table element in an embodiment of the present application is shown;
[0040] Fig.17 A schematic diagram showing a process of obtaining a picture HTML element corresponding to picture information in an embodiment of the present application is shown;
[0041] Fig.18 A block diagram of an HTML file generating device proposed in one embodiment of the present application is shown;
[0042] Fig.19 A structural block diagram of an electronic device for executing the HTML file generation method according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. According to the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0044] In the following description, the terms "first\second" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0045] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0046] It should be noted that the "multiple" mentioned in this article refers to two or more. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship.
[0047] It should also be noted that in the embodiments of the present application, the acquisition of information such as the user's job type, education level, age, life stage (for example, whether married), work location, and favorite products requires the user's permission or consent, and the collection, use, processing, and storage of information such as the user's job type, education level, age, life stage (for example, whether married), work location, and favorite products must comply with the regulations of the region where the user is located.
[0048] The present application discloses an HTML file generation method, device, electronic device and storage medium, and relates to cloud technology, etc.
[0049] Cloud technology refers to a hosting technology that unifies hardware, software, network and other resources within a wide area network or local area network to achieve data computing, storage, processing and sharing.
[0050] Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, which can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The backend services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the rapid development and application of the Internet industry, in the future, each item may have its own identification mark, which needs to be transmitted to the backend system for logical processing. Data of different levels will be processed separately. All kinds of industry data need strong system backing support, which can only be achieved through cloud computing.
[0051] Cloud storage is a new concept that extends and develops from the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as storage system) refers to a storage system that uses cluster applications, grid technology, and distributed storage file systems to bring together a large number of different types of storage devices (storage devices are also called storage nodes) in the network through application software or application interfaces to work together and provide external data storage and business access functions.
[0052] At present, the storage method of the storage system is: create a logical volume, and when creating a logical volume, allocate physical storage space for each logical volume. The physical storage space may be composed of disks of a storage device or several storage devices. The client stores data on a logical volume, that is, stores the data on the file system. The file system divides the data into many parts, each of which is an object. The object contains not only data but also additional information such as data identification (ID, ID entity). The file system writes each object into the physical storage space of the logical volume, and the file system records the storage location information of each object, so that when the client requests to access the data, the file system can allow the client to access the data according to the storage location information of each object.
[0053] The process of the storage system allocating physical storage space to a logical volume is as follows: based on the estimated capacity of the objects stored in the logical volume (this estimate often has a large margin relative to the actual capacity of the objects to be stored) and the grouping of independent redundant disk arrays (RAID, Redundant Array of Independent Disks), the physical storage space is pre-divided into stripes. A logical volume can be understood as a stripe, thereby allocating physical storage space to the logical volume.
[0054] In addition to the methods of the background technology, the text content and text position in the PDF file can also be extracted, and the text can be embedded into an HTML editor for editing according to the extracted text content and text position to obtain an HTML file. However, using this method, the original layer information (which may include images, lines, fills, tables, etc.) in the PDF file is lost, resulting in a low accuracy rate of the generated HTML file.
[0055] In order to avoid data loss during the generation of HTML files and improve the accuracy of the generated HTML files, the inventors have proposed an HTML file generation method, device, electronic device and storage medium after long-term research. The text information included in the PDF file to be processed is processed to generate a text HTML element, and the image information included in the PDF file to be processed is processed to generate an image HTML element, thereby avoiding information loss caused by resolution loss caused by rendering text information as an image, and also avoiding the loss of layer information caused by processing only text information, thereby greatly reducing the occurrence of data loss in the obtained HTML file and improving the accuracy of the HTML file.
[0056] At the same time, it avoids the situation where the resource consumption of image processing is high when rendering text information as images, reduces the resource and time consumption of the processing process of the PDF file to be processed, and improves the efficiency of the generated HTML file.
[0057] like Figure 1 As shown, the application scenario applicable to the embodiment of the present application includes a terminal 20 and a server 10, and the terminal 20 and the server 10 are connected through a wired network or a wireless network. The terminal 20 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart home appliance, a vehicle terminal, an aircraft, a wearable device terminal, a virtual reality device, and other terminal devices that can display pages, or run other applications that can call page display applications (such as instant messaging applications, shopping applications, search applications, game applications, forum applications, map traffic applications, etc.).
[0058] The server 10 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server 10 may be used to provide services for applications running on the terminal 20.
[0059] Among them, the terminal 20 can send a PDF file to be processed to the server 10, and the server 10 can receive the PDF file to be processed, obtain text HTML elements according to the text information in the PDF file to be processed, and obtain image HTML elements according to the image information in the PDF file to be processed. Then, the server 10 obtains the HTML file according to the preset template, text HTML elements and image HTML elements. After that, the server 10 can perform customized operations according to the HTML file. The customized operations can, for example, be the display time and display effect of the customized HTML file.
[0060] In some possible implementations, the terminal 20 can directly obtain the text HTML element based on the PDF file to be processed and the text information in the PDF file to be processed, and obtain the image HTML element based on the image information in the PDF file to be processed. Then, the server 10 obtains the HTML file based on the preset template, the text HTML element and the image HTML element. After that, the terminal 20 can send the HTML file to the server 10, and the server 10 performs customized operations based on the HTML file.
[0061] like Figure 2As shown, the user can upload or reference the PDF file to be processed to the terminal 20, the terminal 20 sends the PDF file to be processed to the server 10, and the server 10 returns the HTML file to the terminal 20. The terminal 20 performs a customized operation on the HTML file to obtain the operation result, and then the terminal 20 displays the relevant interface corresponding to the operation result, thereby achieving the effect of displaying the relevant interface according to the PDF file to be processed.
[0062] Optionally, the server 10 may store the acquired HTML file in a cloud storage system. When executing the HTML file generation method of the present application, the terminal 20 acquires the HTML file from the cloud storage system so that the terminal 20 can perform customized operations.
[0063] For the convenience of description, in the following embodiments, the generation of HTML files by electronic devices is used as an example for description.
[0064] See also Figure 3 , Figure 3 A flowchart of a method for generating an HTML file according to an embodiment of the present application is shown. The method can be applied to an electronic device, which can be Figure 1 The terminal 20 or the server 10 in the embodiment of the present invention comprises:
[0065] S110, obtaining a PDF file to be processed.
[0066] In this embodiment, the PDF file to be processed may refer to a PDF file used to generate an HTML file. The PDF file may include multiple pages, and each page may include text information and / or image information. That is, the PDF file to be processed may include only image information, the PDF file to be processed may include only text information, or the PDF file to be processed may include both text information and image information. For example, a PDF file includes 10 pages, of which, except for page 9 which is image information, the other 9 pages are all text information. The text information may include text, characters, etc., and the image information may include grayscale images or color images in any format. For example, the image information may include an RGB image of a vehicle.
[0067] As a possible implementation, Figure 4 As shown, the PDF file to be processed is a structure of an index tree, the root node is the name or number of the PDF file to be processed, the page tree can be the directory of the PDF file to be processed, and is used to index each page of the PDF file to be processed. The contents of the PDF file to be processed are isolated from each other by page (in Figure 4The content stream is the main carrier of the content of the PDF file to be processed. Each page in the PDF file to be processed can be decoded to obtain the content stream of the PDF file to be processed. The obtained content stream includes the resource index and content index of each page. Among them, the resource index refers to the resources in each page content that cannot be written in plain text on the PDF file to be processed. It is a compressed binary stream (including text information and image information) used by the PDF file to be processed; the content index refers to the resources (including text information and image information) that can be written in plain text on the PDF file to be processed. For example, graphic elements can include straight lines, curved lines, circular fills, rectangular fills, and color tables, etc.
[0068] After decoding of all pages of the PDF file to be processed is completed, all text information and / or image information corresponding to the PDF file to be processed is obtained.
[0069] S120: If the PDF file to be processed includes text information, obtain primitives and primitive values of the primitives from the text information.
[0070] The so-called primitive refers to a program segment composed of several instructions, which is used to implement a specific function and cannot be interrupted during execution. The value of the primitive refers to the specific instruction content of the several instructions that make up the primitive. For example, the primitive in this embodiment may include a text color rendering instruction, a text size rendering instruction, and a text font rendering instruction. Correspondingly, the value of the primitive may include the value corresponding to the text color rendering instruction (for example, rendering text in red), the value of the text size rendering instruction (for example, rendering text in size 3), and the value of the text font rendering instruction (for example, rendering text in Songti).
[0071] That is, the text information in the PDF file to be processed may be a PDF instruction. The PDF instruction may be directly extracted from the text information included in the PDF file to be processed, and the primitive and the primitive value of the primitive may be determined according to the extracted PDF instruction.
[0072] S130. Determine a target element and element attributes of the target element according to the primitive and the primitive value of the primitive; the target element includes a text element and / or a graphic element.
[0073] Among them, text elements can be texts in any language and format, for example, the text can be Chinese characters or English; the element attributes of text elements can refer to the text style of the text elements (the text style can be, for example, a font), text color, text size and text posture information (the text posture information can include the coordinates of the text in the PDF file to be processed and the text element spacing of the text elements); graphic elements can include line elements, fill elements and table elements, etc. The element attributes of line elements can include line color, line shape, line width and line path (the line path can refer to the specific path of the line, which can be determined by the starting point and the end point of the line), the element attributes of fill elements can include fill color, fill shape and fill path (the fill path can refer to the specific fill path, which can be determined by the boundary line of the fill element), and the element attributes of table elements can include element attributes of straight lines constituting the table and element attributes of fill elements of fill areas in the table elements.
[0074] After the primitive and the primitive value of the primitive are obtained from the text information, the target element can be determined according to the primitive, and the element attribute of the target element can be determined according to the primitive value of the primitive.
[0075] For example, based on the primitives including "text color rendering instructions", "text size rendering instructions" and "text font rendering instructions", it is determined that the target element is a text element, and the values corresponding to the text color rendering instructions (for example, rendering text in red), the values of the text size rendering instructions (for example, rendering text in size 3) and the values of the text font rendering instructions (for example, rendering text in Songti) are summarized as element attributes of the text element.
[0076] For another example, based on the primitives including "line color rendering instructions", "line shape rendering instructions" and "line thickness rendering instructions", the target element is determined to be a line element, and the values corresponding to the line color rendering instructions (for example, rendering the line as red), the values of the line shape rendering instructions (for example, rendering the line as a straight line) and the values of the line thickness rendering instructions (for example, rendering the line as a 0.5mm line) are summarized as element attributes of the line element.
[0077] As a possible implementation, S130 may include: obtaining a first primitive and a second primitive from the primitive; the first primitive is a primitive of a first instruction category, and the second primitive is a primitive of a second instruction category; determining a target element according to the primitive value of the first primitive; and determining an element attribute of the target element according to the primitive value of the second primitive.
[0078] In this embodiment, the primitive of the first instruction category may refer to an instruction primitive. The instruction primitive may refer to Table 1, which is as follows:
[0079] Table 1
[0080] PDF Instructions explain W / W* The clip state has changed, and the HTML output clip state needs to be changed at the same time Tj Indicates that text needs to be output Do There are pictures that need to be rendered and output f / f* / S (f fill, S line) There are fills / shapes that need to be exported
[0081] The PDF instructions in Table 1 refer to the primitives of the instruction category. Clip refers to the mask in the PDF file to be processed, which may include the respective visible ranges of text elements and image elements, which will be described below and will not be repeated here.
[0082] In this embodiment, the primitive of the second instruction category may refer to the primitive of the state category. The primitive of the state category may refer to Table 2, which is as follows:
[0083] Table 2
[0084]
[0085]
[0086] The target element can be determined directly according to the primitive value of the first primitive, and the primitive value of the second primitive can be obtained as the specific element attribute of the target element.
[0087] It can be understood that the first primitive includes the first primitives of different target elements. For text elements, the primitive value of the first primitive of the text element (such as the Tj instruction in Table 1) can be obtained as the text element itself, and the second primitive corresponding to the text element (such as the primitives corresponding to the instructions such as Td, Tz, Tw and Tc in Table 2) can be determined, and the primitive value of the second primitive of the text element can be used as the element attribute of the text element; for line elements, the primitive value of the first primitive of the line element (such as the S instruction in Table 1) can be obtained as the line element itself, and the second primitive corresponding to the line element (such as the RG, l and m instructions in Table 2) can be determined. For the filling element, the primitive value of the first primitive of the filling element (such as the f and f* instructions in Table 1) can be obtained as the filling element itself, and the second primitive corresponding to the filling element (such as the primitive corresponding to the instruction symbols rg, v and y in Table 2) can be determined, and the primitive value of the second primitive of the filling element can be used as the element attribute of the filling element; for the table element, the filling elements that constitute the table and the element attributes of the filling elements can be determined as the element attributes of the table element.
[0088] Usually, the poppler link library can be used to monitor the primitives (also referred to as PDF instructions in this application) in the PDF file to be processed. By monitoring the PDF instructions, the PDF instructions of the status category are recorded and maintained, and an instruction callback is added at the PDF instructions of the instruction category. When the PDF instructions of the instruction category are monitored, the target element corresponding to the PDF instructions of the instruction category can be determined, and the element attribute corresponding to the PDF instructions of the status category can be determined. The processing module corresponding to the text information is called through the instruction callback to perform the subsequent steps of determining the text HTML element according to the target element and the element attribute of the target element.
[0089] S140: Determine a text HTML element according to the target element and the element attribute of the target element.
[0090] As an implementation method, a text HTML tag may be generated based on the text element and the element attributes of the text element. The text HTML tag may include the text element and the element attributes of the text element. For example, the generated text HTML tag may include the text element "d1" and the element attributes of the text element corresponding to "d1", "Songti, red, font size 3, and text posture D1".
[0091] As another implementation, a text HTML tag and a text CSS stream (Cascading Style Sheets) file may be generated based on the text element and the element attributes of the text element, and the generated HTML tag and the text CSS stream file may be used as a text HTML element. The text HTML tag may include the text element and the text element attribute identifier of the text element, and the text CSS stream stores the element attributes of the text element corresponding to different text element attribute identifiers. For example, the generated text HTML tag may include the text element "d1" and the text element attribute identifier d2 corresponding to "d1", and the element attribute corresponding to the text element attribute identifier d2 in the text CSS stream file is "Songti, red, font size 3 and text posture D1".
[0092] Similarly, a filling HTML tag can be generated based on the filling element and the element attributes of the filling element. The filling HTML tag may include the filling element and the element attributes of the filling element. For example, the generated filling HTML tag may include the filling element "d3" and the element attributes of the filling element corresponding to "d3", "straight line, red, width 0.5mm and filling path D2". A filling HTML tag and a filling CSS stream file may also be generated based on the filling element and the element attributes of the filling element. The generated HTML tag and the filling CSS stream file are used as text HTML elements. Among them, the filling HTML tag may include the filling element and the filling element attribute identifier of the filling element, and the filling CSS stream stores the element attributes of the filling element corresponding to different filling element attribute identifiers. For example, the generated filling HTML tag may include the filling element "d3" and the filling element attribute identifier d4 corresponding to "d3". The element attribute corresponding to the filling element attribute identifier d4 in the filling CSS stream file is "straight line, red, width 0.5mm and filling path D2".
[0093] Similarly, a filling HTML tag can be generated based on the filling element and the element attributes of the filling element. The filling HTML tag may include the filling element and the element attributes of the filling element. For example, the generated filling HTML tag may include the filling element "d5" and the element attributes of the filling element corresponding to "d5", "straight line, green, and filling path D3". A filling HTML tag and a filling CSS stream file may also be generated based on the filling element and the element attributes of the filling element. The generated HTML tag and the filling CSS stream file are used as text HTML elements. Among them, the filling HTML tag may include the filling element and the filling element attribute identifier of the filling element, and the filling CSS stream stores the element attributes of the filling element corresponding to different filling element attribute identifiers. For example, the generated filling HTML tag may include the filling element "d5" and the filling element attribute identifier d6 corresponding to "d5", and the element attribute corresponding to the filling element attribute identifier d6 in the filling CSS stream file is "straight line, green, and filling path D3".
[0094] Similarly, a table HTML tag can be generated based on the table element and the element attributes of the table element. The table HTML tag can include the table element and the element attributes of the table element. For example, the generated table HTML tag can include the table element "d7" and the element attributes of the table element corresponding to "d7" include the element attribute D4 of the straight line filling in the table element and the element attribute D5 of the filling element in the table element. The table HTML tag and the table CSS stream file can also be generated based on the table element and the element attributes of the table element. The generated HTML tag and the table CSS stream file are used as text HTML elements. Among them, the table HTML tag can include the table element and the table element attribute identifier of the table element, and the table CSS stream stores the element attributes of the table element corresponding to different table element attribute identifiers. For example, the generated table HTML tag can include the table element "d7" and the table element attribute identifier d8 corresponding to "d7". The element attributes corresponding to the table element attribute identifier d8 in the table CSS stream file include the element attribute D4 of the straight line filling in the table element and the element attribute D5 of the filling element in the table element.
[0095] As an implementation method, the primitive value of the primitive of the second instruction category can be recorded through a state recording function to obtain the element attributes of the target element, and the primitive of the first instruction category can be monitored. When the primitive of the first instruction category is monitored, step S140 is executed to obtain the text HTML element corresponding to the target element.
[0096] S150: Generate an HTML file according to a preset template and text HTML elements.
[0097] The preset template may be a template set based on demand. The preset template includes a filling position for a text HTML element. The text HTML element is directly written into the corresponding filling position to obtain an HTML file.
[0098] Among them, the filling position of the text HTML element may include the filling position of the text HTML element corresponding to the text element, the filling position of the text HTML element corresponding to the line element, the filling position of the text HTML element corresponding to the filling element and the filling position of the text HTML element corresponding to the table element. The text HTML element corresponding to the text element, the text HTML element corresponding to the line element, the text HTML element corresponding to the filling element and the text HTML element corresponding to the table element are written into the corresponding filling positions respectively to obtain an HTML file.
[0099] As an implementation mode, as described above, the text HTML element includes an HTML tag and a cascading style sheet corresponding to the HTML tag (i.e., the CSS stream file mentioned above), and S150 may include: generating an HTML file according to the preset template, the HTML tag, and the cascading style sheet. That is, according to the HTML tag and the cascading style sheet of the target element, the target element may be filled into the filling position of the text HTML element of the preset template to obtain the HTML file.
[0100] In this embodiment, when the PDF file to be processed includes text information, the primitives obtained from the text information and the primitive values of the primitives are processed to generate text HTML elements, and then the HTML file is generated according to the text HTML elements and the preset template, thereby avoiding information loss caused by resolution loss when rendering the text information as an image, thereby greatly reducing the occurrence of data loss in the obtained HTML file and improving the accuracy of the HTML file.
[0101] See also Figure 5 , Figure 5 A flowchart of a method for generating an HTML file according to another embodiment of the present application is shown. The method can be applied to an electronic device, which can be Figure 1 The terminal 20 or the server 10 in the embodiment of the present invention comprises:
[0102] S210, obtaining a PDF file to be processed; if the PDF file to be processed includes text information, obtaining a primitive and a primitive value of the primitive from the text information; obtaining a first primitive and a second primitive from the primitive; and determining a target element according to the primitive value of the first primitive.
[0103] The description of S210 refers to the description of S110 to S130 above, and will not be repeated here.
[0104] S220. Obtain the second primitive corresponding to the text element from the second primitive as a text attribute primitive; obtain the symbol code from the primitive value of the text attribute primitive as a target symbol code for the text element; obtain the text style corresponding to the target symbol code of the text element from the text style library as the target text style of the text element; the text style library includes text styles corresponding to different symbol codes; obtain text posture information, text color and text size of the text element from the primitive value of the text attribute primitive; obtain the text posture information, text color, text size and target text style as element attributes of the text element.
[0105] As described above, the second primitive corresponding to the text element may include primitives corresponding to the Td, Tz, Tw and Tc directives in Table 2. The text style library may include a resource dictionary and a local font library, and both the resource dictionary and the local font library include text styles corresponding to different symbol codes; the target text style may be indexed in the resource dictionary by the target symbol code, and if the target text style is indexed, the target text style is obtained, and if the target text style is not indexed, the target text style is obtained from the local font library, and after obtaining the target text style, the text posture information, text color and text size of the text element may be obtained from the text attribute primitive, and then the text posture information, text color, text size and target text style are summarized as element attributes of the text element.
[0106] S230, determining the bounding box of the text element according to the text posture information and the text size of the text element; merging the text elements according to the bounding boxes of the text elements to obtain at least one text element string, each text element string including at least one text element.
[0107] A bounding box may refer to a rectangular box used to wrap a text element, which is represented by the coordinates of the upper left corner and the lower right corner; one text element corresponds to one bounding box. The text size of the text element may be obtained first, and the bounding box of the text element may be determined according to the text posture information and the text size in the element attributes of the text element.
[0108] Whether each text element can be merged can be determined based on the bounding box of each text element. If there are text elements that can be merged, then the text elements that can be merged are merged to obtain a text element string. For text elements that cannot be merged, they themselves are regarded as a text element string.
[0109] As an implementation method, each text element is arranged in order; the process of merging text elements may include: if the bounding boxes of any two adjacent text elements overlap after translation along the target direction, any two adjacent text elements are combined to obtain at least one initial text element string; the spacing between any adjacent text elements in each initial text element string is adjusted according to the placeholder to obtain a text element string corresponding to each initial text element string. Among them, the arrangement order of the text elements is the reading order of the text elements themselves or the arrangement order of the text elements in the generated PDF file to be processed.
[0110] If the text elements are arranged in rows, the target direction is horizontal; if the text elements are arranged in columns, the target direction is vertical. After combining any two adjacent text elements, an initial text element string is obtained. The number of padding characters (span) can be determined according to the character spacing in the text pose information of the text elements, and the determined padding characters are filled between any two adjacent text elements to adjust the spacing between any two adjacent text elements and obtain an adjusted text element string.
[0111] For example, for adjacent characters "我", "们", "要", "去", "哪", and "走", for any two adjacent text elements, if their bounding boxes can coincide after translation in the horizontal direction, they are merged; if their bounding boxes cannot coincide after translation in the horizontal direction, they are not merged. Thus, the obtained initial text element strings are "我们要去哪" and "走" respectively. At this time, the padding characters to be added to the initial text element string can be determined according to the text spacing between any two adjacent text elements in the initial text element string, and the spacing between each character element in "我们要去哪" is adjusted by the padding characters to obtain the text element string "我span们span要span去span哪".
[0112] S240. Determine the HTML data of each text element string according to each text element string, the text element spacing between adjacent text elements in each text element string, the text pose information, text style, text size, and text color of each text element in each text element string; obtain and summarize the HTML data of each of the above-mentioned text element strings to obtain a text HTML element.
[0113] After obtaining the text element string, determine the HTML data of each text element string according to each text element string, the text pose information, text style, text size, and text color of each text element in each text element string. The HTML data of each text element string may include the HTML data of each text element in the text element string. The HTML data of each text element may include a text HTML tag, and the text HTML tag may be as shown in Table 3. Table 3 is as follows:
[0114] Table 3
[0115] Text related information Corresponding HTML style FontInfo: Fonts font-family FontInfo: Font size font-size FontInfo: Character Color color Text Position: Bounding Box left, bottom Text Char Space: Text element spacing char spacing Text Word Space: Text element space word-spacing
[0116] Among them, the text element space in Table 3 may be the text pose information of the text element, which is used to indicate the position information of the text element.
[0117] The text HTML tag obtained according to the steps of S240 may be: <div class=text style of the text element>text or span placeholder.
[0118] As an implementation mode, determining the HTML data of each text element string according to each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size and text color of each text element in each text element string includes: determining the comparison result of each text element and the visible range of each text element; determining the text display style of each text element according to the comparison result; determining the HTML data of each text element string according to each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size, text color and text display style of each text element in each text element string. .
[0119] The visible range of a text element may refer to a mask corresponding to the text element in the PDF file to be processed. The mask means that any element exceeding the specified rectangular range will be hidden. The comparison result includes the comparison result of each text element with the visible range of each text element. The comparison result may specifically include that the text element is within the visible range or that the text element is not within the visible range. If the comparison result is that the text element is within the visible range, its text display style is determined to be normal display. If the comparison result is that the text element is not within the visible range, its text display style is determined to be transparent display.
[0120] Finally, the HTML data of each text element string can be determined based on each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size, text color and text display style of each text element in each text element string. The HTML data of each text element string includes the text HTML tags of each text element.
[0121] After obtaining the HTML data of each text element string, the HTML data of each text element string are aggregated to obtain a text HTML element, which is a text HTML element corresponding to the text element.
[0122] S250: Determine the text HTML element corresponding to the graphic element according to the graphic element and the element attribute of the graphic element; generate an HTML file according to the preset template and the text HTML element.
[0123] The description of S250 refers to the description of S140-S150 above and will not be repeated here.
[0124] In this embodiment, the text HTML element corresponding to the text element is accurately determined based on the text element and the element attribute of the text element, avoiding the occurrence of inaccurate text HTML element due to the loss of the text element, thereby improving the accuracy of the generated HTML file.
[0125] See also Figure 6 , Figure 6 A flowchart of a method for generating an HTML file according to another embodiment of the present application is shown. The method can be applied to an electronic device, which can be Figure 1 The terminal 20 or the server 10 in the embodiment of the present invention comprises:
[0126] S310, obtaining a PDF file to be processed; if the PDF file to be processed includes text information, obtaining a primitive and a primitive value of the primitive from the text information; obtaining a first primitive and a second primitive from the primitive; determining a target element according to the primitive value of the first primitive; determining a text HTML element corresponding to the text element according to the text element and the element attribute of the text element.
[0127] The description of S210 refers to the description of S110 - S130 and S210 - S240 above, and will not be repeated here.
[0128] S320. Determine element attributes of the line element and element attributes of the fill element according to the primitive value of the second primitive.
[0129] In this embodiment, a second primitive corresponding to the line element can be obtained from the second primitive as a line attribute primitive; according to the primitive value of the line attribute primitive, the line color, line shape, line width and line path of the line element are determined as element attributes of the line element; wherein, the second primitive corresponding to the line element can refer to the primitive corresponding to the instruction symbols such as RG, l and m in Table 2.
[0130] At the same time, a second primitive corresponding to the filling element is obtained from the second primitive as a filling attribute primitive; and according to the primitive value of the filling attribute primitive, the filling color, filling shape and filling path of the filling element are determined as element attributes of the filling element. The second primitive corresponding to the filling element may refer to the primitives corresponding to the directives such as rg, v and y in Table 2.
[0131] S330. If there are multiple intersecting straight line elements, merge the multiple intersecting straight line elements to obtain a table element, and determine the boundary box of the table element; the straight line element refers to a line element whose line shape in the element attribute is a straight line.
[0132] According to the line shapes of the line elements determined in S320, the line elements with straight line shapes can be used as straight line elements, and it can be determined whether the straight line elements intersect. If they intersect, the intersecting straight line elements are merged to obtain a table element. The bounding box of the table element refers to a rectangular box that selects the table element.
[0133] S340. If a target fill element exists, obtain element attributes of the target fill element and element attributes of each straight line element in the table element as element attributes of the table element; the target fill element refers to a fill element whose fill area matches the bounding box of the table element; if there is no target fill element, obtain element attributes of each straight line element in the table element as element attributes of the table element.
[0134] If there is a target filling element, it indicates that the table element needs to be filled, then the element attributes of the target filling element and the element attributes of each straight line element in the table element are obtained as the element attributes of the table element. If there is no target filling element, it is determined that the table element does not need to be filled, and the element attributes of each straight line element in the table element are directly obtained as the element attributes of the table element.
[0135] S350. If the target element is a table element, determine the first tag according to the element attributes of the target fill element, determine the second tag according to the element attributes of each straight line element in the table element, add the first tag to the second tag as a subtag to obtain a third tag, and obtain a text HTML element according to the third tag.
[0136] If it is a table element, the svg path tag (first tag, which includes the element attributes of the target filling element) can be determined according to the element attributes of the target filling element in the table element, and the svg path tag (second tag, which includes the element attributes of the straight line element) can be determined according to the element attributes of each straight line filling element in the table element, and the svg path tag of the target filling element is added as a subtag to the svg path tag of the straight line element to obtain the svg tag (third tag), and a table HTML tag is generated according to the third tag, and the table HTML tag can be used as a text HTML element corresponding to the table element.
[0137] For example, the resulting HTML tags may be:
[0138]
[0139] The starting positioning point is used to determine the starting point of the line path of the straight line element.
[0140] As an implementation mode, a table HTML tag and a table CSS stream file corresponding to the table element may also be obtained, and the table HTML tag and the table CSS stream file may be used as a text HTML element, as described in S140 above, which will not be repeated here.
[0141] S360: If the target element is a filling element, determine a fourth tag according to the element attribute of the filling element, and obtain a text HTML element according to the fourth tag.
[0142] If it is a filling element, the svg path tag (the fourth tag) is directly determined according to the element attributes of the filling element, and a filling HTML tag is generated according to the svg path tag. The generated filling HTML tag can be used as the text HTML element of the filling element.
[0143] As an implementation mode, a filling HTML tag and a filling CSS stream file corresponding to the filling element may also be obtained, and the filling HTML tag and the filling CSS stream file may be used as a text HTML element, as described in S140 above, which will not be repeated here.
[0144] S370: If the target element is a line element, determine the fifth tag according to the element attributes of the line element, and obtain the text HTML element according to the fifth tag.
[0145] If it is a line element, the svg path tag (fifth tag) is directly determined according to the element attributes of the line element, and a line HTML tag is generated according to the svg path tag. The generated line HTML tag can be used as the text HTML element of the line element.
[0146] As an implementation mode, the line HTML tag and the line CSS stream file corresponding to the line element may also be obtained, and the line HTML tag and the fill CSS stream are used as the text HTML element, as described in S140 above, which will not be repeated here.
[0147] S380: Generate an HTML file according to a preset template and text HTML elements.
[0148] The description of S380 refers to the description of S150 above and will not be repeated here.
[0149] In this embodiment, line elements, fill elements and table elements are processed separately to obtain their corresponding text HTML elements, thereby achieving accurate conversion of line elements, fill elements and table elements, avoiding the loss of line elements, fill elements and table elements, and improving the accuracy of HTML files.
[0150] See also Figure 7 , Figure 7A flowchart of a method for generating an HTML file according to another embodiment of the present application is shown. The method can be applied to an electronic device, which can be Figure 1 The terminal 20 or the server 10 in the embodiment of the present invention comprises:
[0151] S410, obtaining a PDF file to be processed; if the PDF file to be processed includes text information, obtaining a primitive and a primitive value of the primitive from the text information; determining a target element and an element attribute of the target element according to the primitive and the primitive value of the primitive; determining a text HTML element according to the target element and the element attribute of the target element.
[0152] The description of S410 refers to the description of S110-S140 above, or refers to the description of S210-S240 and S310-S370 above, and will not be repeated here.
[0153] S420: If the PDF file to be processed also includes picture information, the picture information is mapped using a preset two-dimensional affine matrix to obtain a picture HTML element.
[0154] In an embodiment, the PDF file to be processed may also include picture information, and the picture information may be processed by a preset two-dimensional affine matrix to obtain a picture HTML element.
[0155] The preset two-dimensional affine matrix may be set by the user based on the requirements. For example, as a possible implementation, the two-dimensional affine matrix may refer to Formula 1, which is as follows:
[0156]
[0157] Among them, m0, m1, m2, m3, m4, and m5 are values in a preset two-dimensional affine matrix (Current Transform Matrix, CTM for short), and width and height represent the length and width of the picture information, respectively.
[0158] The image information may be mapped using a preset two-dimensional affine matrix to obtain a mapped result, and a picture HTML tag may be generated according to the mapped result. The generated picture HTML tag may be used as a picture HTML element.
[0159] Optionally, S420 may include: reading a binary stream of image information to obtain a reading result, mapping the reading result to a target space through a preset two-dimensional affine matrix to obtain a mapping result; converting the mapping result to a preset format to obtain a conversion result; and determining the image HTML element according to the conversion result.
[0160] The target format can refer to base64. The target space can refer to the HTML space. That is, in this embodiment, through the preset two-dimensional affine matrix in Formula 1, the reading result is mapped to the HTML space to obtain a transform matrix, and this transform matrix is used as the mapping result. At this time, the mapping result can be expressed as Formula 2, and Formula 2 is as follows:
[0161]
[0162] Among them, m0, m1, m2, m3, m4, and m5 are respectively the values in the CTM list, and width and height represent the length and width of the picture information.
[0163] After obtaining the conversion result, an HTML tag can be generated according to the conversion result as the picture HTML tag, and this picture HTML tag is used as the picture HTML element. The expression of the picture HTML tag corresponding to the picture information can refer to Table 4, and Table 4 is as follows:
[0164] Table 4
[0165] Image related information Corresponding HTML style CTM transform
[0166] For example, the finally generated HTML tag can be: .
[0167] As an implementation manner, S440 may include: determining the comparison result of the mapping result and the visible range corresponding to the picture information; determining the picture display style according to the comparison result; and obtaining the picture HTML element according to the conversion result and the picture display style.
[0168] The visible range of the picture information may refer to the mask corresponding to the picture information in the PDF file to be processed. The comparison result includes the comparison results of each picture information and the visible range of each picture information. Specifically, the comparison result may include that the picture information is within the visible range or the picture information is not within the visible range. If the comparison result is that the picture information is within the visible range, determine its picture display style as normal display. If the comparison result is that the picture information is not within the visible range, determine its picture display style as transparent display.
[0169] Finally, according to the conversion result and the picture display style of each picture information, the HTML tag corresponding to the picture can be obtained as the picture HTML element.
[0170] S430. Generate an HTML file according to the preset template, text HTML element, and picture HTML element.
[0171] The preset template may also include a filling position for a picture HTML element, and the text HTML element and the picture HTML element are directly written into the corresponding filling positions to obtain an HTML file.
[0172] In this embodiment, the picture information is converted into the picture HTML element through a preset two-dimensional affine matrix, which avoids data loss of the picture information and improves the conversion accuracy of the picture information, thereby improving the accuracy of the HTML file.
[0173] In order to explain the technical solution of the present application more clearly, the HTML file generation method of the present application is explained below in combination with an exemplary scenario. In this scenario, the PDF to be processed includes 20 pages, of which pages 16-20 are new image information, pages 2-15 are text information, the first page is a directory, and the text information includes text elements, line elements, fill elements, and table elements.
[0174] like Figure 8 As shown, in the present application, the user edits the PDF file through the local file system to obtain the PDF file to be processed, and can also preview the edited PDF file to be processed through the local file system, and can also render the PDF file to be processed into an HTML file through the local file conversion system and display the edited HTML file.
[0175] The structure of the local file system is as follows: Fig. 9 As shown, the local file system may include a PDF preprocessor, an overall scheduler, a text processing module, a PDF clip module, an image rendering and positioning module, and a line & fill rendering and positioning module. The PDF preprocessor includes a text extraction module, a line extraction module, and a fill extraction module. The overall scheduler includes a PDF rendering module, a temporary stream storage module, an element positioning / style registration module, and an HTML output template module. The text processing module may include a text horizontal / column processing unit and a text font / color processing unit.
[0176] 1. Read the PDF file to be processed
[0177] The PDF rendering module is the core of the scheduling module. Fig.10As shown, the PDF rendering module opens the PDF file to be processed and reads the PDF file to be processed page by page. When reading each page, it determines whether the content of the current page is empty. If it is empty, the reading is terminated. If it is not empty, the content stream of the current page is opened, and a state recording function and an instruction callback are added. The state recording function records the primitives and primitive values of the state category of the PDF file to be processed. When the primitives of the instruction category are detected, the instruction callback is used to call the module of the primitives of the corresponding instruction category in the local file system for related processing. The current page content stream is traversed to determine whether the current page content stream is ended. If it is ended, the next page is read. If it is not ended, the current page content stream is read.
[0178] When the PDF rendering module reads the instruction of the status category corresponding to the text element in the PDF file to be processed, the font extraction module in the PDF preprocessor is scheduled through the instruction callback, and the text information is extracted through the font extraction module. The text information extraction process is as follows: Fig.11 As shown. Get the symbol code corresponding to the text element, and search for the corresponding text style in the local resource library. If not found, find the corresponding text style in the resource dictionary. If found, record the text style. After that, you can also register the text posture information, text color, text size and text style of the text element through the element positioning / style registration module, and store the text element, the text posture information, text color, text size and text style of the text element in the temporary stream storage module.
[0179] When the PDF rendering module reads the instruction of the state category corresponding to the line element in the PDF file to be processed, the line extraction module in the PDF preprocessor is scheduled through the instruction callback, and the line element is extracted through the line extraction module. The extraction process of the line element is as follows: Fig.12 As shown. Start extracting the line path and determine whether the line path is found. If found, determine the line shape, line color, line width and line path, register the line shape, line color, line width and line path through the element positioning / style registration module, and store the line, the line shape, line color, line width and line path of the line in the temporary stream storage module.
[0180] When the PDF rendering module reads the instruction corresponding to the state category of the fill element in the PDF file to be processed, the fill extraction module in the PDF preprocessor is scheduled through the instruction callback, and the fill element is extracted through the fill extraction module. The extraction process of the fill element is as follows: Fig.13As shown. Start extracting the fill path, determine whether the fill path is found, if found, determine the fill color, fill shape and fill path of the fill element, register the fill color, fill shape and fill path through the element positioning / style registration module, and store the fill, fill color, fill shape and fill path in the temporary stream storage module.
[0181] Meanwhile, when the PDF rendering module reads the instructions of the state categories of the corresponding line elements and fill elements in the PDF file to be processed, the processing process of the fill extraction module may also include: Fig.14 The process shown, such as Fig.14 As shown, it is also possible to determine whether there are multiple straight line elements. If so, merge the multiple straight line elements to obtain a table element, and continue to determine whether there is a target filling element (the target filling element refers to a filling element whose filling area matches the bounding box of the table element). If so, merge the target filling element in the table element and the element attributes of the straight line element to obtain the element attributes of the table element. If not, merge the straight line elements in the table element to obtain the element attributes of the table element. The element attributes of the table element can also be registered through the element positioning / style registration module, and the table element and the element attributes of the table element are stored in the temporary stream storage module.
[0182] 2. HTML file generation
[0183] When the PDF rendering module receives the PDF instruction (that is, the primitive of the instruction category) "Tj", it schedules the text processing module through the instruction callback, and the text processing module processes the text information. The processing process of the text processing module is as follows: Fig.15As shown. The text posture information and text size of the registered text element can be obtained from the element positioning / style registration module. The text boundary box is determined by the text posture information and text size, and then the PDF The clip module obtains the mask of the text and determines whether the boundary box of the text is within the mask. If so, the text display style of the text element is determined to be normal display; if not, the text display style of the text element is determined to be transparent display. Then, the text row / column processing unit determines whether the text is in the same row / column as the previous text. If so, the text and the previous molecule are merged to obtain a text element string. If not, the text itself is used as a text element string. After obtaining the text element string, the text font / color processing unit determines the HTML data of each text element string according to each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size, text color and text display style of each text element in each text element string. The HTML data of each text element string may include the text HTML tag of each text element and the text CSS stream file. The HTML data of each text element string is summarized to obtain the text HTML element of the text element, and the text HTML element of the text element is stored in the temporary stream storage module.
[0184] When the PDF rendering module receives any of the PDF commands "l, m, v, y", it schedules the line & fill rendering positioning module through the command callback, and the line & fill rendering positioning module processes the lines, fills, and tables. The processing process is as follows: Fig.16 As shown. First, the registered line element and fill element are obtained through the line & fill rendering positioning module, and it is determined whether the line element and fill element belong to the table element. If they belong, the fill element in the table element is read to generate a first tag, the line element is read to generate a second tag, and the first tag is added to the second tag as a subtag to obtain the text HTML element corresponding to the table. The text HTML element corresponding to the table may include a table HTML tag and a table CSS flow file; if it does not belong, if it is a line element, the fifth tag is determined according to the element attribute of the line element, and the text HTML element of the line element is obtained according to the fifth tag. The text HTML element corresponding to the line may include a line HTML tag and a line CSS flow file; if it is a fill element, the fourth tag is determined according to the element attribute of the fill element, and the text HTML element of the fill element is obtained according to the fourth tag. The text HTML element corresponding to the fill may include a fill HTML tag and a fill CSS flow file.
[0185] Afterwards, the text HTML elements corresponding to the line elements, the fill elements and the table elements may be stored in a temporary stream storage module.
[0186] When the PDF rendering module receives the PDF command "Do", it schedules the image rendering positioning module through the command callback. The image rendering positioning module renders the image information. The rendering process of the image information is as follows: Fig.17 As shown, first read the binary stream of the image information, then map the read result to the HTML space to obtain the mapping result, then obtain the mask of the image information through the PDF clip module, and determine whether the mapping result is within the mask, determine the image display style of the image information within the mask as normal display, and determine the image display style of the image information outside the mask as transparent display, then export the mapping result to base64 format, and then obtain the image HTML tag according to the base64 format export result and the image display style, as the image HTML element, the image HTML element can be stored in the temporary stream storage module.
[0187] After obtaining the text HTML element and the image HTML element, the HTML output template module obtains the text HTML element and the image HTML element from the temporary stream storage module, and fills the text HTML element and the image HTML element in the filling position corresponding to the preset template to obtain an HTML file.
[0188] In this scenario, compared with traditional PDF editors, this solution can achieve accurate (referring to accurate position, accurate layer, accurate size, accurate font and accurate color) and complete (referring to complete and no loss of visible information such as text and images) conversion of the PDF file to be processed into HTML file. At the same time, it can also greatly reduce the computing resource usage during PDF editing. The computing resource usage of single-page PDF editing is reduced by about 90% on average (compared with Adobe Acrobat Pro processing general PDF). The editing response speed under the same hardware conditions (electronic devices with general configuration) has been greatly improved.
[0189] See also Fig.18 , Fig.18 A block diagram of an HTML file generating device proposed in an embodiment of the present application is shown, and the device 1800 includes:
[0190] The first acquisition module 1810 is used to acquire a PDF file to be processed, where the PDF file to be processed includes text information and image information;
[0191] The second acquisition module 1820 is used to acquire the primitive and the primitive value of the primitive from the text information if the PDF file to be processed includes text information;
[0192] The first determination module 1830 is used to determine the target element and the element attribute of the target element according to the primitive and the primitive value of the primitive; the target element includes a text element and / or a graphic element;
[0193] The second determination module 1840 is used to determine the text HTML element according to the target element and the element attribute of the target element;
[0194] The generation module 1850 is used to generate an HTML file according to a preset template and text HTML elements.
[0195] Optionally, the text information includes primitives and primitive values of the primitives; the first determination module 1830 is also used to obtain a first primitive and a second primitive from the primitive; the first primitive is a primitive of a first instruction category, and the second primitive is a primitive of a second instruction category; according to the primitive value of the first primitive, the target element is determined; according to the primitive value of the second primitive, the element attribute of the target element is determined.
[0196] Optionally, the target element includes a text element; the first determination module 1830 is further used to obtain a second primitive corresponding to the text element from the second primitive as a text attribute primitive; obtain a symbol code from the primitive value of the text attribute primitive as a target symbol code for the text element; obtain a text style corresponding to the target symbol code of the text element from a text style library as a target text style of the text element; the text style library includes text styles corresponding to different symbol codes; obtain text posture information, text color and text size of the text element from the primitive value of the text attribute primitive; obtain text posture information, text color, text size and target text style as element attributes of the text element.
[0197] Optionally, the second determination module 1840 is also used to determine the bounding box of the text element based on the text posture information and text size of the text element; merge each text element according to the bounding box of each text element to obtain at least one text element string, each text element string including at least one text element; determine the HTML data of each text element string according to each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size and text color of each text element in each text element string; obtain and summarize the HTML data of each text element string to obtain a text HTML element.
[0198] Optionally, the second determination module 1840 is also used to determine the comparison results of each text element and the visible range of each text element; determine the text display style of each text element based on the comparison results; determine the HTML data of each text element string based on each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size, text color and text display style of each text element in each text element string.
[0199] Optionally, the text elements are arranged in sequence; the second determination module 1840 is also used to combine any two adjacent text elements if their bounding boxes overlap after translation along the target direction, so as to obtain at least one initial text element string; and adjust the spacing between any adjacent text elements in each initial text element string according to the placeholder to obtain the text element string corresponding to each initial text element string.
[0200] Optionally, the target element includes a graphic element, and the graphic element includes a line element and a fill element; the first determination module 1830 is also used to obtain a second primitive corresponding to the line element from the second primitive as a line attribute primitive; according to the primitive value of the line attribute primitive, determine the line color, line shape, line width and line path of the line element as element attributes of the line element; obtain a second primitive corresponding to the fill element from the second primitive as a fill attribute primitive; according to the primitive value of the fill attribute primitive, determine the fill color, fill shape and fill path of the fill element as element attributes of the fill element.
[0201] Optionally, the graphic elements include fill elements, fill elements and table elements; the first determination module 1830 is also used to determine the element attributes of the line elements and the element attributes of the fill elements according to the primitive value of the second primitive; the element attributes of the fill elements include the fill area of the fill elements, and the element attributes of the line elements include the line shape of the fill elements; if there are multiple intersecting straight line elements, the multiple intersecting straight line elements are merged to obtain a table element, and the bounding box of the table element is determined; the straight line element refers to a line element whose line shape is a straight line in the element attributes; if there is a target fill element, the element attributes of the target fill element and the element attributes of each straight line element in the table element are obtained as the element attributes of the table element; the target fill element refers to a fill element whose fill area matches the bounding box of the table element; if there is no target fill element, the element attributes of each straight line element in the table element are obtained as the element attributes of the table element.
[0202] Optionally, the second determination module 1840 is also used to determine the first tag according to the element attributes of the target fill element if the target element is a table element, determine the second tag according to the element attributes of each straight line element in the table element, add the first tag to the second tag as a subtag to obtain a third tag, and obtain a text HTML element according to the third tag; if the target element is a fill element, determine the fourth tag according to the element attributes of the fill element, and obtain a text HTML element according to the fourth tag; if the target element is a line element, determine the fifth tag according to the element attributes of the line element, and obtain a text HTML element according to the fifth tag.
[0203] Optionally, the generation module 1850 is further used to map the image information through a preset two-dimensional affine matrix to obtain an image HTML element if the PDF file to be processed also includes image information; and generate an HTML file according to a preset template, text HTML elements and image HTML elements.
[0204] Optionally, the generation module 1850 is also used to read the binary stream of the image information, obtain the reading result, map the reading result to the target space through a preset two-dimensional affine matrix, and obtain a mapping result; convert the mapping result into a preset format to obtain a conversion result; and determine the image HTML element according to the conversion result.
[0205] Optionally, the generation module 1850 is further used to determine the mapping result and the comparison result of the visible range corresponding to the image information; determine the image display style according to the comparison result; and obtain the image HTML element according to the conversion result and the image display style.
[0206] Optionally, the text HTML element includes an HTML tag and a cascading style sheet corresponding to the HTML tag; the generating module 1850 is further used to generate an HTML file according to a preset template, HTML tag and cascading style sheet.
[0207] It should be noted that the device embodiment in the present application corresponds to the aforementioned method embodiment. The specific principles in the device embodiment can be found in the contents of the aforementioned method embodiment and will not be repeated here.
[0208] Fig.19 A structural block diagram of an electronic device for executing the HTML file generation method according to an embodiment of the present application is shown. The electronic device may be Figure 1 The terminal 20 or the server 10, etc., need to be explained that, Fig.19 The computer system 1900 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0209] like Fig.19As shown, the computer system 1900 includes a central processing unit (CPU) 1901, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1902 or the program loaded from the storage part 1908 to the random access memory (RAM) 1903, such as executing the method in the above embodiment. In RAM 1903, various programs and data required for system operation are also stored. CPU 1901, ROM 1902 and RAM 1903 are connected to each other through bus 1904. Input / output (I / O) interface 1905 is also connected to bus 1904.
[0210] The following components are connected to the I / O interface 1905: an input section 1906 including a keyboard, a mouse, etc.; an output section 1907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1908 including a hard disk, etc.; and a communication section 1909 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1909 performs communication processing via a network such as the Internet. A drive 1910 is also connected to the I / O interface 1905 as needed. A removable medium 1911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1910 as needed so that a computer program read therefrom is installed into the storage section 1908 as needed.
[0211] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 1909, and / or installed from a removable medium 1911. When the computer program is executed by a central processing unit (CPU) 1901, various functions defined in the system of the present application are executed.
[0212] It should be noted that the computer-readable storage medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, - but not limited to - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a 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 above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0213] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0214] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0215] As another aspect, the present application further provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or may exist independently without being assembled into the electronic device. The above computer-readable storage medium carries computer-readable instructions, and when the computer-readable storage instructions are executed by a processor, the method in any of the above embodiments is implemented.
[0216] According to one aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device executes the method in any of the above embodiments.
[0217] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0218] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the implementation method of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable an electronic device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the implementation method of the present application.
[0219] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the embodiments disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary techniques in the art that are not disclosed in the present application. It should be understood that the present application is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
[0220] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for generating an HTML file, characterized in that: The method comprises: Get the PDF file to be processed; If the PDF file to be processed includes text information, obtaining a primitive and a primitive value of the primitive from the text information; Determine a target element and an element attribute of the target element according to the primitive and the primitive value of the primitive; the target element includes a text element and / or a graphic element; Determine a text HTML element according to the target element and the element attribute of the target element; Generate an HTML file according to the preset template and the text HTML element.
2. The method according to claim 1, characterized in that The determining the target element and the element attribute of the target element according to the primitive and the primitive value of the primitive includes: Acquire a first primitive and a second primitive from the primitive; the first primitive is a primitive of a first instruction category, and the second primitive is a primitive of a second instruction category; Determining the target element according to the primitive value of the first primitive; An element attribute of the target element is determined according to the primitive value of the second primitive.
3. The method according to claim 2, characterized in that The target element includes a text element; and determining the element attribute of the target element according to the primitive value of the second primitive includes: Acquire a second primitive corresponding to the text element from the second primitive as a text attribute primitive; Obtaining a symbol code from the primitive value of the text attribute primitive as the target symbol code of the text element; Acquire a text style corresponding to the target symbol code of the text element from a text style library as the target text style of the text element; the text style library includes text styles corresponding to different symbol codes; Acquire text posture information, text color and text size of the text element from the primitive value of the text attribute primitive; The text posture information, the text color, the text size, and the target text style are acquired as element attributes of the text element.
4. The method according to claim 3, characterized in that The step of determining the text HTML element according to the target element and the element attribute of the target element includes: Determining a bounding box of the text element according to the text posture information and the text size of the text element; Merging the text elements according to their bounding boxes to obtain at least one text element string, each of which includes at least one text element; Determine the HTML data of each of the text element strings according to each of the text element strings, the text element spacing between adjacent text elements in each of the text element strings, the text posture information, text style, text size and text color of each of the text elements in each of the text element strings; Obtain and summarize the HTML data of each of the text element strings to obtain a text HTML element.
5. The method according to claim 4, characterized in that Determining the HTML data of each text element string according to each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size and text color of each text element in each text element string, comprises: Determine a comparison result of each of the text elements and the visible range of each of the text elements; Determining a text display style for each of the text elements according to the comparison result; The HTML data of each text element string is determined based on each text element string, the text element spacing between adjacent text elements in each text element string, the text posture information, text style, text size, text color and text display style of each text element in each text element string.
6. The method according to claim 4, characterized in that The text elements are arranged in order; and the text elements are merged according to the bounding boxes of the text elements to obtain at least one text element string, including: If the bounding boxes of any two adjacent text elements overlap after translation along the target direction, the any two adjacent text elements are combined to obtain at least one initial text element string; The spacing between any adjacent text elements in each of the initial text element strings is adjusted according to the placeholders to obtain a text element string corresponding to each of the initial text element strings.
7. The method according to claim 2, characterized in that The target element includes a graphic element, and the graphic element includes a line element and a fill element; and determining the element attribute of the target element according to the primitive value of the second primitive includes: Acquire a second primitive corresponding to the line element from the second primitive as a line attribute primitive; According to the primitive value of the line attribute primitive, determine the line color, line shape, line width and line path of the line element as element attributes of the line element; Acquire a second primitive corresponding to the filling element from the second primitive as a filling attribute primitive; According to the primitive value of the fill attribute primitive, the fill color, fill shape and fill path of the fill element are determined as element attributes of the fill element.
8. The method according to claim 2, characterized in that: The graphic elements include line elements, fill elements, and table elements; and determining the element attribute of the target element according to the primitive value of the second primitive includes: Determine, according to the primitive value of the second primitive, the element attributes of the line element and the element attributes of the filling element; the element attributes of the line element include the line shape of the line element, and the element attributes of the filling element include the filling area of the filling element; If there are multiple intersecting straight line elements, the multiple intersecting straight line elements are merged to obtain a table element, and the boundary box of the table element is determined; the straight line element refers to a line element whose line shape in the element attribute is a straight line; If there is a target filling element, obtaining element attributes of the target filling element and element attributes of each straight line element in the table element as element attributes of the table element; the target filling element refers to a filling element whose filling area matches the bounding box of the table element; If the target filling element does not exist, the element attributes of each straight line element in the table element are obtained as the element attributes of the table element.
9. The method according to claim 8, characterized in that The step of determining the text HTML element according to the target element and the element attribute of the target element includes: If the target element is a table element, determine the first tag according to the element attribute of the target fill element, determine the second tag according to the element attribute of each straight line element in the table element, add the first tag to the second tag as a subtag to obtain a third tag, and obtain the text HTML element according to the third tag; If the target element is a filling element, determining a fourth tag according to an element attribute of the filling element, and obtaining the text HTML element according to the fourth tag; If the target element is a line element, a fifth tag is determined according to the element attribute of the line element, and the text HTML element is obtained according to the fifth tag.
10. The method according to claim 1, characterized in that The step of generating an HTML file according to the preset template and the text HTML element comprises: If the PDF file to be processed also includes picture information, the picture information is mapped using a preset two-dimensional affine matrix to obtain a picture HTML element; Generate an HTML file according to the preset template, the text HTML element and the image HTML element.
11. The method according to claim 10, characterized in that The mapping process of the picture information by a preset two-dimensional affine matrix to obtain a picture HTML element includes: Read the binary stream of the image information and get the reading result Mapping the reading result to the target space through a preset two-dimensional affine matrix to obtain a mapping result; Converting the mapping result into a preset format to obtain a conversion result; The image HTML element is determined according to the conversion result.
12. The method according to claim 11, characterized in that Determining the image HTML element according to the conversion result includes: Determine a comparison result of the mapping result and a visual range corresponding to the image information; Determine the image display style according to the comparison result; The image HTML element is obtained according to the conversion result and the image display style.
13. The method according to claim 1, characterized in that The text HTML element includes an HTML tag and a cascading style sheet corresponding to the HTML tag; generating an HTML file according to the preset template and the text HTML element includes: Generate an HTML file according to the preset template, the HTML tag and the cascading style sheet.
14. An HTML file generating device, characterized in that: The device comprises: A first acquisition module is used to acquire a PDF file to be processed, wherein the PDF file to be processed includes text information and image information; A second acquisition module, configured to acquire a primitive and a primitive value of the primitive from the text information if the PDF file to be processed includes text information; A first determination module, configured to determine a target element and an element attribute of the target element according to the primitive and the primitive value of the primitive; the target element includes a text element and / or a graphic element; A second determination module, used for determining a text HTML element according to the target element and the element attribute of the target element; The generation module is used to generate an HTML file according to a preset template and the text HTML element.
15. An electronic device, characterized in that: include: one or more processors; Memory; One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs being configured to execute the method according to any one of claims 1-13.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program code, and the program code can be called by a processor to execute the method according to any one of claims 1 to 13.
