Streaming document conversion method and system, electronic equipment and storage medium
By parsing the streaming document structure, extracting multi-dimensional layout features, setting target layout parameters, identifying layout types and mapping styles, and optimizing pagination, columns, and mixed text and image layout, the problems of poor adaptability, chaotic content, and poor mixed text and image layout in streaming document conversion are solved, achieving efficient and accurate layout document generation.
Patent Information
- Application Number
- CN202511676792.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-17
- Publication Date
- 2026-02-10
AI Technical Summary
Existing technologies lack the ability to adapt to different paper sizes and column layouts, have insufficient support for multi-column layouts, easily lead to chaotic content structures, mismatched pagination and column mechanisms, and poor effects of mixed text and graphics, resulting in problems such as unbalanced column heights, content breaks, and incorrect cross-column display of charts during streaming document conversion.
By parsing the streaming document structure, extracting multi-dimensional layout feature vectors, establishing feature matrices and index tables, setting target layout parameters, identifying layout types, establishing style mapping rule sets, executing hierarchical repair strategies, optimizing pagination, columns, and mixed text and image layouts, and generating layout documents.
It improves the accuracy and fidelity of layout conversion, enhances layout adaptability, optimizes pagination and column effects, improves the rationality and reading smoothness of mixed text and images, realizes automatic detection and repair of layout defects, and improves the automation and efficiency of the conversion process.
Smart Images

