Method and system for batch generation and consistent output of document images based on browser instance pool

By dividing document image generation requests into task slices and utilizing structural changes and network request monitoring to generate dynamic rendering convergence and page boundary sensitivity levels, the problems of browser instance management and layout consistency are solved, achieving efficient and stable document image generation.

CN121598922APending Publication Date: 2026-03-03TEKEFA (SHENZHEN) EDUCATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511801741.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-02
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Existing technologies have shortcomings in browser instance management, page rendering and export timing determination, and batch export strategies, making it difficult to meet the requirements of high concurrency and long-term operation, and there are inconsistencies in layout when outputting across environments.

Method used

By dividing batch document image generation requests into task slices, and using structural change monitoring and network request monitoring to generate dynamic rendering convergence level and page boundary sensitivity level, browser instance scheduling and document image export strategy are controlled to achieve consistent output across environments.

Benefits of technology

It significantly reduces content loss and component misalignment issues during page structure changes, identifies the risk of cross-page splitting and element drift of key layout elements, provides refined risk layering control, and ensures the consistency and efficiency of document image generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121598922A_ABST
    Figure CN121598922A_ABST
Patent Text Reader

Abstract

The invention discloses a document image batch generation and consistent output method and system based on a browser instance pool, and relates to the technical field of document image generation, and the method comprises the steps: dividing a batch document image generation request into task slices according to a template identifier and an output type, and distributing browser instances, loading a template page, injecting a ready probe, and registering structure change monitoring and network request monitoring; injecting business data into the task slice record, and generating a dynamic rendering convergence degree grade based on a time interval from data injection to structure stabilization and the number of structural change events; after the page structure is stable, according to the proportion of format key elements in upper and lower boundaries of a page content area and upper and lower critical zones of the page and slice distribution, generating a page boundary sensitivity level, generating a slice risk level label, and controlling browser instance scheduling and document image export and compression strategies; and the export stability and the resource utilization rate are improved while the consistency of cross-environment formats is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of document image generation technology, specifically to a method and system for batch generation of consistent output of document images based on a browser instance pool. Background Technology

[0002] With the development of internet businesses, a large amount of business data needs to be generated in batches from front-end template pages into PDFs or images for archiving, distribution, and printing. Existing technologies are usually based on headless browsers or embedded browser engines, loading template pages, injecting business data, and performing print export on the server side in order to achieve a layout that approximates the front-end display effect.

[0003] Regarding browser instance management, one approach is to start a separate browser instance for each export task. While this provides good isolation, the overhead of starting and destroying the instance is high, making it difficult to meet the needs of high concurrency and long-term operation. Another approach is to reuse a small number of long-lived browser instances. Although this improves throughput, the frequent creation and destruction of pages within the instance can easily lead to memory leaks. If there is an abnormal disconnection or abnormal status, it may cause subsequent tasks to fail or the layout to be abnormal. This approach lacks a fine-grained scheduling and risk control mechanism that combines rendering behavior.

[0004] Regarding the timing of page rendering and export, existing solutions often rely on fixed delays, simple document readiness events, or a small number of network request completion signals. These methods struggle to accurately reflect the true, stable state in complex scenarios such as single-page applications and asynchronous loading, easily leading to export being triggered while the page structure is still changing, resulting in missing content or misaligned layouts. Furthermore, existing technologies typically control print layout only by fixing paper size and margin configurations, lacking quantitative analysis of the spatial relationship between key layout elements such as titles, headers, and signature areas and the top and bottom edges of the page. This makes it impossible to identify and classify sensitive records that are "close to page boundaries and susceptible to differences in pagination algorithms," resulting in inconsistencies such as element drift near page boundaries and page splitting when outputting across different environments.

[0005] In batch export strategies, traditional systems often only perform coarse-grained grouping and queuing based on templates or business types. Browser instance scheduling and document image compression strategies are decoupled from page rendering stability and page boundary sensitivity. A risk measurement and hierarchical control mechanism oriented towards task slices has not been established: high-risk and low-risk records are not differentiated in instance allocation, export configuration, and compression intensity. This results in either an overall conservative approach leading to uncontrollable throughput and final product size, or an overall aggressive approach leading to a lack of guaranteed layout quality. In summary, existing document image generation technologies still have shortcomings in instance pool management, rendering convergence measurement, page boundary sensitivity identification, and risk-based scheduling and output control. Summary of the Invention

[0006] Based on the shortcomings of the prior art described above, the purpose of this invention is to provide a method and system for batch generation of consistent output of document images based on browser instance pools, so as to solve the above-mentioned technical problems.

