Content truncation and restoration method in process of converting webpage to PDF (Portable Document Format)
By obtaining web page DOM structure tree and browser screenshot technology, combining width standardization and DOM element analysis, the problem of content truncation during web page conversion to PDF is solved, and the integrity repair of web page elements and dynamic web page support is achieved.
Patent Information
- Application Number
- CN202510307667.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-17
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2045-03-17
AI Technical Summary
In the prior art, there is a problem of content truncation in the process of web page conversion to PDF, especially when the web page height is greater than 32,767 pixels or the standard PDF A4 size is inconsistent with the web page size, text, tables, pictures or seals are prone to truncation.
By obtaining the basic data set of the DOM structure tree of the web page, using browser screenshot technology to take full screenshots, combining the screenshots to form a large picture, and standardizing the width of the large picture. Then, the truncation processing rules are formed through the analysis of the DOM element definition, the pictures are truncated, and multiple segmented picture data sets are formed, and PDF conversion is finally performed.
It effectively solves the problem of element truncation during web page conversion to PDF, realizes the integrity repair of text, tables, pictures or seals, supports the conversion of static and dynamic web pages, and can customize the repaired HTML element types.
Smart Images

Figure CN119830865A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a method for repairing content truncation during a webpage to PDF conversion process. Background Art
[0002] The function of converting web pages to PDF is currently quite common. Generally, users will achieve PDF conversion by manual printing. Since printing can only be done manually, batch conversion of web pages to PDF can only be achieved through software. Whether it is manual processing or software processing, the converted PDF usually has the following problems: 1. Software processing: When a web page is very long (generally greater than 32767 pixels in height), it is impossible to capture the complete image through the front-end code or the browser's built-in functions.
[0003] 2. Software processing: Since the standard PDF A4 size and the web page size are basically inconsistent, there may be problems with truncation of text, tables, stamps, images or other elements after the web page is converted to PDF.
[0004] 3. Manual processing: Although the print preview will automatically process text, pictures, tables, etc. to avoid truncation; however, some customized signatures and seals still cannot avoid truncation.
[0005] 4. Traditional archiving PDF technology on the market has poor support for dynamic web pages (the page loads the structure first and then the data), and there are problems such as incomplete data loading and element truncation. Summary of the invention
[0006] In view of the problem of text, table, picture or seal truncation in the process of converting web page to PDF in the above-mentioned prior art, the present invention provides a method for repairing content truncation in the process of converting web page to PDF, which effectively solves the problem of element truncation.
[0007] The present invention provides a method for repairing content truncation during the process of converting a web page to PDF, comprising the following steps: Step 1: Obtain a basic data set of the web page DOM structure tree for the web page to be processed; Step 2: For the web page to be processed, a browser screenshot technology is used to perform full-screen screenshot processing on the web page to be processed, and multiple web page screenshot images are obtained; Step 3: merge all webpage screenshots in order from top to bottom to form a large image, and the height of the large image is determined based on the height and height of all webpage screenshots; Step 4, standardize the width of the large image in step 3 and correct the width to the width of the standard A4 size; Step 5, performing DOM element definition analysis on the width-normalized large image in step 4 using the DOM structure tree data set generated in step 1, analyzing the relationship between the position of each row of pixels in the large image and the position of the DOM element in the web page, and forming a first truncation processing rule; Step 6, truncating the image generated in step 4 within the A4 size according to the first truncation processing rule to form multiple segmented image data sets; Step 7: Convert the image dataset generated in step 6 into a PDF file to form a complete PDF file.
[0008] In some embodiments, the step 1 comprises: For the web page to be processed, the current element is obtained, and whether the current element belongs to a preset truncation information type is analyzed, and the preset truncation information type includes a picture, a table, and a seal; If the current element belongs to the preset truncation information type, the type, coordinates, and size parameters of the element are extracted through a processing function.
[0009] In some embodiments, the step 2 includes: Use browser screenshot technology to take screenshots of web pages opened by the browser. If it is a multi-screen page, multiple pictures will be generated; When the height of a web page is greater than the maximum height of a single static screenshot of the browser screenshot technology, a scrolling screenshot is performed on the web page to generate image array data.
[0010] In some embodiments, the step 3 comprises: Pre-create a large image of original size, wherein the width of the large image of original size is greater than the width of the webpage, and the height of the large image of original size is greater than the height of the webpage in step 1; Import the screenshots in step 2 into the large image one by one.
[0011] In some embodiments, step 4 comprises: According to the data generated in step 1, determine the coordinate data of the blank range of the page; The large image generated in step 3 is edge-cut according to the coordinate data of the blank range of the page, and then the page of the large image is enlarged to make its width consistent with the width of A4.
[0012] In some embodiments, the step 5 comprises: Step 51, scanning and analyzing pixels of the width-normalized large image generated in step 4 row by row in reverse order from the bottom to the top; Step 52, for each row of pixels, analyze the relationship between the position of the current row of pixels and the position of the element belonging to the preset truncation information type; if a part or all of the pixels in the current row of pixels are within the coordinate range of the element, or a part or all of the pixels in the current row of pixels are at the edge of the coordinate range of the element, then mark the current row as non-truncation, forming the first truncation processing rule data.
[0013] In some embodiments, the step 5 further includes: determining a second truncation processing rule for the width-normalized large image in step 4 by using a background color continuity determination rule; The step 6 further includes: truncating the width-standardized large image generated in step 4 within the A4 size according to a second truncation processing rule.
[0014] In some embodiments, the second truncation processing rule is determined by using a background color continuity determination rule for the width normalized large image in step 4, including: Step 53, color classification of the pixels in the current pixel row, and calculation of the total number of color categories a and the total number of color pixels in each category T; Step 54, obtaining the distance standard deviation d of the positions of the same category color pixels; Step 55, if the total number of color categories a is less than the first preset value, and the distance standard deviation of the pixel position of the color with the largest color proportion is less than the second preset value, determine that the current row is included in the non-truncation rule, which is recorded as the second truncation processing rule.
[0015] In some implementations, in step 6, the width-standardized large image generated in step 4 is truncated within the A4 size according to the first truncation processing rule and the second truncation processing rule, including: Step 61, for the width-normalized large image generated in step 4, count from the first pixel row, and when reaching the pixel row of A4 size height, determine whether the current pixel row belongs to the first truncation processing rule or the second truncation processing rule; if not, proceed to step 62; if yes, proceed to step 63; Step 62, if it does not belong to, then cut off at the current pixel row to form an A4 size image, and take the next pixel row of the current pixel row as the first row, start counting, and execute step 61; Step 63, if yes, then go back to the pixel row that does not belong to the first truncation processing rule and the second truncation processing rule, record it as pixel row L1, truncate at the position of pixel row L1, and start counting with the next pixel row of pixel L1 as the first row, and execute step 61; Step 64, if the height of the truncated image is less than the height of the A4 size, a blank image filled with blank elements is added at the bottom so that the height of the truncated image after adding the blank image reaches the height of the A4 size.
[0016] In some implementations, step 7 includes: for all A4-sized images generated in step 6, converting them one by one into single PDF pages of A4 standard size using a PDF conversion tool, and finally merging them into a whole PDF.
[0017] The content truncation repair method in the process of converting a web page to PDF of the present invention has the following beneficial effects: 1. You can customize the types of HTML elements to be processed and repaired in a flexible way.
[0018] 2. Supports repair of element truncation data.
[0019] 3. It not only supports the conversion and repair of static web pages, but also supports the conversion and repair of dynamic web pages (the data content is changing).
[0020] 4. This method is implemented through software and can automatically process multiple tasks simultaneously. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 It is a flow chart of a method for repairing content truncation during the process of converting a web page to PDF in an embodiment of the present application; Figure 2 It is a flowchart of a method for truncating the image generated in step 4 within the A4 size in an embodiment of the present application. DETAILED DESCRIPTION
[0022] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0023] Example 1
[0024] See also Figure 1 and Figure 2 The present application embodiment provides a method for repairing content truncation during the process of converting a web page to PDF, comprising the following steps: Step 1: Obtain a basic data set of the web page DOM structure tree for the web page to be processed; Specifically, step 1 includes the following steps: Step 11, for the web page to be processed, obtain the current element, and analyze whether the current element belongs to a preset truncation information type. Specifically, the preset truncation information type can be customized according to the scene requirements. For example, the preset truncation information type includes pictures, tables, seals, etc.; Step 12, if the current element belongs to the preset truncation information type, the type, coordinates, and size parameters of the element are extracted through the processing function getHtmlCoordinate(e). It should be noted that the coordinate parameters of the element are the coordinate data relative to the top of the web page, and the obtained coordinate data are the horizontal and vertical coordinate values relative to the upper left corner of the web page.
[0025] In the embodiment of the present application, the processing function getHtmlCoordinate(e) is a custom function. This function first calls the system function document.getElementsByTagName("F") (where F can be an element type such as table, img, div, etc.) to obtain the specified element information (but not all elements are required. In one implementation, element information such as table, img, div, etc. can be filtered), and returns the result element; Then, the element rectangle size and coordinate information are obtained by calling the system function element.getBoundingClientRect. For elements with borders, the border data is obtained by calling the system function window.getComputedStyle(element).getPropertyValue("border-width"), and the element coordinates, length, width and border size data are obtained in turn.
[0026] Step 2: For the web page to be processed, a browser screenshot technology is used to perform full-screen screenshot processing on the web page to be processed, and multiple web page screenshot images are obtained; The step 2 specifically includes the following steps: Step 21, using browser screenshot technology to take screenshots of the web page opened by the browser, and if it is a multi-screen page, multiple pictures are generated; Step 22, when the height of the web page is greater than the maximum height of a single static screenshot of the browser screenshot technology, a scrolling screenshot process is performed on the web page to generate image array data.
[0027] In one implementation, the above step 2 can be implemented in the following manner: Step 23, using selenium webdriver to take screenshots of the web page opened by the browser, and if it is a multi-screen page, multiple pictures are generated.
[0028] In one implementation, the above step 2 may also be implemented in the following manner: Step 24, when the height of the web page is greater than 32767 pixels, a scrolling screenshot is taken of the web page to generate image array data.
[0029] Step 3: merge all webpage screenshots in order from top to bottom to form a large image, and the height of the large image is determined based on the height and height of all webpage screenshots; The step 3 specifically includes the following steps: Step 31, pre-create a large image of original size, the width of the large image of original size is larger than the width of the webpage, for example, twice the size of 72dpi A4 size, that is, 1190 pixels; the height of the large image of original size is larger than the height of the webpage in step 1; Step 32, importing the screenshots in step 2 into the large image one by one.
[0030] Step 4, standardize the width of the large image in step 3 and correct the width to the width of the standard A4 size; In this step 4, it specifically includes: Step 41, determining the page blank range coordinate data according to the data generated in step 1; Step 42, cutting the edge of the large image generated in step 3 according to the coordinate data of the blank range of the page, and then enlarging the page of the large image to make its width consistent with the width of A4, so that the data in the image will be clearer.
[0031] Step 5, performing DOM element definition analysis on the width-normalized large image in step 4 using the DOM structure tree data set generated in step 1, analyzing the relationship between the position of each row of pixels in the large image and the position of the DOM element in the web page, and forming a first truncation processing rule; This step 5 specifically includes: Step 51, scanning and analyzing pixels of the width-normalized large image generated in step 4 row by row in reverse order from the bottom to the top; Step 52, for each row of pixels, analyze the relationship between the position of the current row of pixels and the position of the element belonging to the preset truncation information type; if a part or all of the pixels in the current row of pixels are within the coordinate range of the element, or a part or all of the pixels in the current row of pixels are at the edge of the coordinate range of the element, then mark the current row as non-truncation, forming the first truncation processing rule data.
[0032] Specifically, for the width-normalized large image generated in step 4, the position of the corresponding DOM element is located on the width-normalized large image according to the coordinate position of each DOM element in the web page. In the embodiment of the present application, in one case, the width-normalized large image generated in step 4 is not scaled compared to the displayed content of the web page in step 1, at least not scaled in the height direction. Then, under the premise that the coordinate position P of a certain DOM element (element such as a picture, table, seal, etc.) on the web page is known, the position of the DOM element on the width-normalized large image can be determined at the same position P of the width-normalized large image, and then it can be determined whether it can be truncated at the same coordinate position P of the width-normalized large image. At the same time, consider another case. After the web page screenshot image is processed based on the aforementioned steps 2, 3, and 4, the width-normalized large image generated in step 4 may deviate from the size and position of the displayed content of the web page in step 1. In this case, it is necessary to determine the more accurate pixel row area of elements such as pictures, tables, seals, etc. in the width-normalized large image. Therefore, in the embodiment of the present application, before the above step 51, the following steps are included: step 50, determining whether the display content at the same position of the width-normalized large image generated in step 4 and the web page in step 1 are the same. It can be understood that when the display content at the same position of the two is the same, the pixel row occupied by the element in the large image can be determined based on the coordinate position of the DOM element on the web page. This step 50 includes: Step 501, determining the coordinate position of each element of the preset truncation information type in the web page according to the DOM structure tree data set generated in step 1 (the coordinate position is the coordinate value relative to the top of the web page); Step 502, selecting at least three elements of preset truncation information types in the webpage as elements to be referenced, and obtaining coordinate positions of the elements to be referenced in the webpage, wherein the at least three elements of preset truncation information types preferably use different truncation information types; Step 503, based on the coordinate position of the element to be referenced, determine the same coordinate position (relative to the coordinate value at the top of the large image) of the width normalized large image generated in step 4 as the preliminary pixel area of the element to be referenced; Step 504, pixel matching is performed based on the preliminary pixel region of the element to be referenced and the coordinate position region image of the element to be referenced in the webpage, and whether the same coordinate position in the webpage and the width-normalized large image has the same content based on the matching result: if the features of a preset number of pixels dispersed in the preliminary pixel region of the element to be referenced are consistent with the features of a preset number of pixels in the coordinate position region image of the element to be referenced in the webpage (the features include the position of the pixel relative to the upper left corner of the region image, the gray value of the pixel, and the distribution of the gray value of the pixel's neighborhood pixels), then it is determined that the content of the same position in the width-normalized large image generated in step 4 is consistent with that in the webpage; Then, step 51 is executed to scan and analyze pixels of the width-normalized large image generated in step 4 row by row from the bottom to the top in reverse order; Then, step 52 is performed to analyze the relationship between the position of the current row of pixels in the large image and the coordinate position of the element of the preset truncation information type on the web page for each row of pixels. If a part of the pixels or all of the pixels in the current row of pixels are within the coordinate range of the element, or a part of the pixels or all of the pixels in the current row of pixels are at the edge of the coordinate range of the element, the current row is marked as non-truncation, and the first truncation processing rule data is formed. For example, if the coordinate position of the element of the preset truncation information type on the web page is [(200, 14600), (400, 14800)] (the upper left corner coordinate and the lower right corner coordinate of the element on the web page), then the element corresponds to the pixel row between the 14600th row and the 14800th row (including the 14600th row and the 14800th row) in the large image. If the pixel row currently scanned is between the 14600th row and the 14800th row (including the 14600th row and the 14800th row), it is determined that the pixel row currently scanned cannot be truncated.
[0033] In the above step 504, the pixel matching, in one embodiment, is determined based on whether the pixel values of the pixels to be matched in the two regional images are consistent and whether the grayscale distribution characteristics of the neighborhood pixels of the pixels to be matched in the two regional images are consistent, and the pixels to be matched use a preset number of pixels at random positions in the regional images. Furthermore, in order to subsequently determine whether to further reduce or enlarge the width-normalized large image generated in step 4, another pixel matching method is provided. In another embodiment, the pixel matching includes: based on at least one pixel point in the preliminary pixel area of the element to be referenced as the pixel point to be matched, a matching pixel point is matched in the coordinate position regional image of the element to be referenced in the web page, the pixel features of the matching pixel point and the pixel point to be matched (the pixel features can be pixel grayscale values) are consistent, and the pixel feature distribution of the domain pixel points of the matching pixel point is consistent with the pixel feature distribution of the domain pixel points of the pixel point to be matched (the pixel features can be pixel grayscale values); the matching result is determined based on the difference in the position of the pixel point to be matched and the corresponding matching pixel point relative to the upper left corner of the regional image: if the pixel point to be matched and the corresponding matching pixel point relative to the regional image If the positions of the upper left corners are the same, it is determined that the width-normalized large image generated in step 4 is consistent with the content of the same position on the web page; otherwise, it is determined that the width-normalized large image generated in step 4 is further reduced or enlarged according to the position difference to eliminate the difference (it should be noted that the above “the distribution of pixel features of the domain pixels of the matching pixels is consistent with the distribution of pixel features (pixel features can be pixel grayscale values) of the domain pixels of the pixels to be matched” indicates that compared with other pixels in the coordinate position area image of the element to be referenced in the web page, the pixel feature distribution of the domain pixels of the matching pixels in the coordinate position area image of the element to be referenced in the web page and the pixel feature distribution of the domain pixels of the pixel to be matched are most similar).
[0034] The above step 504 also includes, if the features of the pixels dispersed at the preset number of positions in the two regional images cannot be matched, it is determined that the width-normalized large image generated in step 4 is inconsistent with the content at the same position of the web page; then based on the matching result, it is determined whether to further reduce or enlarge the width-normalized large image generated in step 4. For example, if the pixel features and the distribution of the grayscale values of the pixel neighborhood pixels are consistent in the two regional images but the positions are different, then it is determined whether to further reduce or enlarge the width-normalized large image generated in step 4 according to the position difference.
[0035] Step 6, truncating the width-normalized large image generated in step 4 within the A4 size according to the first truncation processing rule to form a plurality of segmented image data sets; This step 6 specifically includes: Step 61, for the width-normalized large image generated in step 4, count from the first pixel row, and when reaching the pixel row of A4 size height, determine whether the current pixel row belongs to the first truncation processing rule; if not, proceed to step 62, if yes, proceed to step 63; Step 62, if it does not belong to, then cut off at the current pixel row to form an A4 size image, and take the next pixel row of the current pixel row as the first row, start counting, and execute step 61; Step 63, if yes, then go back to the pixel row that does not belong to the first truncation processing rule, record it as pixel row L1, truncate at the position of pixel row L1, and start counting with the next pixel row of pixel L1 as the first row, and execute step 61; Step 64, if the height of the truncated image is less than the height of the A4 size, a blank image filled with blank elements is added at the bottom so that the height of the truncated image after adding the blank image reaches the height of the A4 size.
[0036] Step 7: Convert the image dataset generated in step 6 to PDF to form a complete PDF.
[0037] Step 7 includes: for all A4-sized images generated in step 6, converting them one by one into single PDF pages of A4 standard size through a PDF conversion tool, and finally merging them into a whole PDF.
[0038] Example 2
[0039] In another embodiment, considering that the data processed in step 5 is usually quite accurate, but since the data set generated in step 1 is floating point, there is a slight error between it and the pixel coordinate set (integer data) in step 5 (there is an error in converting floating point to integer); therefore, it is necessary to add a patching step to further improve step 5 of the above embodiment 1, and further adapt step 6.
[0040] See also Figure 1 and Figure 2 The present application embodiment provides a method for repairing content truncation during the process of converting a web page to PDF, comprising the following steps: Execute steps 1 to 4 as described in the above embodiment 1 in sequence. The definitions of steps 1 to 4 in the embodiment of the present application are consistent with steps 1 to 4 described in the above embodiment 1; Step 5 includes: performing DOM element definition analysis on the image in step 4 using the DOM structure tree data set generated in step 1 to form a first truncation processing rule; and a method for obtaining the first truncation processing rule includes: Step 51, scanning and analyzing pixels of the image generated in step 4 row by row from the bottom to the top in reverse order; Step 52, for each row of pixels, analyze the relationship between the position of the current row of pixels and the position of the element belonging to the preset truncation information type; if a part or all of the pixels in the current row of pixels are within the coordinate range of the element, or a part or all of the pixels in the current row of pixels are at the edge of the coordinate range of the element, then mark the current row as non-truncation, forming the first truncation processing rule data.
[0041] The step 5 also includes determining a second truncation processing rule for the image in step 4 by using a background color continuity determination rule. The method for obtaining the second truncation processing rule includes: Step 53, color classification of the pixels in the current pixel row, and calculation of the total number of color categories a and the total number of color pixels in each category T; Step 54, obtaining the distance standard deviation d of the positions of the same category color pixels; Step 55, if the total number of color categories a is less than a first preset value (for example, the first preset value is 5), and the distance standard deviation of the position of the pixel of the color with the largest color proportion is less than a second preset value (for example, the second preset value is 50), then determine that the current row is included in the non-truncation rule, which is recorded as the second truncation processing rule.
[0042] It should be noted that before color classification is performed on the pixels of the current pixel row in step 53, background color data is retrieved for exclusion, and then color classification is performed on the pixels of the current pixel row.
[0043] Further, in step 6, it includes: truncating the image generated in step 4 within the A4 size according to the first truncation processing rule and the second truncation processing rule. This step 6 specifically includes: Step 61, for the image generated in step 4, count from the first pixel row, and when reaching the pixel row of A4 size height, determine whether the current pixel row belongs to the first truncation processing rule or the second truncation processing rule; if not, proceed to step 62, if yes, proceed to step 63; Step 62, if it does not belong to, then cut off at the current pixel row to form an A4 size image, and take the next pixel row of the current pixel row as the first row, start counting, and execute step 61; Step 63, if yes, then go back to the pixel row that does not belong to the first truncation processing rule and the second truncation processing rule, record it as pixel row L1, truncate at the position of pixel row L1, and start counting with the next pixel row of pixel L1 as the first row, and execute step 61; Step 64, if the height of the truncated image is less than the height of the A4 size, a blank image filled with blank elements is added at the bottom so that the height of the truncated image after adding the blank image reaches the height of the A4 size.
[0044] Then, step 7 is executed to convert the image data set generated in step 6 into PDF to form a complete PDF. The specific definition of step 7 is consistent with step 7 in the above embodiment 1.
[0045] The present invention is not limited to the above-mentioned specific implementation modes. Various changes made by ordinary technicians in this field based on the above-mentioned concepts without creative work are all within the protection scope of the present invention.
Claims
1. A method for repairing content truncation during web page to PDF conversion, characterized in that: The steps include: Step 1: Obtain a basic data set of the web page DOM structure tree for the web page to be processed; Step 2: For the web page to be processed, a browser screenshot technology is used to perform full-screen screenshot processing on the web page to be processed, and multiple web page screenshot images are obtained; Step 3: merge all webpage screenshots in order from top to bottom to form a large image, and the height of the large image is determined based on the height and height of all webpage screenshots; Step 4, standardize the width of the large image in step 3 and correct the width to the width of the standard A4 size; Step 5, performing DOM element definition analysis on the width-normalized large image in step 4 using the DOM structure tree data set generated in step 1, analyzing the relationship between the position of each row of pixels in the large image and the position of the DOM element in the web page, and forming a first truncation processing rule; Step 6, truncating the image generated in step 4 within the A4 size according to the first truncation processing rule to form multiple segmented image data sets; Step 7: Convert the image dataset generated in step 6 into a PDF file to form a complete PDF file.
2. The method for repairing content truncation during webpage to PDF conversion according to claim 1, characterized in that: The step 1 comprises: For the web page to be processed, the current element is obtained, and whether the current element belongs to a preset truncation information type is analyzed, and the preset truncation information type includes a picture, a table, and a seal; If the current element belongs to the preset truncation information type, the type, coordinates, and size parameters of the element are extracted through a processing function.
3. The method for repairing content truncation during webpage to PDF conversion according to claim 1, characterized in that: The step 2 includes: Use browser screenshot technology to take screenshots of web pages opened by the browser. If it is a multi-screen page, multiple pictures will be generated; When the height of a web page is greater than the maximum height of a single static screenshot of the browser screenshot technology, a scrolling screenshot is performed on the web page to generate image array data.
4. The method for repairing content truncation during webpage to PDF conversion according to claim 1, characterized in that: The step 3 comprises: Pre-create a large image of original size, wherein the width of the large image of original size is greater than the width of the webpage, and the height of the large image of original size is greater than the height of the webpage in step 1; Import the screenshots in step 2 into the large image one by one.
5. The method for repairing content truncation during webpage to PDF conversion according to claim 1, characterized in that: The step 4 comprises: According to the data generated in step 1, determine the coordinate data of the blank range of the page; The large image generated in step 3 is edge-cut according to the coordinate data of the blank range of the page, and then the page of the large image is enlarged to make its width consistent with the width of A4.
6. The method for repairing content truncation during webpage to PDF conversion according to claim 1, characterized in that: The step 5 comprises: Step 51, scanning and analyzing pixels of the width-normalized large image generated in step 4 row by row in reverse order from the bottom to the top; Step 52, for each row of pixels, analyze the relationship between the position of the current row of pixels and the position of the element belonging to the preset truncation information type; if a part or all of the pixels in the current row of pixels are within the coordinate range of the element, or a part or all of the pixels in the current row of pixels are at the edge of the coordinate range of the element, then mark the current row as non-truncation, forming the first truncation processing rule data.
7. The method for repairing content truncation during webpage to PDF conversion according to claim 1 or 6, characterized in that: The step 5 further includes: for the width-normalized large image in step 4, determining a second truncation processing rule by using a background color continuity determination rule; The step 6 further includes: truncating the width-standardized large image generated in step 4 within the A4 size according to a second truncation processing rule.
8. The method for repairing content truncation during webpage to PDF conversion according to claim 7, characterized in that: The second truncation processing rule is determined for the width-normalized large image in step 4 by using the background color continuity determination rule, including: Step 53, color classification of the pixels in the current pixel row, and calculation of the total number of color categories a and the total number of color pixels in each category T; Step 54, obtaining the distance standard deviation d of the positions of the same category color pixels; Step 55, if the total number of color categories a is less than the first preset value, and the distance standard deviation of the pixel position of the color with the largest color proportion is less than the second preset value, determine that the current row is included in the non-truncation rule, which is recorded as the second truncation processing rule.
9. The method for repairing content truncation during webpage to PDF conversion according to claim 7, characterized in that: In step 6, the width-standardized large image generated in step 4 is truncated within the A4 size according to the first truncation processing rule and the second truncation processing rule, including: Step 61, for the width-normalized large image generated in step 4, count from the first pixel row, and when reaching the pixel row of A4 size height, determine whether the current pixel row belongs to the first truncation processing rule or the second truncation processing rule; if not, proceed to step 62; if yes, proceed to step 63; Step 62, if it does not belong to, then cut off at the current pixel row to form an A4 size image, and take the next pixel row of the current pixel row as the first row, start counting, and execute step 61; Step 63, if yes, then go back to the pixel row that does not belong to the first truncation processing rule and the second truncation processing rule, record it as pixel row L1, truncate at the position of pixel row L1, and start counting with the next pixel row of pixel L1 as the first row, and execute step 61; Step 64, if the height of the truncated image is less than the height of the A4 size, a blank image filled with blank elements is added at the bottom so that the height of the truncated image after adding the blank image reaches the height of the A4 size.
10. The method for repairing content truncation during webpage to PDF conversion according to claim 1, characterized in that: The step 7 includes: for all the A4-sized pictures generated in step 6, converting them one by one into single PDF pages of A4 standard size through a PDF conversion tool, and finally merging them into a whole PDF.
Citation Information
Patent Citations
Method, device and equipment for generating PDF (Portable Document Format)
CN115861486A
Method and device for generating PDF (Portable Document Format) file of webpage and electronic equipment
CN118260501A
PDF text generation method and device and storage medium
CN118276798A
Page segmentation method and device, equipment and medium
CN118606278A
Front-end dom element-to-pdf downloading method, system and equipment
CN118981577A