Figure CN121503431A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of document processing technology, and specifically to a streaming document conversion method, system, electronic device, and storage medium. Background Technology
[0002] Streaming documents (such as Epub and HTML) employ flexible content layouts, adapting to the screen size of the display device without fixed pagination. However, in print publishing, formal documents, and contract texts, it is necessary to convert streaming documents into formatted documents with fixed page layouts (such as Word and PDF) to meet different paper sizes and typesetting requirements.
[0003] Taking the conversion of Epub format to Word documents as an example, Epub documents are packaged in the open standard ZIP compression format. Their internal structure includes XHTML / HTML files, CSS style files, image resource files, and metadata files that define the document structure and reading order. This modular file organization structure gives the Epub format good cross-platform compatibility and scalability, but it also brings technical challenges to format conversion.
[0004] Existing conversion methods mainly suffer from the following technical problems:
[0005] Lack of adaptive layout capability: Existing methods are usually designed for specific formats and fixed layouts, and lack the ability to adaptively adjust to different paper sizes (A3, A4, A5, B5, Letter) and column layouts (single column, double column, multi-column).
[0006] Insufficient support for multi-column layout: There is a fundamental difference between the continuous text flow of a streaming document and the column layout of a formatted document. Existing methods are prone to problems such as uneven column heights, unreasonable content breaks, and incorrect display of charts across columns when handling two-column or multi-column layouts.
[0007] Content structure is prone to confusion: Complex HTML structures can easily lead to formatting issues in elements such as paragraphs, lists, and tables during conversion. This is especially true for complex cases such as nested div structures and merged table cells, which existing algorithms struggle to handle accurately.
[0008] Incompatibility in pagination and column mechanisms: Epub, as a fluid layout ebook format, does not have a fixed concept of pagination; content is automatically rearranged according to the device screen size. Word documents, on the other hand, are based on a page-based layout with clear pagination and column boundaries. This fundamental difference leads to unreasonable pagination breaks during conversion, such as titles isolated at the bottom of the page (title-memorization problem) or images separated from their titles on different pages (title-image separation problem).
[0009] Poor image and text integration: The CSS float property in Epub and the text wrapping mechanism in Word are fundamentally different in their implementation principles. Existing conversion methods often simply perform property mapping, ignoring the semantic relationship between images and surrounding text content. This leads to improper image insertion and a lack of effective image display mode (within a column or across the entire column) determination mechanism in multi-column layouts, disrupting the original reading flow.
[0010] Therefore, this application provides a streaming document conversion method to solve the above-mentioned technical problems. Summary of the Invention
[0011] The purpose of this invention is to provide a streaming document conversion method, system, electronic device, and storage medium to solve the technical problems of poor adaptability, chaotic content, and poor effect of mixed text and graphics in the prior art.
[0012] To address the aforementioned technical problems, this invention provides a streaming document conversion method, comprising:
[0013] Analyze the internal structure of the streaming document, extract the content file, style file, and resource file, and build a file index table and a resource index table;
[0014] For each content page, a multidimensional layout feature vector is extracted and standardized to establish a feature matrix and a feature index table. The multidimensional layout feature vector includes text density features, image proportion features, title distribution entropy features, blank rate features, structural complexity features, and style diversity features.
[0015] Set the target layout parameters based on user input or preset configuration, including paper size, margins, column layout and column spacing;
[0016] For each page, identify the layout type, output the page type classification results, and establish a relationship table between the page type classification vector and the layout structure.
[0017] Based on the target layout parameters and page type classification results, the style mapping parameters are adaptively adjusted to establish a mapping rule set from flow document style to layout document style;
[0018] The layout optimization process is performed, layout defects are detected and repaired using a hierarchical repair strategy, and a layout document is generated based on the mapping rule set and the layout optimization process results. The layout optimization process includes pagination optimization based on a multi-dimensional scoring mechanism, column optimization based on a two-dimensional scoring mechanism, and image and text mixed layout optimization based on heuristic analysis.
[0019] Based on the same concept, the present invention also provides a streaming document conversion system, comprising:
[0020] The streaming document parsing module is configured to parse the internal structure of streaming documents, extract content files, style files, and resource files, and build file index tables and resource index tables.
[0021] The multi-dimensional layout feature vector extraction and processing module is configured to extract multi-dimensional layout feature vectors for each content page, perform standardization processing, and establish a feature matrix and feature index table. The multi-dimensional layout feature vectors include text density features, image proportion features, title distribution entropy features, blank rate features, structural complexity features, and style diversity features.
[0022] The target layout parameter setting module is configured to set target layout parameters based on user input or preset configuration, including paper size, page margins, column layout and column spacing;
[0023] The layout type recognition module is configured to identify the layout type of each page, output the page type classification results, and establish a page type classification vector and a layout structure relationship table.
[0024] The mapping rule set establishment module is configured to adaptively adjust the style mapping parameters based on the target layout parameters and page type classification results, and establish a mapping rule set from flow document style to layout document style;
[0025] The layout document generation module is configured to perform layout optimization processing, detect layout defects and repair them using a hierarchical repair strategy, and generate layout documents based on the mapping rule set and layout optimization processing results. The layout optimization processing includes pagination optimization based on a multi-dimensional scoring mechanism, column optimization based on a two-dimensional scoring mechanism, and image and text mixed layout optimization based on heuristic analysis.
[0026] Based on the same concept, the present invention also provides an electronic device, including: a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of a streaming document conversion method.
[0027] Based on the same concept, the present invention also provides a computer-readable storage medium storing a computer program executable by an electronic device, which, when run on the electronic device, causes the electronic device to perform the steps of a streaming document conversion method.
[0028] Compared with existing technologies, its advantages are as follows:
[0029] This invention discloses a streaming document conversion method, system, electronic device, and storage medium, which improves the accuracy and fidelity of layout conversion: by establishing a multi-dimensional layout feature quantification system and accurately analyzing and mapping streaming document styles, it ensures high-fidelity restoration of content elements such as text, images, and tables, as well as style attributes such as fonts, colors, and layouts during the conversion process.
[0030] Enhanced layout adaptability: By introducing a target layout parameter-driven mechanism, it can dynamically adjust style mapping parameters and page layout rules according to different paper sizes, column layouts, and layout style requirements, realizing flexible and adaptive conversion of streaming documents to multiple target layouts.
[0031] The pagination and column layout effects have been optimized: Through pagination optimization based on a multi-dimensional scoring mechanism and column optimization based on a two-dimensional scoring mechanism, the system automatically selects pagination and column positions with high content integrity, reasonable page filling, good semantic coherence, and balanced column height. This effectively avoids problems such as isolated titles and unreasonable content breaks, generating a harmonious and aesthetically pleasing multi-column layout.
[0032] Improved the rationality and reading fluency of mixed text and images: Through heuristic analysis-based optimization of mixed text and images, the system comprehensively considers the distance between images and text, content relevance, and layout feasibility, automatically calculates and selects the optimal insertion position and display size of images, ensuring a close association between images and related text, and enhancing the reading experience of layout documents.
[0033] Automatic detection and repair of layout defects have been achieved: Through a hierarchical defect detection and repair mechanism, typical layout defects such as isolated titles, separated figures and titles, and tables spanning multiple pages can be automatically identified and repaired, reducing manual intervention and improving the quality and usability of the final layout document.
[0034] The automation and efficiency of the conversion process have been improved: by building an end-to-end automated conversion process and using interpretable and efficient technologies such as rule engines, the manual operation and time cost required for format conversion have been reduced, and the overall processing efficiency has been improved. Attached Figure Description
[0035] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0036] Figure 1 This is a flowchart illustrating some specific embodiments of the streaming document conversion method of the present invention;
[0037] Figure 2 This is one of the flowcharts of another embodiment of the streaming document conversion method of the present invention;
[0038] Figure 3 This is a second flowchart illustrating another embodiment of the streaming document conversion method of the present invention;
[0039] Figure 4 This is a third flowchart illustrating another embodiment of the streaming document conversion method of the present invention;
[0040] Figure 5 This is the fourth flowchart of another embodiment of the streaming document conversion method of the present invention;
[0041] Figure 6 This is the fifth flowchart of another embodiment of the streaming document conversion method of the present invention;
[0042] Figure 7 This is a flowchart of another embodiment of the streaming document conversion method of the present invention;
[0043] Figure 8 This is the seventh flowchart of another embodiment of the streaming document conversion method of the present invention;
[0044] Figure 9 This is the eighth flowchart of another embodiment of the streaming document conversion method of the present invention;
[0045] Figure 10 This is a schematic diagram of the structure of a streaming document conversion system according to some specific embodiments of the present invention;
[0046] Figure 11 This is a schematic diagram of the structure of an electronic device according to some specific embodiments of the present invention;
[0047] In the diagram, 710 is the processor; 720 is the memory; 730 is the input device; and 740 is the output device. Detailed Implementation
[0048] Reference Figure 1 A streaming document conversion method, comprising:
[0049] S101, parse the internal structure of the streaming document, extract the content file, style file and resource file, and build the file index table and resource index table;
[0050] S102, extract multi-dimensional layout feature vectors for each content page, perform standardization processing, and establish a feature matrix and feature index table. The multi-dimensional layout feature vectors include text density features, image proportion features, title distribution entropy features, blank rate features, structural complexity features, and style diversity features.
[0051] S103, set the target layout parameters according to user input or preset configuration, including paper size, page margins, column layout and column spacing;
[0052] S104, perform layout type identification for each page, output page type classification results, and establish a page type classification vector and layout structure relationship table;
[0053] S105, Based on the target layout parameters and page type classification results, adaptively adjust the style mapping parameters to establish a mapping rule set from flow document style to layout document style;
[0054] S106, Perform layout optimization processing, detect layout defects and repair them using a hierarchical repair strategy, and generate a layout document based on the mapping rule set and layout optimization processing results. The layout optimization processing includes pagination optimization based on a multi-dimensional scoring mechanism, column optimization based on a two-dimensional scoring mechanism, and graphic and text mixed layout optimization based on heuristic analysis.
[0055] Specifically, in this embodiment of the invention, the internal structure of the streaming document is analyzed, the reading order is determined by reading the manifest file, and the content file, style file, and resource file are extracted in sequence. A file index table and a resource index table are established to record file paths and resource information. For each content page, a multi-dimensional layout feature vector is extracted, including text density features obtained by calculating the number of characters per unit area, image proportion features obtained by weighted calculation of image size, position, and content relevance, title distribution entropy features obtained by calculating information entropy based on the probability of occurrence of each level of title, white space ratio features obtained by calculating the proportion of white space to the total area, structural complexity features obtained by analyzing the nesting depth and branching factors of the document object model tree, and style diversity features obtained by statistically analyzing the ratio of different style classes to the total number of elements. All features are standardized to eliminate the influence of dimensions, and a feature matrix and feature index table are established for subsequent analysis. Target layout parameters are set according to user input or preset configuration, including paper specifications such as size and orientation, margin distance, column layout such as single or multiple columns, and column spacing width. A rule engine is used to identify the layout type of each page based on page features and predefined parameters. The rules output page type classification results, such as cover page or body page, and establish a page type classification vector and layout structure relationship table to describe the relationship between page type and structure. Based on the target layout parameters and page type classification results, the style mapping parameters are adaptively adjusted, including adjusting the font size conversion factor and line spacing ratio according to paper size, adjusting the image display mode and paragraph format according to the number of columns, and adjusting the layout rules according to page type. A mapping rule set from fluid document style to layout document style is established to define attribute conversion relationships. Finally, layout optimization processing is performed, including pagination optimization based on a multi-dimensional scoring mechanism to select pagination positions by evaluating content integrity, page fill rate and context relevance; column optimization based on a two-dimensional scoring mechanism to select column positions by evaluating column height balance and content coherence; and image and text integration optimization based on heuristic analysis to calculate image insertion positions and display sizes by analyzing distance, content relevance and layout factors. At the same time, layout defects such as isolated titles or separated images and titles are detected and repaired step by step from lightweight to heavyweight using a hierarchical repair strategy. Based on the mapping rule set and layout optimization processing results, a layout document is generated by creating document objects, setting parameters, adding content, and applying styles and repair operations.
[0056] For example, when parsing streaming documents, taking Epub format as an example, the OPF manifest file is read to obtain the reading order, and HTML content files, CSS style files, and PNG image resource files are extracted. A file index table is built to record the HTML file paths and CSS file links, and a resource index table records the image identifiers and storage paths. In feature extraction, a multi-dimensional layout feature vector is calculated for an example page. The text density feature calculation formula is: text density = total number of characters / content area. For example, if the total number of characters is 80 and the content area is 100 mm², then...2 Therefore, the text density = 80 / 100 = 0.8 characters / mm. 2 The formula for calculating the image proportion feature is: Image Proportion = Σ(Image Area × Weight Coefficient) / Page Area, where the weight coefficient = 0.4 × Size Factor + 0.3 × Position Factor + 0.3 × Content Relevance Factor, and the size factor = current image area / average image area; the position factor = 1 / (1 + distance from page center / 100); and the content relevance factor = min(number of overlaps between alt attribute and surrounding text words / 3, 1.0). Assuming a page width of 1000px and a height of 500px, the page area = 500000 px², image 1 area = 30000 px², distance from page center 50 pixels, number of overlapping words 3; image 2 area = 10000 px², distance from page center 100 pixels, number of overlapping words 1; and the average image area = (30000 + 10000) / 2 = 20000 px. 2 Image 1: Size factor = 30000 / 20000 = 1.5, Position factor = 1 / (1+50 / 100) = 0.667, Content relevance factor = min(3 / 3, 1.0) = 1.0, Weight coefficient = 0.4×1.5+0.3×0.667+0.3×1.0 = 0.6+0.2001+0.3≈1.1001; Image 2: Size factor = 10000 / 20000 = 0.5, Position factor = 1 / (1+100 / 100) = 0.5, Content relevance factor = min(1 / 3, 1.0)≈0.333, Weight coefficient = 0.4×0.5+0.3×0.5+0.3×0.333 = 0.2+0.15+0.0999≈0.4499, Image proportion
[0057] λ img =(30000×1.1001+10000×0.4499) / 500000
[0058] =(33003+4499) / 500000=37502 / 500000≈0.075,
[0059] The formula for calculating the title distribution entropy feature is H. entropy =-Σ(p i ×log2(p i )), where p i =Number of occurrences of the i-th level heading / Total number of headings. For example, if heading h1 appears 2 times and heading h2 appears 3 times, the total number of headings is 5. Therefore, p1 = 2 / 5 = 0.4, p2 = 3 / 5 = 0.6, H... entropy=-(0.4×log2(0.4)+0.6×log2(0.6))≈0.971, the blank area ratio is calculated as blank area ratio = blank area / page area, for example, blank area = 100mm 2 Page area = 500mm 2 The blank rate is calculated as 100 / 500 = 0.2. The structural complexity feature is calculated as: Structural Complexity = Maximum Nesting Depth × Average Branch Factor. For example, if the maximum depth is 5 and the average branch factor is 2, the structural complexity is 5 × 2 = 10. The style diversity feature is calculated as: Style Diversity = Number of Different CSS Classes / Total Number of Elements. For example, if the number of different CSS classes is 10 and the total number of elements is 50, the style diversity is 10 / 50 = 0.2. All features are standardized using Z-scores. The formula is: Standardized Value = (Original Value - Mean) / Standard Deviation. For example, if the text density has a full document mean of 0.5 and a standard deviation of 0.2, the standardized value is (0.8 - 0.5) / 0.2 = 1.5. The image proportion has a full document mean of 0.07 and a standard deviation of 0.01, with a standardized value λ'. img=(0.075-0.07) / 0.01=0.5, establish the feature matrix and feature index table; in the target layout parameter settings, the user inputs A4 paper (210mm×297mm) portrait layout, page margins of 20mm on all sides, and column spacing of 5mm for a two-column layout; in the layout type recognition, the rule engine is used to check page features, for example, when the text density is >0.8 and the image ratio is <0.2, it is identified as a text page, and the page type classification vector is output as a text page, and a layout structure relationship table is established to describe the page order; in the adaptive adjustment, the font size conversion factor is adjusted to 1.2 based on A4 paper, the line spacing ratio is 1.5, the column width is adjusted to 80mm for each column based on the two-column layout, and the image display mode is in-column, based on The main text page type adjusts the column rules, establishing a mapping rule set, such as mapping a CSS font size of 12pt to a Word font size of 12 × 1.2 = 14.4pt. In layout optimization, pagination optimization uses a three-dimensional scoring mechanism to calculate candidate points. Content integrity scoring is based on the pagination point position; if it's within a paragraph, the score = number of used lines / total number of lines. For example, if there are 6 used lines and 10 total lines, the score = 6 / 10 = 0.6. Page fill rate scoring is based on the current page usage rate: usage rate = occupied content height / available page height. The target fill rate is 0.8, and the score is calculated using a Gaussian function; for example, a usage rate of 0.8 results in a score of 0.9. Contextual relevance scoring is based on the number of keyword overlaps before and after the pagination. For example, if there are 2 overlapping keywords, the score is 0.6. The overall score is calculated as: Content Completeness Score × Page Fill Rate Score × Context Relevance Score. The highest-scoring position is selected. Column optimization uses a two-dimensional scoring mechanism to calculate candidate points. Column height balance score = 1 - |Left column height - Right column height| / Page height. For example, if the left column height is 100mm, the right column height is 90mm, and the page height is 200mm, the score is 1 - |100 - 90| / 200 = 0.95. Content coherence score is calculated based on the degree of content breakage. For example, if the break is at the beginning of a paragraph, the score is 0.2. The highest-scoring position is selected for the overall score. Image and text integration optimization uses heuristic analysis to calculate the image insertion position. Distance factor = 1 / (1 + image and text distance). The content relevance factor is min(number of overlapping words between alt attribute and text / 3, 1.0), and the layout factor is based on the page layout feasibility score. The overall score is calculated as: distance factor × content relevance factor × layout factor. For example, with a distance of 100 pixels, 4 overlapping words, and a layout factor of 0.9, the distance factor is 1 / (1+100 / 100) = 0.5, the content relevance factor is min(4 / 5, 1.0) = 0.8, and the overall score is 0.5 × 0.8 × 0.9 = 0.36. The optimal position and display size are selected, such as an image width of 150 pixels. Page defects are detected, such as when the title is isolated, a hierarchical repair strategy is adopted to first adjust the line spacing and then force pagination. Finally, the page layout document is generated and all processing results are applied.
[0060] The process parses the compressed structure of the streaming document, obtaining the document's organizational structure and file list information by reading the manifest file within the container; it reads the metadata definitions in the manifest file to determine the document's reading order and file dependencies; it extracts all content files sequentially according to the determined reading order, including files storing text content and structural tags; it extracts all style files, including style rule definition files that control the document's visual presentation; and it extracts all image resource files, including image files of various formats, and builds a resource index table to systematically record the unique identifier of each image resource, its storage path information in the compressed package, and the original pixel size data of the image.
[0061] For example, when parsing the structure of a streaming document archive in Epub format, the container.xml file under the META-INF container directory is parsed to obtain the OPF file path; then the OPF manifest file is read. <spine>Element definition, determine the reading order as item1.html, item2.html, item3.html; extract content files according to the reading order, including three HTML files item1.html, item2.html and item3.html; extract all style files, including two CSS files styles.css and layout.css; extract all image resource files, including three image files image1.jpg, image2.png and image3.svg, and establish a resource index table, the specific records are as follows: image identifier IMG001 corresponds to the storage path images / image1.jpg, the original size is 800 pixels x 600 pixels, image identifier IMG002 corresponds to the storage path images / image2.png, the original size is 1024 pixels x 768 pixels, image identifier IMG003 corresponds to the storage path images / image3.svg, the original size is 1200 pixels x 900 pixels.
[0062] Calculate the text density feature for each content page, obtain the unit area text density by counting the total number of visible text nodes in the page and dividing by the content area; calculate the image proportion feature, by identifying all image elements in the page, based on the image size factor reflecting the relative size of the image, the position factor reflecting the closeness of the image to the center of the page, and the content relevance factor reflecting the semantic association degree of the image and the surrounding text, the weighted comprehensive calculation is carried out; calculate the title distribution entropy feature, by counting the occurrence frequency of each level of title tag, calculate the occurrence probability of each level of title and quantify the uncertainty of title level distribution based on information entropy formula; at the same time, calculate the blank rate feature, by calculating the proportion of blank area after subtracting the total area of all content elements from the total area of the page; calculate the structure complexity feature, by analyzing the product of the maximum nesting depth and the average branch factor of the document object model tree; calculate the style diversity feature, by counting the ratio of the number of different style categories in the page to the total number of elements; finally, standardize all features to eliminate dimensional differences, establish a feature matrix to store the feature vectors of all pages, and establish a feature index table to record the correspondence between feature values and pages.
[0063] For example, in calculating the text density feature, the visible text nodes are identified by traversing the page DOM tree, the total number of characters N char =80 is counted, the content area S content =100 mm 2 is calculated, the text density p text =N char / S content =80 / 100=0.8 characters / mm 2 ; In calculating the image proportion feature, two images in the page are identified, and their pixel sizes are obtained. Image 1 has a width of 200 px and a height of 150 px, and image 2 has a width of 100 px and a height of 100 px. The image areas are calculated as follows: image 1 area = 200 x 150 = 30000 px 2 , image 2 area = 100 x 100 = 10000 px 2 , average image area = (30000 + 10000) / 2 = 20000 px 2 , the size factor f is calculated size , image 1 size factor = 30000 / 20000 = 1.5, image 2 size factor = 10000 / 20000 = 0.5, the position factor f is calculated pos , image 1 is 50 px away from the center of the page, and the position factor = 1 / (1 + 50 / 100) = 0.667. Image 2 is 100 px away from the center of the page, and the position factor = 1 / (1 + 100 / 100) = 0.5. The content relevance factor f is calculated content , the alt attribute of image 1 overlaps with the surrounding text by 3 words, and the content relevance factor = min(3 / 3, 1) = 1.0. Image 2 overlaps by 1 word, and the content relevance factor = min(1 / 3, 1) ≈ 0.333. The weight coefficient w is calculated i = 0.4 x f size + 0.3 x f pos + 0.3 x f content , image 1 weight = 0.4 x 1.5 + 0.3 x 0.667 + 0.3 x 1.0 = 1.1, image 2 weight = 0.4 x 0.5 + 0.3 x 0.5 + 0.3 x 0.333 = 0.45, page area S page 500000 px ² (assuming the page width is 1000 px and the height is 500 px), image proportion λ img = (30000 x 1.1001 + 10000 x 0.4499) / 500000 = 37502 / 500000 ≈ 0.075; In calculating the title distribution entropy feature, h1 title appears 2 times, h2 title appears 3 times, and the total number of titles is 5 times. The probability p1 = 2 / 5 = 0.4, and p2 = 3 / 5 = 0.6. The information entropy H entropy = -(0.4 x log2(0.4) + 0.6 x log2(0.6)) ≈ 0.971; In calculating the blank rate feature, the total area of the page = 500 mm 2 , the total area of the content elements = 400 mm 2 , the blank area = 100 mm 2 , blank rate β blank = 100 / 500 = 0.2; in calculating the structural complexity feature, DOM tree maximum nesting depth = 5, average branch factor = 2, structural complexity γ struct = 5 x 2 = 10; in calculating the style diversity feature, different CSS class number = 10, element total number = 50, style diversity δ style = 10 / 50 = 0.2; normalized, text density document mean μ text = 0.5, standard deviation σ text = 0.2, normalized value ρ' text = (0.8-0.5) / 0.2 = 1.5, image proportion mean μ img = 0.07, standard deviation σ img = 0.01, normalized value λ' img = (0.075-0.07) / 0.01 = 0.5, title distribution entropy mean μ H = 1.0, standard deviation σ H = 0.3, normalized value H' entropy = (0.971-1.0) / 0.3 = -0.0967, a feature matrix is established to store feature vectors such as [1.5, 0.5, -0.097,...], and a feature index table is established to record the correspondence between pages and features.
[0064] Set paper size parameters, including selecting standard paper types or customizing size specifications, determining page orientation as portrait or landscape arrangement mode, setting page margins including blank distance in four directions of up, down, left and right; set column number layout parameters, including selecting single column or multi-column layout column number settings, determining the interval distance between adjacent columns, setting column width allocation methods including equal width allocation or proportional allocation; then set the layout style parameters, including defining the style hierarchy relationship of multiple levels of titles, setting the format specification requirements of text paragraphs, determining the display mode of chart elements including position and size rules; finally, set special layout processing rules, including defining the layout format requirements of cover pages, setting the typesetting specifications of table of contents pages, and specifying the layout processing method of appendix pages.
[0065] For example, when setting the paper size parameter, the user selects the A4 paper type, the size of which is 210 mm x 297 mm, sets the page direction as portrait, and sets the page margin as 20 mm for the top margin, 20 mm for the bottom margin, 25 mm for the left margin, and 25 mm for the right margin; when setting the column number layout parameter, the user selects the double-column layout setting, sets the column spacing as 8 mm, and calculates the column width using the equal-width allocation method, wherein the available width = 210 - 25 - 25 = 160 mm, and the single-column width = (160 - 8) / 2 = 76 mm; when setting the style parameter, the user defines the three-level title style level, including the first-level title font size 16 pt, the second-level title font size 14 pt, and the third-level title font size 12 pt, sets the text format specification to include the font size 10.5 pt, the line spacing 1.5 times, and the first-line indentation 2 characters, and determines the chart display mode as the chart width not exceeding the column width, the height being adaptive, and the center alignment; when setting the special layout processing rule, the user defines the cover page layout as single-column center display and no display of the header and footer, sets the table of contents page layout as single-column layout, automatically generates the table of contents item, and strictly controls the page division, and stipulates that the appendix page layout processing is to continue the text column layout and separately set the appendix title style.
[0066] The rule engine is used to identify the layout type of each page, the pre-defined symbol rule set is used to analyze the layout feature combination of the page, the classification result of the page type is output according to the identification result, the page is classified into a specific layout type category, the page type classification vector is established to record the specific type identification information of each page in a numerical form, and finally, the layout structure relationship table is established to systematically describe the logical structure relationship and the arrangement order information between the pages.
[0067] For example, when the rule engine is used to identify the layout type, the feature combination of a specific page is analyzed, the text density feature value of the page is 0.8 characters / mm 2 The image proportion feature value is 0.1, and the title distribution entropy feature value is 0.5. Applying the conditional judgment rules in the rule engine, rule 1 stipulates that if the text density is greater than 0.7 and the image proportion is less than 0.2, it is identified as a main text page; rule 2 stipulates that if the title distribution entropy is less than 1.0 and the text density is greater than 0.5, it is identified as a main text page. The current page satisfies both rules 1 and 2, therefore it is identified as a main text page. When outputting the page type classification results, the page is identified as a "main text page" type, and the recognition confidence is recorded as 0.9. When establishing the page class... When creating page type classification vectors, one-hot encoding is used to represent page types. The vector dimension is set to 6 to correspond to the six page types. The vector position corresponding to the main text page is set to 1, and the other positions are set to 0, generating a vector [0,0,1,0,0,0]. When establishing the page structure relationship table, the structural relationship of the three pages is recorded: page 1 is the cover page, page 2 is the table of contents page, and page 3 is the main text page. The structure relationship table records the predecessor and successor relationship from page 1 to page 2, and the predecessor and successor relationship from page 2 to page 3, forming a complete page structure chain.
[0068] Adjust font size conversion factors, line spacing and paragraph spacing ratios, and maximum image size limits based on paper specifications; dynamically calculate style scaling ratios based on the available width and height of the target paper; adjust column width, long paragraph spanning, and image display methods based on column layout parameters; determine content layout rules based on column number settings and column spacing; adjust page layout rules based on page type classification results; adopt differentiated layout processing strategies for different types of pages; establish a mapping rule set from fluid document styles to layout document styles; and systematically define the conversion relationships and mapping rules for various style attributes.
[0069] For example, when adjusting layout parameters based on paper specifications, if the user sets the target format to A4 paper (width 210mm, height 297mm), portrait orientation, and 20mm margins, the calculated usable width is 210-20-20=170mm, and the usable height is 297-20-20=257mm. The font size conversion factor is set to usable width / base width = 170 / 141.75≈1.2, line spacing ratio is 1.5, paragraph spacing ratio is 1.2, and the maximum image size is limited to a width of no more than 150mm and a height of no more than 200mm. When adjusting layout parameters based on the number of columns, if a two-column layout is set with a column spacing of 8mm, the calculated single column width is (170-8) / 2=81mm. The rule for long paragraphs spanning columns is set to automatically rotate when the number of lines in a paragraph exceeds 15. For full-width layout, image display is determined by image width: images less than 70mm are displayed within a column, while those 70mm or wider are displayed full-width. When adjusting based on page type classification results, the cover page uses a single-column centered layout with no header or footer; the table of contents uses a single-column layout with strict pagination control; the main text page uses a pre-defined two-column layout; and charts are prioritized for full-width display. When establishing the mapping rule set, specific style attribute conversion relationships are defined, including mapping a CSS font size of 12pt to a layout document font size of 12 × 1.2 = 14.4pt; mapping a CSS line height of 1.2 to a layout document line height of 1.2 × 1.5 = 1.8 times; and converting a CSS image width of 300 pixels to mm based on DPI and applying size constraint rules, ultimately forming a complete set of style mapping rules.
[0070] The process involves three key optimization steps: pagination optimization, which uses a comprehensive scoring mechanism to select the optimal pagination position based on three dimensions: content integrity (whether the pagination point is located at the natural boundary of a paragraph or table), page fill rate (the degree of matching between the current page content usage rate and the target fill rate), and context relevance (the degree of semantic connection between the text content before and after the pagination). Next, it involves two more optimization steps: column layout optimization, which uses a scoring mechanism based on two dimensions: column height balance (evaluating the balance of column heights in a multi-column layout) and content coherence (evaluating the impact of content breaks at column points on reading continuity). Finally, it involves three more optimization steps: image and text integration optimization, which uses a distance factor (evaluating the distance between the image and its original position), a content relevance factor (evaluating the semantic connection between the image and surrounding text), and a layout optimization mechanism based on these dimensions. The system uses three heuristic analysis factors—local factor assessment, image insertion location, and display size—to calculate the optimal insertion location and display size for the image. Simultaneously, it detects layout defects, including isolated titles (separated from their body text on different pages), image-capture separation (separated from their descriptions), table spanning across pages, and unreasonable column breaks in multi-column layouts. A tiered repair strategy is employed, progressively escalating repair measures from adjusting spacing parameters to forcibly paginating and dividing columns, based on the severity of the defects. Finally, a layout document is generated based on the style mapping rule set and layout optimization results. This is achieved by creating document objects, setting page parameters, adding content elements sequentially, and applying style mapping and optimization results.
[0071] For example, when performing pagination optimization, a three-dimensional score is calculated for a candidate pagination point: Regarding content completeness, the pagination point is located within a paragraph of 10 lines, with 6 lines already used, representing 60% of the total. According to the scoring rules, this situation scores 0.5 points. Regarding page fill rate, the current page has occupied 180mm of content height, leaving 220mm of usable height. The usage rate is approximately 180 / 220 ≈ 0.818, and the target fill rate is 0.8. Using a Gaussian function to calculate the score, the deviation is |0.818 - 0.8| = 0.018, and the score is exp(-(0.018 / 0.1)). 2 The score is approximately 0.97. Regarding contextual relevance scoring, keywords are extracted from 200 characters of text before and after the pagination. Eight keywords were extracted from the text before the pagination, and seven keywords were extracted from the text after the pagination. There are three overlapping keywords. According to the scoring rules, 3-4 overlapping keywords score 0.3 points. The overall score is 0.5 × 0.97 × 0.3 = 0.1455. When performing column optimization, a two-dimensional score is calculated for each candidate column point: For column height balance scoring, after column splitting, the left column height is 105mm, the right column height is 95mm, and the page height is 200mm. The column height balance score is 1 - |105 - 95| / 200 = 0.95; Regarding content coherence scoring, the column break point is located at the beginning of the paragraph, and according to the scoring rules, it scores 0.2 points; The comprehensive score is calculated using a product: 0.95 × 0.2 = 0.19; When performing image and text mixed layout optimization, the scores of three candidate positions are calculated for a single image: In terms of distance factor, position 1 is 50 pixels away from the original position, distance factor = 1 / (1+50 / 100) = 0.667, position 2 is 150 pixels away, distance factor = 1 / (1+150 / 100) = 0.4; In terms of content relevance factor, the number of overlapping words between the text and image alt attributes around position 1 is 4, indicating content relevance. The relevance factor is min(4 / 5,1)=0.8, with 2 overlapping words at position 2, and the content relevance factor is min(2 / 5,1)=0.4. Regarding layout factors, position 1 has a layout feasibility score of 0.9, and position 2 has a layout feasibility score of 0.7. The overall score is: position 1 = 0.667 × 0.8 × 0.9 = 0.48, position 2 = 0.4 × 0.4 × 0.7 = 0.112. Position 1 is selected as the insertion point, and the image display size is set to a width of 76mm and a height that adapts proportionally based on the column width limit. During the detection and repair of layout defects, an isolated title defect was detected, and a tiered repair strategy was adopted: the first... The first-level repair attempted to reduce the spacing before the heading paragraph from 5 points to 2 points, but the defect persisted after verification. The second-level repair attempted to reduce the line spacing of the paragraph containing the heading from 1.5 times to 1.2 times, but the defect persisted after verification. The third-level repair forced the insertion of a page break before the heading, and the defect was eliminated after verification. Finally, based on all the processing results, a layout document was generated, including creating a Word document object, setting the A4 paper size and two-column layout, adding text and image content in reading order, applying style attributes such as font size and line spacing, inserting page breaks and column breaks at the optimized positions, performing all repair operations, and outputting the final layout document file.
[0072] The following is combined with Figures 2-9 Another embodiment of the streaming document conversion method of the present invention is described below:
[0073] like Figure 2 , Figure 3 , Figure 4 , such as 5, 6, 7, 8 and Figure 9 As shown, this embodiment includes:
[0074] Streaming document parsing and resource extraction: Parse the internal structure of streaming documents, extract content files, style files, and resource files in a standardized order, and build file index tables and resource index tables.
[0075] Page layout feature extraction and quantization: Extract multi-dimensional page layout feature vectors for each content page, including text density, image proportion, title distribution entropy, white space ratio, structural complexity, and style diversity features. Perform Z-score standardization on all features and establish feature matrix and feature index table.
[0076] Target layout parameter settings: Set the target layout parameters according to the conversion requirements, including paper size (A3, A4, A5, B5, Letter), margins, column layout (single column, double column, three columns or multiple columns), column spacing, and column width allocation layout elements.
[0077] Page Layout Type Identification and Classification: A rule engine is used to identify the page layout type of each page, distinguishing between cover pages, table of contents pages, main text pages, chart pages, copyright pages, and appendix pages, and establishing page type classification vectors and page layout structure relationship tables.
[0078] Adaptive adjustment based on target layout: Based on the target layout parameters (paper size, column layout) and the identified layout type, the style mapping parameters are adaptively adjusted, including font size conversion factor, line spacing ratio, image display mode (full-width or in-column), paragraph format, and a set of mapping rules from flow document style to layout document style is established.
[0079] Layout optimization: This includes pagination optimization, column optimization, and image / text integration optimization. Pagination and column optimization uses a multi-dimensional scoring mechanism (content completeness, page fill rate, column height balance, and contextual relevance) to select the optimal breakpoint position. Image / text integration optimization uses heuristic analysis (distance factor, content relevance factor, and layout factor) to calculate the optimal insertion position and display size for images.
[0080] Page layout defect detection and automatic repair: A hierarchical defect detection and repair mechanism is applied to detect page layout defects such as isolated titles, separated images and titles, tables spanning multiple pages, and broken columns, and to automatically repair them according to priority using a hierarchical repair strategy.
[0081] Layout document generation and output: Create document objects according to the target layout requirements, set page parameters and column layout, add content elements in sequence, and apply the processing results of style mapping, layout optimization and defect repair to generate the final layout document.
[0082] Streaming document parsing and resource extraction supports multiple formats: For Epub format: reads the OPF manifest file to determine the reading order and extracts HTML, CSS, and image resources; For HTML format: parses the DOM tree structure and extracts style rules and multimedia resources.
[0083] The target layout parameters include: paper specifications: paper type, page orientation, and margins; column layout parameters: number of columns, column spacing, and column width allocation; layout style parameters: title style hierarchy, body text format specifications, and chart display methods; and special layout processing rules: format requirements for the cover page, table of contents, and appendix pages.
[0084] Adaptive adjustments include: paper-size-based adjustments: adjusting font size conversion factors, line spacing and paragraph spacing ratios, and maximum image size limits based on the available width and height of the target paper; column-based layout adjustments: maintaining the original text flow in single-column layouts, adjusting column widths, long paragraphs spanning columns, and selecting single-column or full-column display for images based on width in double-column or multi-column layouts; and page-type-based adjustments: forcing single-column centering on the cover page, strictly controlling pagination in single-column layouts on the table of contents page, dividing the main text page into columns according to the set number of columns, and prioritizing full-column display on chart pages.
[0085] The specific calculation standards for each dimension of the feature are as follows:
[0086] Text density feature ρ text This is used to represent the number of text characters per unit area, distinguishing between dense, normal, and sparse text pages. Calculation standard: Traverse the DOM tree in the streaming document, identify all visible text nodes, excluding elements with the `display` property set to `none` or the `visibility` property set to `hidden`; accumulate the total number of characters in all visible text nodes, denoted as N. char ;
[0087] Calculate the area of the content region:
[0088] ;
[0089] Calculate the text density feature value by multiplying the page width (minus the left and right margins) by the page height (minus the top and bottom margins), in square millimeters.
[0090] The unit is characters per square millimeter.
[0091] Determine the page density level based on the range of text density values: ρ text >0.8 represents a dense text page, 0.3 <ρ text ≤0.8 indicates a normal page, ρ text ≤0.3 indicates sparse pages; normalization: ρ' text =(ρ text -μ text )÷σ text , where μ text σ is the average text density of the entire document. text This represents the standard deviation of the text density of the entire document.
[0092] Image proportion feature λ img This represents the weighted proportion of image content within the page, used to comprehensively consider image size, location, and content relevance. Calculation criteria: Identify all `img` tags on the page and obtain their pixel dimensions (width and height); calculate the average image size on the page: Average size = Sum of all image areas ÷ Total number of images; calculate a weight coefficient `w` for each image `i`. i The weighting considers three factors: size factor f. size : Current image area ÷ Average image area; Location factor f pos The closer the content is to the center of the page, the higher its weight. The calculation formula is 1 ÷ (1 + distance ÷ 100), where the distance is in pixels; content relevance factor f content : Number of words overlapping between the image's alt attribute and the surrounding text ÷ 3, with a maximum of 1.0; Overall weight: w i =0.4×f size +0.3×f pos +0.3×f content ; Calculate the image proportion feature value: ;
[0093] Determined based on the range of image proportions: λ img >0.4 is for the chart page, 0.2 <λ img ≤0.4 indicates an illustration page, λ img ≤0.2 indicates a text-dominant page; standardization: λ' img =(λ img -μ img )÷σ img , where μ img σ represents the average percentage of images in the entire document. img This represents the standard deviation of the percentage of images in the entire document.
[0094] Title distribution entropy H entropy Information entropy is used to quantify the complexity of the page heading hierarchy. A lower entropy value indicates a clearer hierarchy, used to determine the document's structure and guide layout. Highly structured documents require strict control over isolated headings, while documents without clear hierarchy can employ more flexible pagination strategies. Calculation criteria: Count the occurrences of heading tags h1 to h6 on the page, denoted as count1 to count6; calculate the total number of headings: totalheading = Σ(counti); calculate the probability of each heading level: pi = counti ÷ totalheading, where i = 1 to 6; calculate the information entropy value: H entropy =-Σ(pi×log2(pi)), where the corresponding terms are not included in the summation for the case where pi=0; the document's structural level is determined based on the entropy value: H entropy <1 indicates a highly structured document, 1≤H entropy <2.5 is a normal structured document, H entropy ≥2.5 indicates no clear hierarchical structure; Standardization: H' entropy =(H entropy -μ H )÷σ H , where μ H σ is the average entropy of the entire document's title distribution. H The standard deviation of the entropy of the entire document title distribution.
[0095] Blank rate characteristics This represents the proportion of blank area to the total area of the page, used to evaluate page fill and optimize pagination decisions. Calculation standards: Calculate the total page area: pagearea = page width × page height; Calculate the area occupied by all content elements: contentarea = sum of all text area areas + all image area areas + all table area areas; Calculate the blank area area: blankarea = pagearea - contentarea; Calculate the blank area ratio feature value: =blankarea÷pagearea; Standardization: β' blank =(β blank -μβ)÷σβ, where μβ is the average blank rate of the entire document and σβ is the standard deviation of the blank rate of the entire document.
[0096] Structural complexity feature γstruct: quantifies the nesting depth and branching complexity of the HTML DOM tree, used to predict conversion difficulty, guide style mapping strategies, and assist in defect detection. Calculation standard: Traverse the DOM tree of the streaming document, calculate the maximum nesting depth maxdepth; calculate the average branching factor of the tree structure: average branching factor = sum of child nodes of all nodes ÷ total number of nodes; calculate the structural complexity feature value: γstruct = maxdepth × average branching factor; standardization: γ'struct = (γstruct - μγ) ÷ σγ, where μγ is the average structural complexity feature of the entire document, and σγ is the standard deviation of the structural complexity feature of the entire document.
[0097] The style diversity feature δstyle represents the degree of diversity of CSS style classes on a page, used to evaluate style complexity and optimize conversion strategies and quality control. Calculation criteria: Count the total number of different CSS classes appearing on the page: distinctclasses; Count the total number of all elements on the page: totallements; Calculate the style diversity feature value: δstyle = distinctclasses ÷ totallements; Range constraint: δstyle ∈ [0,1], closer to 1 indicates high style diversity, closer to 0 indicates a single style; Standardization: δ'style = (δstyle - μδ) ÷ σδ, where μδ is the average of the style diversity feature across the entire document structure, and σδ is the standard deviation of the style diversity feature across the entire document.
[0098] The specific calculation criteria for the three-dimensional scoring mechanism are as follows:
[0099] Pagination optimization: Identify candidate pagination points and assign a three-dimensional score to each. Column optimization: Identify candidate column division points and select content split points when converting from a flow document to a layout document. This ensures a harmonious and aesthetically pleasing two-column layout, avoiding situations where one side is crammed with content while the other is largely blank. Calculate the column height balance score (score = 1 - |left column height - right column height| ÷ page height) and the content coherence score, selecting the position with the highest overall score as the column division point. The calculation method for the content integrity score of pagination and columns: If the candidate pagination point is located at the natural boundary of a paragraph or table, this dimension is scored as follows: The maximum score is 1.0. If the candidate pagination point is located inside a paragraph, calculate the ratio of the number of lines used at the pagination point to the total number of lines in the paragraph. If the ratio is greater than or equal to 85%, the score is 0.7 (indicating that the paragraph is about to end). If the ratio is between 20% and 80%, the score is 0.5 (indicating that partial splits in the paragraph may result in orphan lines or isolated lines). If the ratio is less than 20%, the score is 0.2 (indicating that splitting at the beginning of the paragraph will result in obvious orphan line problems). If the candidate pagination point is a title and there is no content paragraph after the title, this dimension scores 0 points, indicating that pagination at this point is strictly prohibited.
[0100] The page fill rate score is calculated as follows: The current page utilization rate is calculated by dividing the occupied content height by the available page height. A target fill rate of 0.8 is defined. A Gaussian function is used to calculate the score based on the deviation between the fill rate and the target value. A fill rate of 0.8 results in a score of 0.9; a fill rate of 0.7 or 0.9 results in a score of 0.78; a fill rate of 0.6 or 1.0 results in a score of 0.36; and a fill rate less than 0.5 or greater than 1.1 results in a score close to 0. If a candidate pagination point will cause orphaned or missing lines, the score will be reduced by 30% based on the above calculations.
[0101] The calculation method for context relevance score is as follows: Extract the paragraph text before pagination and the paragraph text after pagination. Extract keywords from both paragraphs separately, selecting words with a length of 2 characters or more, a TF-IDF value higher than the document median, and not in the stop word list. Calculate the overlap between the two keyword sets. If the number of overlapping keywords is greater than or equal to 5, the score is 0.1 (indicating that the semantics are highly related and not suitable for pagination); if the overlap is 3 to 4, the score is 0.3; if the overlap is 1 to 2, the score is 0.6; and if the overlap is 0, the score is 1.0 (indicating that the two parts are semantically unrelated and suitable for pagination).
[0102] The image processing steps include: extracting all image resource files from the streaming document; establishing an image index table to record the identifier, storage path, original size, and the streaming file and location information of each image; applying image content recognition algorithms to analyze image types, determining whether an image is a decorative image, infographic, or illustration based on image size, position, and surrounding text content features; selecting appropriate processing strategies based on image type and layout conditions of the document: decorative images are embedded to minimize space occupation, infographics are centered to highlight importance, and illustrations are arranged around the text flow; calculating image display size based on the document page width limit and image importance level to ensure the clarity and readability of key infographics while avoiding excessively large images that disrupt the page layout; and embedding the processed image into the appropriate position in the document with optimal quality parameters.
[0103] The steps for maintaining layout consistency include: analyzing the visual density and information hierarchy of the original streaming document layout, and extracting quantitative indicators such as the number of lines, character density, and white space ratio as conversion reference standards; calculating the effective display area and content capacity limits of the layout document page to determine the maximum number of characters and images that can be accommodated after conversion; establishing a layout consistency evaluation model, which includes multiple evaluation indicators such as line count ratio, character density, and white space ratio, to quantitatively compare the layout before and after conversion; fine-tuning the font size, line spacing, and paragraph spacing attributes of the layout document based on the consistency evaluation results, controlling the differences between the converted layout and the original streaming layout in various indicators within an acceptable range; and performing a final layout consistency check to ensure that the converted layout document maintains a high degree of consistency with the original streaming document in terms of visual effect and information density.
[0104] The following describes this embodiment in conjunction with an application scenario:
[0105] Data Flow and System Architecture: Outputs include an ordered list of HTML files, a set of CSS rules, and a resource index table. These outputs provide the foundational data source for all subsequent modules. A feature matrix and feature index table are also included, with the feature index table being the core shared data structure of the entire system. It records all key information for each page, including its six-dimensional feature values, identified layout type, applied style parameters, pagination score, and defect detection results. The data flow for the target layout parameter setting phase includes: a page type classification vector, a style mapping instruction set, an optimal pagination position list, an image position and size instruction set, and a repair operation list. This output records the specific repair measures taken for each detected defect. Finally, a Word document is provided.
[0106] Layout type recognition is implemented using a rule engine, requiring no model training. For each page, the system checks whether it meets the criteria for various layout types in priority order; if the criteria are met, it is classified as that type. Compared to deep learning, this method is fully interpretable, fast in execution, and does not rely on GPU resources.
[0107] Pagination optimization is achieved through a three-dimensional scoring mechanism. First, all possible pagination candidates are identified. Each candidate is scored based on three dimensions: content completeness, page fill rate, and contextual relevance. The candidate with the highest overall score is then selected.
[0108] The optimization of column layout is achieved through a two-dimensional scoring mechanism based on column height balance and content coherence. All possible candidate column layout points are identified, the column height difference and content breakage degree of each candidate point are calculated, and the position that provides the most balanced column heights and the most complete content is selected as the column layout point.
[0109] The optimization of mixed text and image layout is achieved through heuristic association analysis. Multiple candidate insertion positions are scored for each image, taking into account factors such as distance, content relevance, and layout feasibility. The position with the highest overall score is then selected. This ensures that the image is both close to its original position and highly relevant to the surrounding text, without disrupting the page layout.
[0110] Defect detection and repair are implemented using a tiered repair strategy. For each defect type, the system starts with the lightest repair solution and gradually upgrades to more aggressive solutions. During the repair process, it continuously verifies whether new defects have been introduced, ensuring the final Word document quality.
[0111] Comparison of effects before and after conversion:
[0112] The Word document generated according to this embodiment maintains a high degree of consistency with the original Epub document in the following aspects:
[0113] Complete preservation of style properties: Through precise CSS to Word style mapping, the font, color, size style properties in the original Epub document are completely preserved in the Word document.
[0114] Significant improvement in layout quality: Through pagination optimization and defect detection and repair, the generated Word documents avoid common layout problems such as isolated titles, truncated tables, and separation of figures and titles, resulting in a significant improvement in layout quality.
[0115] Significant improvement in reading experience: Through optimized text and image integration, images are more closely related to the surrounding text, improving reading fluency.
[0116] Significant reduction in human intervention: Compared with traditional manual conversion methods, the automatic conversion method of this application significantly reduces the need for human intervention, and the converted documents are basically of usable quality.
[0117] like Figure 9 As shown, this embodiment includes a parsing module for parsing the compressed structure of the streaming document, reading the manifest file to determine the reading order, extracting all content files, style files, and image resource files in sequence, and establishing a resource index table; a layout parameter setting module for receiving and managing target layout parameters (paper size, column layout); a feature extraction module for calculating a six-dimensional layout feature vector for each streaming document page, including text density, image proportion, title distribution entropy, white space ratio, structural complexity, and style diversity, performing Z-score normalization on all features, and outputting a feature matrix and feature index table; a layout analysis module for identifying and classifying the layout type of each page based on a rule engine, including cover, copyright page, table of contents, main text, and appendix types, and outputting a page type classification vector and a layout structure relationship diagram; an adaptive adjustment module for dynamically adjusting the style mapping rules according to the target layout parameters; and an extraction module for parsing the streaming document structure and extracting various content elements such as text content, images, tables, and lists. The system comprises the following modules: **Associated Style Information:** Establishes a correspondence between elements and styles; **Layout Optimization Module:** Performs pagination optimization, column optimization, and mixed text / image layout optimization; **Image / Text Processing Module:** Calculates the optimal insertion position and display size for each image, considering multiple scoring dimensions such as distance, content relevance, and layout factors, and outputs a set of image position and size instructions; **Defect Detection Module:** Scans and detects typical layout defects such as isolated titles, tables spanning multiple pages, and image-title separation, outputting a list of defects and their location information based on detection criteria; **Repair Module:** Executes a tiered repair strategy based on the defect list, gradually attempting repairs from lightweight to heavyweight for each type of defect, verifying whether new defects are introduced after repair; **Conversion Module:** Performs style conversion based on a mapping table, converting extracted flow document style attributes into corresponding layout document style attributes; **Construction Module:** Creates layout document objects, adds content elements one by one according to the reading order, applies the converted styles, inserts page breaks, applies defect repair operations, and finally generates a layout document that meets the requirements.
[0118] For the purpose of simplicity, the method steps disclosed in the above embodiments are described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.
[0119] like Figure 10 As shown, the present invention also provides a streaming document conversion system, comprising:
[0120] The streaming document parsing module 201 is configured to parse the internal structure of streaming documents, extract content files, style files, and resource files, and build file index tables and resource index tables.
[0121] The multi-dimensional layout feature vector extraction and processing module 202 is configured to extract multi-dimensional layout feature vectors for each content page, perform standardization processing, and establish a feature matrix and feature index table. The multi-dimensional layout feature vectors include text density features, image proportion features, title distribution entropy features, blank rate features, structural complexity features, and style diversity features.
[0122] The target layout parameter setting module 203 is configured to set target layout parameters based on user input or preset configuration, including paper size, page margins, column layout and column spacing.
[0123] The layout type recognition module 204 is configured to recognize the layout type of each page, output the page type classification results, and establish a page type classification vector and a layout structure relationship table.
[0124] The mapping rule set establishment module 205 is configured to adaptively adjust the style mapping parameters based on the target layout parameters and page type classification results, and establish a mapping rule set from flow document style to layout document style;
[0125] The layout document generation module 206 is configured to perform layout optimization processing, detect layout defects and repair them using a hierarchical repair strategy, and generate layout documents based on the mapping rule set and layout optimization processing results. The layout optimization processing includes pagination optimization based on a multi-dimensional scoring mechanism, column optimization based on a two-dimensional scoring mechanism, and graphic and text mixed layout optimization based on heuristic analysis.
[0126] like Figure 11 As shown, the present invention also provides an electronic device, including: a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of a streaming document conversion method.
[0127] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. For example... Figure 11 The structure shown in this embodiment of the invention includes an electronic device comprising one or more processors 710 and a memory 720; the processors 710 in this electronic device may be one or more. Figure 11 Taking a processor 710 as an example; a memory 720 is used to store one or more programs; the one or more programs are executed by the one or more processors 710, so that the one or more processors 710 implement a streaming document conversion method as described in any one of the embodiments of the present invention.
[0128] The electronic device may also include an input device 730 and an output device 740.
[0129] The processor 710, memory 720, input device 730, and output device 740 in this electronic device can be connected via a bus or other means. Figure 11 Taking the example of a connection between China and Israel via a bus.
[0130] The memory 720 in this electronic device serves as a computer-readable storage medium, capable of storing one or more programs. These programs can be software programs, computer-executable programs, or modules, such as the program instructions / modules corresponding to the streaming document conversion method provided in this embodiment of the invention. The processor 710 executes various functional applications and data processing of the electronic device by running the software programs, instructions, and modules stored in the memory 720, thereby implementing the streaming document conversion method described in the above embodiment.
[0131] The memory 720 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the electronic device. Furthermore, the memory 720 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 720 may further include memory remotely located relative to the processor 710, which can be connected to the device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0132] Input device 730 can be used to receive input digital or character information, and to generate key signal inputs related to user settings and function control of the electronic device. Output device 740 may include display devices such as a display screen.
[0133] The present invention also provides a computer-readable storage medium storing a computer program executable by an electronic device, which, when run on the electronic device, causes the electronic device to perform the steps of a streaming document conversion method.
[0134] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.< / spine>
Claims
1. A streaming document conversion method, characterized in that, include: Analyze the internal structure of the streaming document, extract the content file, style file, and resource file, and build a file index table and a resource index table; For each content page, a multidimensional layout feature vector is extracted and standardized to establish a feature matrix and a feature index table. The multidimensional layout feature vector includes text density features, image proportion features, title distribution entropy features, blank rate features, structural complexity features, and style diversity features. Set the target layout parameters based on user input or preset configuration, including paper size, margins, column layout and column spacing; For each page, identify the layout type, output the page type classification results, and establish a relationship table between the page type classification vector and the layout structure. Based on the target layout parameters and page type classification results, the style mapping parameters are adaptively adjusted to establish a mapping rule set from flow document style to layout document style; The layout optimization process is performed, layout defects are detected and repaired using a hierarchical repair strategy, and a layout document is generated based on the mapping rule set and the layout optimization process results. The layout optimization process includes pagination optimization based on a multi-dimensional scoring mechanism, column optimization based on a two-dimensional scoring mechanism, and image and text mixed layout optimization based on heuristic analysis.
2. The streaming document conversion method according to claim 1, characterized in that, Parse the internal structure of the streaming document, extract content files, style files, and resource files, and build file index tables and resource index tables. Further steps include: Parse the compressed structure of the streaming document and read the manifest file to determine the reading order; Extract all content files in the order they are read; Extract all style files; Extract all image resource files and create the resource index table to record the identifier, storage path, and original size of each image.
3. The streaming document conversion method according to claim 1, characterized in that, For each content page, a multi-dimensional layout feature vector is extracted and standardized to establish a feature matrix and a feature index table. The multi-dimensional layout feature vector includes text density features, image proportion features, title distribution entropy features, white space ratio features, structural complexity features, and style diversity features, further including: The text density feature is calculated based on the number of characters per unit area; The image proportion feature is calculated by weighting based on image size, location, and content relevance; The title distribution entropy feature is calculated based on the probability of occurrence of each level of title. Calculate the blank rate feature, structural complexity feature, and style diversity feature, and standardize all features to establish the feature matrix and feature index table.
4. The streaming document conversion method according to claim 1, characterized in that, Set the target layout parameters based on user input or preset configuration, including paper size, margins, column layout, and column spacing, and further include: Set paper specifications, including paper type, page orientation, and margins; Set the column layout parameters, including column number settings, column spacing, and column width allocation method; Set layout style parameters, including heading style hierarchy, body text format specifications, and chart display methods; Set special layout rules, including format requirements for the cover page, table of contents, and appendix pages.
5. The streaming document conversion method according to claim 1, characterized in that, For each page, perform layout type identification, output page type classification results, and establish a page type classification vector and layout structure relationship table, further including: A rules engine is used to identify the layout type of each page; Output page type classification results based on the recognition results; Establish a page type classification vector to record the type information of each page; Establish the layout structure relationship table to describe the structural relationships and order between pages.
6. The streaming document conversion method according to claim 1, characterized in that, Based on the target layout parameters and page type classification results, the style mapping parameters are adaptively adjusted to establish a mapping rule set from flow document style to layout document style, further including: Adjust the font size conversion factor, line spacing and paragraph spacing ratio, and maximum image size limit based on paper specification parameters; Adjust column width, long paragraph crossover layout, and image display based on column number layout parameters; Adjust page layout rules based on page type classification results; Establish the mapping rule set and define the conversion relationship of style attributes.
7. The streaming document conversion method according to claim 1, characterized in that, Perform layout optimization processing, detect layout defects and repair them using a tiered repair strategy, and generate a layout document based on the mapping rule set and layout optimization processing results. The layout optimization processing includes pagination optimization based on a multi-dimensional scoring mechanism, column optimization based on a two-dimensional scoring mechanism, and image-text mixed layout optimization based on heuristic analysis, and further includes: The pagination optimization is performed by selecting the pagination position based on a three-dimensional scoring mechanism of content completeness, page fill rate, and context relevance. Perform the column optimization, and select the column position based on the column height balance score and content coherence score; The image and text layout optimization is performed by calculating the image insertion position and display size based on the distance factor, content relevance factor, and layout factor. The system detects layout defects such as isolated titles, separated figures and titles, tables spanning multiple pages, and broken columns, and uses the described hierarchical repair strategy to repair these defects and generate a layout document.
8. A streaming document conversion system, characterized in that, include: The streaming document parsing module is configured to parse the internal structure of streaming documents, extract content files, style files, and resource files, and build file index tables and resource index tables. The multi-dimensional layout feature vector extraction and processing module is configured to extract multi-dimensional layout feature vectors for each content page, perform standardization processing, and establish a feature matrix and feature index table. The multi-dimensional layout feature vectors include text density features, image proportion features, title distribution entropy features, blank rate features, structural complexity features, and style diversity features. The target layout parameter setting module is configured to set target layout parameters based on user input or preset configuration, including paper size, page margins, column layout and column spacing. The layout type recognition module is configured to identify the layout type of each page, output the page type classification results, and establish a page type classification vector and a layout structure relationship table. The mapping rule set establishment module is configured to adaptively adjust the style mapping parameters based on the target layout parameters and page type classification results, and establish a mapping rule set from flow document style to layout document style; The layout document generation module is configured to perform layout optimization processing, detect layout defects and repair them using a hierarchical repair strategy, and generate layout documents based on the mapping rule set and layout optimization processing results. The layout optimization processing includes pagination optimization based on a multi-dimensional scoring mechanism, column optimization based on a two-dimensional scoring mechanism, and image and text mixed layout optimization based on heuristic analysis.
9. An electronic device, characterized in that, include: The system includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus; the memory stores a computer program, which, when executed by the processor, causes the processor to perform the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, It stores a computer program executable by an electronic device, which, when run on the electronic device, causes the electronic device to perform the steps of the method according to any one of claims 1 to 7.