[0007] To achieve the above objectives, the present invention provides the following technical solution: a method for batch generating consistent output of document images based on a browser instance pool, comprising: The received batch document image generation requests are divided into multiple task slices, and at least one browser instance is assigned to each task slice to load the template page. Once loaded, inject the ready probe, register the structure change listener and network request listener; For each record in the task slice, business data is injected into the template page. Before the ready probe determines the structure is stable, the time interval from data injection to meeting the structural stability criterion and the structural change behavior are determined based on the number of structural change events, time distribution and correlation with network requests, and a dynamic rendering convergence level is generated. After determining that the page structure is stable, determine the effective content area and the top and bottom boundaries of each page, obtain the positions of key layout elements, define the top and bottom critical zones of the page, and statistically analyze the proportion and distribution of key layout elements located in the critical zones to generate page boundary sensitivity levels. At the end of the task slice, a slice risk level label is generated based on the dynamic rendering convergence level and page boundary sensitivity level. Based on the slice risk level label, browser instance scheduling and document image export and compression strategies are controlled to ensure consistent output of document images across environments.

[0008] The present invention is further configured such that the batch document image generation request includes a template identifier, an output type, and a parameter set, and the received batch document image generation request is divided into multiple task slices, including: The records in the parameter set are grouped according to the template identifier and output type, so that the template identifier and output type of the records in the same group are consistent. Within each group, records are divided into multiple task slices based on the number of records and the estimated number of pages, and the number of records in each task slice does not exceed a preset limit.

[0009] The present invention is further configured such that the structural change monitoring is used to monitor at least the addition of nodes, deletion of nodes, migration of node positions in the hierarchical structure, and overall rearrangement of list, table, and title areas; wherein, structural change events occurring in areas marked as layout key areas are counted separately.

[0010] The present invention is further configured such that the structural stability criterion includes: no structural change event is detected within the continuous stable detection time window, and all key network requests related to template page rendering have been completed, and the ready probe returns a rendering completion signal; The dynamic rendering convergence level is generated as follows: when the time interval is less than the first threshold and the number of structural change events is less than the first threshold, it is marked as fast convergence; when the time interval is greater than or equal to the second threshold or the number of structural change events is greater than or equal to the second threshold, it is marked as slow convergence; otherwise, it is marked as medium convergence.

[0011] The present invention is further configured such that determining the effective content area and the upper and lower boundaries of each page includes: mapping the logical page to a vertical coordinate system according to the printing paper size and page margin configuration, and determining the upper and lower boundaries of the content area of ​​each page in the vertical coordinate system; The definition of the page top and bottom critical zones includes: setting a critical zone area at a height that is a fixed proportion of the page height from the top and bottom boundaries of the content area of ​​each page. The statistical analysis of the proportion of layout key elements located in the critical zone includes: counting the number of elements whose bounding rectangles overlap with the critical zone and the proportion of such elements to the total number of layout key elements; and identifying the clustered distribution of multiple adjacent layout key elements on the same page that are simultaneously located in the critical zone.

[0012] The present invention is further configured such that generating page boundary sensitivity levels includes: when the proportion of layout key elements located in the critical zone is less than a first proportion threshold and there is no clustered distribution, it is marked as low sensitivity level; when the proportion of layout key elements located in the critical zone is greater than or equal to the first proportion threshold and less than a second proportion threshold and there is no clustered distribution, it is marked as medium sensitivity level; when the proportion of layout key elements located in the critical zone is greater than or equal to the second proportion threshold or there is a clustered distribution, it is marked as high sensitivity level.

[0013] The present invention is further configured to generate slice risk level labels based on dynamic rendering convergence level and page boundary sensitivity level, including: The dynamic rendering convergence level and page boundary sensitivity level are mapped to three integer levels respectively, and the largest value in each record is taken as the principal risk level, and the absolute value of the difference is taken as the imbalance level. At the end of the task slice, the proportion of records with the primary risk level equal to the highest level to the total number of records in the task slice is counted as the high primary risk proportion; the proportion of records with the primary risk level equal to the highest level and the imbalance level less than or equal to the first imbalance threshold is counted as the double high combined proportion; the proportion of records with the primary risk level equal to the highest level and the imbalance level greater than or equal to the second imbalance threshold is counted as the extreme imbalance proportion. When the proportion of high-risk main tasks exceeds the first risk threshold, and at least one of the proportion of high combined tasks or extreme imbalance exceeds the second risk threshold, the task slice is marked as a high-risk slice; otherwise, it is marked as a low-risk slice.

[0014] The present invention is further configured to control browser instance scheduling based on slice risk level tags, including: When a slice is marked as high-risk, a target browser instance that has completed a restart within a preset time window and has not recorded any abnormal disconnection events is selected from the browser instance pool to host the high-risk slice. Parallel scheduling of multiple high-risk slices on the same browser instance is prohibited. When a slice is marked as low-risk, it allows the low-risk slice to be split across multiple browser instances for parallel scheduling, or to share execution with other low-risk slices on the same browser instance.

[0015] The present invention is further configured such that the document image export and compression strategy based on slice risk level labels includes: When a slice is marked as high-risk, page size priority and background content rendering configuration are enabled when exporting portable document format files, the preset page rules in the template page are applied, and a lossless compression strategy is adopted during the compression stage. When a slice is marked as low-risk, some page settings and background drawing configurations can be simplified, provided that the layout requirements are met, and a high compression ratio strategy is adopted during the compression stage.

[0016] This invention also provides a system for batch generation of consistent output of document images based on browser instance pools, used to implement the above-mentioned method for batch generation of consistent output of document images based on browser instance pools, including: Instance allocation module: Divides the received batch document image generation requests into multiple task slices, allocates at least one browser instance to each task slice, and loads the template page; Listener registration module: After loading, inject ready probes and register structure change listeners and network request listeners; First-level module: Inject business data into the template page for each record in the task slice. Before the ready probe determines the structure is stable, determine the time interval from data injection to meeting the structure stability criterion and the structure change behavior based on the number of structural change events, time distribution and correlation with network requests, and generate dynamic rendering convergence level. The second-level module: After determining that the page structure is stable, it determines the effective content area and the top and bottom boundaries of each page, obtains the positions of key layout elements, defines the top and bottom critical zones of the page, counts the proportion and distribution of key layout elements located in the critical zones, and generates the page boundary sensitivity level. Consistent Output Module: At the end of the task slice, a slice risk level label is generated based on the dynamic rendering convergence level and page boundary sensitivity level. Based on the slice risk level label, the browser instance scheduling and document image export and compression strategies are controlled to achieve consistent output of document images across environments.

[0017] This invention provides a method and system for batch generation of consistent output of document images based on a browser instance pool. The method divides received batch document image generation requests into multiple task slices, assigns at least one browser instance to each task slice, and loads a template page. After loading, a ready probe is injected, and structural change monitoring and network request monitoring are registered. Business data is injected into the template page for each record within the task slice. Before the ready probe determines structural stability, the time interval from data injection to meeting the structural stability criterion and the structural change behavior are determined based on the number of structural change events, their time distribution, and their correlation with network requests, generating a dynamic rendering convergence level. After determining page structural stability, the effective content area and upper and lower boundaries of each page are determined, the positions of key layout elements are obtained, and upper and lower critical zones are defined. The proportion and distribution of key layout elements located in the critical zones are statistically analyzed, generating a page boundary sensitivity level. At the end of the task slice, a slice risk level label is generated based on the dynamic rendering convergence level and the page boundary sensitivity level. Based on the slice risk level label, browser instance scheduling and document image export and compression strategies are controlled to achieve consistent output of document images across environments. The beneficial effects include: 1. By utilizing a joint readiness probe combining structural change monitoring and network request monitoring, the system continuously monitors the time interval and number of structural change events between the injection of business data and the satisfaction of structural stability criteria, categorizing the records into three convergence levels: fast, medium, and slow. Compared to existing solutions that rely on fixed delays or simple readiness events, this dynamic rendering convergence level directly reflects the structural convergence of the page under actual data and network conditions. This allows the export timing to be based on quantifiable rendering behavior, significantly reducing issues such as content loss and component misalignment caused by exporting while the page structure is still undergoing changes. 2. By constructing a vertical coordinate system based on the printed paper size and page margins, the upper and lower boundaries of the content area on each page are determined, and the upper and lower critical zones of the page are defined. The overlap ratio and distribution of key layout elements with the critical zones are statistically analyzed, and the records are divided into low, medium, and high sensitivity levels. This page boundary sensitivity level can explicitly identify whether key layout elements such as titles, headers, and signature areas are concentrated near the page boundaries, thereby predicting the risk of cross-page splitting and element drift under different browser environments and font rendering conditions. 3. By mapping dynamic rendering convergence level and page boundary sensitivity level to three integer levels, and using the larger of the two as the primary risk level and the absolute value of the difference as the imbalance level, the proportion of high primary risk, the proportion of combined high risk and page boundary sensitivity, and the proportion of extreme imbalance are statistically analyzed at the task slice level to generate high-risk or low-risk slice risk level labels. Compared to the existing batch processing mode that treats all records equally, this label can summarize and identify high-risk scenarios with slow rendering, layout sensitivity, and high imbalance at the task slice level, providing a refined risk stratification basis for browser instance scheduling and export compression strategies.

[0018] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 This is a flowchart illustrating a method for batch generating consistent output of document images based on a browser instance pool, as an exemplary embodiment of the present invention. Detailed Implementation

[0020] The embodiments of the present invention will be described below with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention and not for limiting the scope of protection of the present invention.

[0021] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0022] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the invention. However, it will be apparent to those skilled in the art that embodiments of the invention may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the invention.

[0023] Example 1: A method for batch generating consistent output of document images based on browser instance pools, such as Figure 1 As shown, it includes: The received batch document image generation requests are divided into multiple task slices, and at least one browser instance is assigned to each task slice to load the template page. Once loaded, inject the ready probe, register the structure change listener and network request listener; For each record in the task slice, business data is injected into the template page. Before the ready probe determines the structure is stable, the time interval from data injection to meeting the structural stability criterion and the structural change behavior are determined based on the number of structural change events, time distribution and correlation with network requests, and a dynamic rendering convergence level is generated. After determining that the page structure is stable, determine the effective content area and the top and bottom boundaries of each page, obtain the positions of key layout elements, define the top and bottom critical zones of the page, and statistically analyze the proportion and distribution of key layout elements located in the critical zones to generate page boundary sensitivity levels. At the end of the task slice, a slice risk level label is generated based on the dynamic rendering convergence level and page boundary sensitivity level. Based on the slice risk level label, browser instance scheduling and document image export and compression strategies are controlled to ensure consistent output of document images across environments.

[0024] The present invention is further configured such that the batch document image generation request includes a template identifier, an output type, and a parameter set, and the received batch document image generation request is divided into multiple task slices, including: The records in the parameter set are grouped according to the template identifier and output type, so that the template identifier and output type of the records in the same group are consistent. Within each group, records are divided into multiple task slices based on the number of records and the estimated number of pages, and the number of records in each task slice does not exceed a preset limit; Specifically, upon receiving a batch document image generation request, the template identifier, output type, and corresponding parameter set are parsed from the request. The parameter set includes multiple records of documents to be generated, each carrying business fields used to populate the template page. To avoid frequent switching of templates and output configurations within the same task, the records in the parameter set are first grouped according to the template identifier and output type, ensuring that each group contains only records using the same template and output type. This guarantees that each group can reuse the same page structure and printing settings within the browser instance, reducing the additional overhead and layout differences caused by template switching. Based on the above grouping, for each group, the records within that group are further divided into multiple task slices, taking into account the number of records and the estimated number of pages based on factors such as record data volume and field length. During slice division, the number of records within each task slice is controlled to not exceed a preset limit, ensuring that the rendering and export load of a single task slice in the browser instance remains within a controllable range. This prevents an excessively large slice from causing excessive instance memory consumption or long response times. By first categorizing by template and output type, and then slicing by record quantity and estimated page count, each task slice maintains consistency in template configuration and remains controlled in scale. After the task slices are divided, at least one browser instance is allocated to each task slice based on the current idle and load status of the browser instance pool. Specifically, the scheduling module prioritizes selecting the target instance from available browser instances. If no suitable instance is available, a new instance is created as needed to ensure that the task slice can render the page in an isolated execution environment. After obtaining the target instance, the template page address pointed to by the corresponding template identifier is opened or reused within that browser instance to complete the loading of the template page and the initialization of basic resources. This allows multiple records within the same task slice to continuously inject business data and export document images based on the same template page, avoiding the additional overhead caused by frequent template switching and reducing page state interference between different tasks.

[0025] The present invention is further configured such that the structural change monitoring is used to monitor at least the addition of nodes, deletion of nodes, migration of node positions in the hierarchical structure, and overall rearrangement of list, table, and title areas; wherein, structural change events occurring in areas marked as layout key areas are counted separately; After the template page loads, a ready probe script is first injected into the browser instance to report the structural stability and key rendering completion signals on the front-end page. Simultaneously, structural change listeners and network request listeners are registered in the page's document object model. The structural change listener, based on capturing changes in the node tree, monitors at least node additions, deletions, node relocation within the hierarchical structure, and the overall rearrangement of block-like content such as list areas, table areas, and heading areas. During the initialization phase, key layout areas such as headers, table headings, and signature areas are pre-marked. When such structural changes occur within these key layout areas, they are counted separately to reflect their substantial impact on layout stability. The network request listener tracks when asynchronous requests related to template rendering are initiated and completed. Together with the signals reported by the ready probe, these elements form a fine-grained observation basis for the process from business data injection to page structural stability.

[0026] The present invention is further configured such that the structural stability criterion includes: no structural change event is detected within the continuous stable detection time window, and all key network requests related to template page rendering have been completed, and the ready probe returns a rendering completion signal; The dynamic rendering convergence level is generated as follows: when the time interval is less than the first threshold and the number of structural change events is less than the first threshold, it is marked as fast convergence; when the time interval is greater than or equal to the second threshold or the number of structural change events is greater than or equal to the second threshold, it is marked as slow convergence; otherwise, it is marked as moderate convergence. Specifically, for each record within a task slice, the corresponding business data is injected sequentially into the loaded template page. Monitoring begins from the injection moment based on the aforementioned structural change monitoring and network request monitoring. During the monitoring process, a sliding stability detection time window is used to determine whether the structure has entered a stable state: when no structural change events are detected within a continuous stability detection time window, and all key network requests related to template page rendering have been completed, and the ready probe reports a rendering completion signal, this moment is considered the structural stability moment. The time interval from business data injection to structural stability and the cumulative number of structural change events during this period are calculated. The rendering convergence level is determined based on the time interval and the number of events: if the time interval is less than the first threshold and the number of events is less than the first threshold, the current record is marked as fast convergence; if the time interval is greater than or equal to the second threshold, or the number of events is greater than or equal to the second threshold, it is marked as slow convergence; records that do not meet either of these conditions are marked as moderate convergence. This forms a dynamic rendering convergence level that reflects the speed of structural convergence of the page under actual data and network conditions. The first threshold, second threshold, first threshold, and second threshold are preferably determined statistically based on historical rendering behavior. During the deployment and trial operation phases, [the following criteria are selected]. A representative set of templates and business data is used to record a large number of records from the time intervals from business data injection to structural stability, along with the corresponding sequence of structural change event occurrences. The time intervals are arranged in ascending order, and the upper boundary covering the majority of normal records is selected as the first threshold. The intervals that are clearly in the long tail and significantly amplify rendering time are selected as the second threshold, allowing for the separate classification of obviously slow records. The threshold for the number of structural change events is set in a similar manner. Based on the statistical distribution of event occurrences, two dividing points that can distinguish between few adjustments, medium-frequency adjustments, and frequent rearrangements are selected as the first and second thresholds. Through this adaptive threshold selection based on historical data distribution, the three levels of fast convergence, medium convergence, and slow convergence all have stable discriminative power and engineering operability under different templates and load conditions.

[0027] The present invention is further configured such that determining the effective content area and the upper and lower boundaries of each page includes: mapping the logical page to a vertical coordinate system according to the printing paper size and page margin configuration, and determining the upper and lower boundaries of the content area of ​​each page in the vertical coordinate system; The definition of the page top and bottom critical zones includes: setting a critical zone area at a height that is a fixed proportion of the page height from the top and bottom boundaries of the content area of ​​each page. The statistics on the proportion of layout key elements located in the critical zone include: counting the number of elements whose bounding rectangles overlap with the critical zone and the proportion of the total number of layout key elements; and identifying the clustered distribution of multiple adjacent layout key elements on the same page that are simultaneously located in the critical zone. Specifically, after the template page rendering is completed and the structure stabilizes, the logical page is mapped to a coordinate system with the vertical direction as the main axis, based on the printing paper size and page margin configuration. This obtains the upper and lower boundaries of the content area on each page in the vertical coordinate system, used to characterize the spatial distribution of the content on the paper after pagination. Within each page's content area, upper and lower critical zones are set from top to bottom and from bottom to top, respectively, according to a fixed proportion of the page height. For example, a certain percentage of the page height is selected as the critical zone height to form sensitive areas near the upper and lower boundaries of the page. The bounding rectangles of the marked layout key elements are extracted from the page, and overlap detection is performed with the corresponding upper and lower critical zone areas. The number of layout key elements whose bounding rectangles overlap with any critical zone is counted, and the proportion of this number to the total number of layout key elements is calculated. Based on the adjacency relationship of layout key elements in the vertical and horizontal directions, the distribution of multiple adjacent layout key elements on the same page simultaneously falling into the upper or lower critical zone is identified. Through the above steps, the concentration and clustering characteristics of key layout elements near the page boundaries are transformed into quantifiable proportion and distribution information.

[0028] The present invention is further configured such that generating page boundary sensitivity levels includes: when the proportion of layout key elements located in the critical zone is less than a first proportion threshold and there is no clustered distribution, it is marked as a low sensitivity level; when the proportion of layout key elements located in the critical zone is greater than or equal to the first proportion threshold and less than a second proportion threshold and there is no clustered distribution, it is marked as a medium sensitivity level; when the proportion of layout key elements located in the critical zone is greater than or equal to the second proportion threshold or there is a clustered distribution, it is marked as a high sensitivity level. Specifically, after obtaining the proportion of key layout elements located at the upper and lower critical zones of each page and the markers indicating whether there are clusters of elements, a first proportion threshold and a second proportion threshold are configured in advance based on the statistical results of the element distribution near the page boundaries in historical exported samples or layout design specifications, and the first proportion threshold is guaranteed to be less than the second proportion threshold. During runtime, for each record's page, the proportion of layout key elements falling into the critical zone is first calculated, and it is determined whether there is a cluster distribution of multiple adjacent layout key elements simultaneously located in the upper or lower critical zones: when the proportion is lower than the first proportion threshold and no cluster distribution is detected, the key elements near the page boundary are considered sparsely distributed and insensitive to pagination algorithm and rendering differences, and the record is marked as low sensitivity level; when the proportion is between the first and second proportion thresholds and no cluster distribution still occurs, a certain number of key elements are considered to exist near the page boundary, but have not yet formed a high-density cluster, and the record is marked as medium sensitivity level; when the proportion is greater than or equal to the second proportion threshold, or once a cluster distribution is detected, the key elements near the page boundary are considered to be highly concentrated or clustered, easily affected by font rendering, line height changes, and small offsets of pagination boundaries, and the record is marked as high sensitivity level, thus explicitly quantifying page boundary risk into three levels of sensitivity using a unified rule.

[0029] The present invention is further configured to generate slice risk level labels based on dynamic rendering convergence level and page boundary sensitivity level, including: The dynamic rendering convergence level and page boundary sensitivity level are mapped to three integer levels respectively, and the largest value in each record is taken as the principal risk level, and the absolute value of the difference is taken as the imbalance level. At the end of the task slice, the proportion of records with the primary risk level equal to the highest level to the total number of records in the task slice is counted as the high primary risk proportion; the proportion of records with the primary risk level equal to the highest level and the imbalance level less than or equal to the first imbalance threshold is counted as the double high combined proportion; the proportion of records with the primary risk level equal to the highest level and the imbalance level greater than or equal to the second imbalance threshold is counted as the extreme imbalance proportion. When the proportion of high-risk main tasks exceeds the first risk threshold, and at least one of the proportion of high-risk combined tasks or extreme imbalance exceeds the second risk threshold, the task slice is marked as a high-risk slice; otherwise, it is marked as a low-risk slice. Specifically, after obtaining the dynamic rendering convergence level and page boundary sensitivity level corresponding to each record, the three levels are first uniformly mapped to integers 0, 1, and 2. The larger of the two values ​​is taken as the principal risk level of the record, and the absolute value of the difference between the two is taken as the imbalance level. This is used to simultaneously characterize the record's features in terms of both overall risk height and whether the two-dimensional risk is imbalanced. For the same task slice, after processing all records, the proportion of records with a principal risk level equal to the highest level is calculated to obtain the high principal risk proportion. Based on this, the proportion of records with a principal risk level of the highest level and an imbalance level in a relatively small range (less than or equal to the first imbalance threshold) is further calculated as the double-high combined proportion, used to reflect the concentration of both rendering convergence and page boundary sensitivity being at a high or near-high level. At the same time, the proportion of records with a principal risk level of the highest level and an imbalance level in a relatively large range (greater than or equal to the second imbalance threshold) is calculated as the extreme imbalance proportion, used to reflect the extreme sample proportion where one side has extremely high risk and the other side has low risk. The first risk threshold, the second risk threshold, and the imbalance threshold are pre-configured based on the business's tolerance for layout stability. During operation, when the proportion of high primary risk exceeds the first risk threshold, and at least one of the proportion of dual high combined risk or extreme imbalance exceeds the second risk threshold, the task slice is marked as a high-risk slice; otherwise, it is marked as a low-risk slice. This forms a risk level label at the task slice level that can be used for scheduling and output control.

[0030] The present invention is further configured to control browser instance scheduling based on slice risk level tags, including: When a slice is marked as high-risk, a target browser instance that has completed a restart within a preset time window and has not recorded any abnormal disconnection events is selected from the browser instance pool to host the high-risk slice. Parallel scheduling of multiple high-risk slices on the same browser instance is prohibited. When a slice is marked as low-risk, it is allowed to be split across multiple browser instances for parallel scheduling, or to share execution with other low-risk slices on the same browser instance. Specifically, after generating a risk level label for each task slice, this label is used as one of the constraints for browser instance scheduling: when a task slice is marked as a high-risk slice, the scheduling module selects target browser instances from the browser instance pool that have completed a restart within a preset time window and have not recorded abnormal disconnections or serious error logs during runtime. Only the high-risk slice is allowed to be bound to a single instance that meets the above health conditions for execution, and multiple high-risk slices are prohibited from being scheduled in parallel on the same instance at the same time, so as to avoid the superposition and amplification of failure risks between tasks with high rendering complexity and high layout sensitivity. Conversely, when a task slice is marked as a low-risk slice, the scheduling module selects multiple idle or moderately loaded instances from the instance pool, splits the same low-risk slice and distributes it to multiple instances for parallel processing, or arranges multiple low-risk slices to be executed sequentially or in parallel on the same instance, so as to improve instance utilization and batch export concurrency capabilities while ensuring overall stability, and realize a differentiated scheduling strategy of prioritizing high-risk steady-state bearing and low-risk resource utilization.

[0031] The present invention is further configured such that the document image export and compression strategy based on slice risk level labels includes: When a slice is marked as high-risk, page size priority and background content rendering configuration are enabled when exporting portable document format files, the preset page rules in the template page are applied, and a lossless compression strategy is adopted during the compression stage. When a slice is marked as low-risk, some page settings and background drawing configurations can be simplified while meeting the layout requirements, and a high compression ratio strategy is adopted during the compression stage. Specifically, after determining the risk level of a task slice, the risk level label is used as the basis for layout control during the export and compression stages. When a task slice is marked as high-risk, the export module forces the page size priority configuration and background content drawing options to be enabled when generating portable document format files. This ensures that the printing paper size, margins, and styles of background color blocks and watermarks strictly adhere to the preset page rules in the template page, while automatically adjusting key parameters such as page margins and scaling ratios is prohibited. In the subsequent compression stage, the document image generated for this high-risk slice only adopts a lossless or near-lossless light compression strategy to avoid introducing visible distortion near page boundaries or in key information areas. Conversely, when a task slice is marked as low-risk, provided that its page boundary sensitivity is low and key layout elements are far from the top and bottom page boundaries, it is allowed to disable or simplify some background drawing, detail effects, or redundant page settings. In the compression stage, a high compression ratio strategy is used to compress parameters such as image quality and resolution more forcefully, so as to significantly reduce the size of the final document image without affecting the readability of the core content, thereby improving storage and transmission efficiency.

[0032] Example 2: This exemplary system for batch generation of consistent output from document images based on a browser instance pool is used to implement the aforementioned method for batch generation of consistent output from document images based on a browser instance pool, including: Instance allocation module: Divides the received batch document image generation requests into multiple task slices, allocates at least one browser instance to each task slice, and loads the template page; Listener registration module: After loading, inject ready probes and register structure change listeners and network request listeners; First-level module: Inject business data into the template page for each record in the task slice. Before the ready probe determines the structure is stable, determine the time interval from data injection to meeting the structure stability criterion and the structure change behavior based on the number of structural change events, time distribution and correlation with network requests, and generate dynamic rendering convergence level. The second-level module: After determining that the page structure is stable, it determines the effective content area and the top and bottom boundaries of each page, obtains the positions of key layout elements, defines the top and bottom critical zones of the page, counts the proportion and distribution of key layout elements located in the critical zones, and generates the page boundary sensitivity level. Consistent Output Module: At the end of the task slice, a slice risk level label is generated based on the dynamic rendering convergence level and page boundary sensitivity level. Based on the slice risk level label, the browser instance scheduling and document image export and compression strategies are controlled to achieve consistent output of document images across environments.

[0033] It should be noted that the consistent output system for batch generation of document images based on browser instance pools provided in the above embodiments and the consistent output method for batch generation of document images based on browser instance pools provided in the above embodiments belong to the same concept. The specific methods of execution of each module and unit have been described in detail in the method embodiments and will not be repeated here. In practical applications, the consistent output system for batch generation of document images based on browser instance pools provided in the above embodiments can be assigned to different functional modules as needed, that is, the internal structure of the system can be divided into different functional modules to complete all or part of the functions described above. This is not a limitation here.

[0034] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for batch generating consistent output of document images based on browser instance pools, characterized in that, include: The received batch document image generation requests are divided into multiple task slices, and at least one browser instance is assigned to each task slice to load the template page. Once loaded, inject the ready probe, register the structure change listener and network request listener; For each record in the task slice, business data is injected into the template page. Before the ready probe determines the structure is stable, the time interval from data injection to meeting the structural stability criterion and the structural change behavior are determined based on the number of structural change events, time distribution and correlation with network requests, and a dynamic rendering convergence level is generated. After determining that the page structure is stable, determine the effective content area and the top and bottom boundaries of each page, obtain the positions of key layout elements, define the top and bottom critical zones of the page, and statistically analyze the proportion and distribution of key layout elements located in the critical zones to generate page boundary sensitivity levels. At the end of the task slice, a slice risk level label is generated based on the dynamic rendering convergence level and page boundary sensitivity level. Based on the slice risk level label, browser instance scheduling and document image export and compression strategies are controlled to ensure consistent output of document images across environments.

2. The method for batch generation of consistent output of document images based on browser instance pools according to claim 1, characterized in that, The batch document image generation request includes a template identifier, output type, and parameter set. The received batch document image generation request is divided into multiple task slices, including: The records in the parameter set are grouped according to the template identifier and output type, so that the template identifier and output type of the records in the same group are consistent. Within each group, records are divided into multiple task slices based on the number of records and the estimated number of pages, and the number of records in each task slice does not exceed a preset limit.

3. The method for batch generation of consistent output of document images based on browser instance pools according to claim 1, characterized in that, Structural change monitoring is used to monitor at least the addition and deletion of nodes, the relocation of nodes in the hierarchical structure, and the overall rearrangement of list, table, and title areas; among them, structural change events that occur in areas marked as layout key areas are counted separately.

4. The method for batch generation of consistent output of document images based on browser instance pools according to claim 1, characterized in that, The structural stability criteria include: no structural change events are detected within the continuous stability detection time window, all key network requests related to template page rendering have been completed, and the ready probe returns a rendering completion signal; The dynamic rendering convergence level is generated as follows: when the time interval is less than the first threshold and the number of structural change events is less than the first threshold, it is marked as fast convergence; when the time interval is greater than or equal to the second threshold or the number of structural change events is greater than or equal to the second threshold, it is marked as slow convergence; otherwise, it is marked as medium convergence.

5. The method for batch generation of consistent output of document images based on browser instance pools according to claim 1, characterized in that, Determining the effective content area and top and bottom boundaries of each page includes: mapping the logical page to a vertical coordinate system based on the printing paper size and page margin configuration, and determining the top and bottom boundaries of the content area of ​​each page in the vertical coordinate system; The definition of the page top and bottom critical zones includes: setting a critical zone area at a height that is a fixed proportion of the page height from the top and bottom boundaries of the content area of ​​each page. The statistical analysis of the proportion of layout key elements located in the critical zone includes: counting the number of elements whose bounding rectangles overlap with the critical zone and the proportion of such elements to the total number of layout key elements; and identifying the clustered distribution of multiple adjacent layout key elements on the same page that are simultaneously located in the critical zone.

6. The method for batch generation of consistent output of document images based on browser instance pools according to claim 5, characterized in that, The page boundary sensitivity levels are as follows: when the proportion of layout key elements in the critical zone is less than the first proportion threshold and there is no clustered distribution, it is marked as low sensitivity; when the proportion of layout key elements in the critical zone is greater than or equal to the first proportion threshold and less than the second proportion threshold and there is no clustered distribution, it is marked as medium sensitivity; when the proportion of layout key elements in the critical zone is greater than or equal to the second proportion threshold or there is a clustered distribution, it is marked as high sensitivity.

7. The method for batch generation of consistent output of document images based on browser instance pools according to claim 6, characterized in that, Slice risk level labels are generated based on the dynamic rendering convergence level and page boundary sensitivity level, including: The dynamic rendering convergence level and page boundary sensitivity level are mapped to three integer levels respectively, and the largest value in each record is taken as the principal risk level, and the absolute value of the difference is taken as the imbalance level. At the end of the task slice, the proportion of records with the primary risk level equal to the highest level to the total number of records in the task slice is counted as the high primary risk proportion; the proportion of records with the primary risk level equal to the highest level and the imbalance level less than or equal to the first imbalance threshold is counted as the double high combined proportion; the proportion of records with the primary risk level equal to the highest level and the imbalance level greater than or equal to the second imbalance threshold is counted as the extreme imbalance proportion. When the proportion of high-risk main tasks exceeds the first risk threshold, and at least one of the proportion of high combined tasks or extreme imbalance exceeds the second risk threshold, the task slice is marked as a high-risk slice; otherwise, it is marked as a low-risk slice.

8. The method for batch generation of consistent output of document images based on browser instance pools according to claim 1, characterized in that, Browser instance scheduling is controlled based on slice risk level tags, including: When a slice is marked as high-risk, a target browser instance that has completed a restart within a preset time window and has not recorded any abnormal disconnection events is selected from the browser instance pool to host the high-risk slice. Parallel scheduling of multiple high-risk slices on the same browser instance is prohibited. When a slice is marked as low-risk, it allows the low-risk slice to be split across multiple browser instances for parallel scheduling, or to share execution with other low-risk slices on the same browser instance.

9. The method for batch generation of consistent output of document images based on browser instance pools according to claim 1, characterized in that, The strategies for controlling document image export and compression based on slice risk level labels include: When a slice is marked as high-risk, page size priority and background content rendering configuration are enabled when exporting portable document format files, the preset page rules in the template page are applied, and a lossless compression strategy is adopted during the compression stage. When a slice is marked as low-risk, some page settings and background drawing configurations can be simplified, provided that the layout requirements are met, and a high compression ratio strategy is adopted during the compression stage.

10. A system for batch generation of consistent output of document images based on browser instance pools, used to implement the method for batch generation of consistent output of document images based on browser instance pools as described in any one of claims 1-9, characterized in that, include: Instance allocation module: Divides the received batch document image generation requests into multiple task slices, allocates at least one browser instance to each task slice, and loads the template page; Listener registration module: After loading, inject ready probes and register structure change listeners and network request listeners; First-level module: Inject business data into the template page for each record in the task slice. Before the ready probe determines the structure is stable, determine the time interval from data injection to meeting the structure stability criterion and the structure change behavior based on the number of structural change events, time distribution and correlation with network requests, and generate dynamic rendering convergence level. The second-level module: After determining that the page structure is stable, it determines the effective content area and the top and bottom boundaries of each page, obtains the positions of key layout elements, defines the top and bottom critical zones of the page, counts the proportion and distribution of key layout elements located in the critical zones, and generates the page boundary sensitivity level. Consistent Output Module: At the end of the task slice, a slice risk level label is generated based on the dynamic rendering convergence level and page boundary sensitivity level. Based on the slice risk level label, the browser instance scheduling and document image export and compression strategies are controlled to achieve consistent output of document images across environments.