A web-based PDF file editing method, apparatus, and related media

By employing layered parsing and unified display matrix transformation, combined with mapping processing in the interactive editing layer, the precision problem of PDF file editing in the browser environment is solved, achieving an efficient PDF file editing method.

CN122113842BActive Publication Date: 2026-06-30WANGXU TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
WANGXU TECH CO LTD
Filing Date
2026-04-28
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

Existing technologies make it difficult to achieve integrated collaborative processing of PDF files in a browser environment, resulting in low editing accuracy. The lack of a unified object model and coordinate transformation mechanism between different stages leads to display offset and distortion.

Method used

The document data of the PDF file is obtained through layered parsing, a page object model is constructed, a unified display matrix is ​​calculated for rendering, an interactive editing layer is overlaid for operation mapping, annotation object display is adapted, and incremental operation data is output.

Benefits of technology

It improves the precision of PDF file editing on the web, ensures consistency in data structure and coordinate system across all stages, and enhances the accuracy and efficiency of editing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122113842B_ABST
    Figure CN122113842B_ABST
Patent Text Reader

Abstract

This invention discloses a method, apparatus, and related media for editing PDF files on a web-based platform. The method includes hierarchical parsing of document data to obtain pagination resource data; object-oriented parsing of the pagination resource data to obtain a page object model; calculation of a unified display matrix from page space to device space and rendering it onto a canvas; overlaying an interactive editing layer to respond to editing operations and synchronously mapping it to the page object model; adapting display transformation parameters for annotation objects; and extracting operations of objects marked as changed and aggregating incremental operation data page by page. This invention improves the accuracy of editing PDF files on a web-based platform by using the page object model as the unified data core and integrating multi-threaded collaborative processing across hierarchical parsing, object-oriented modeling, unified display matrix transformation rendering, interactive editing synchronous mapping, annotation display transformation parameter adaptation, and incremental operation data output. This ensures consistency in data structure and coordinate system across all stages.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a method, apparatus and related media for editing PDF files based on a web interface. Background Technology

[0002] With the continued growth in demand for online office work and cross-platform collaboration, users increasingly need to view, edit, save, and export PDF documents directly within their browsers. However, PDF is essentially a page description format designed for printing and accurate rendering. It contains various complex objects such as font resources, graphic states, coordinate matrices, image resources, and annotation appearance flows, making accurate rendering and reliable editing of PDF files in a browser environment a significant challenge.

[0003] Existing web-based PDF editing solutions typically handle document parsing, page rendering, interactive editing, annotation display, and saving of editing results separately. However, these stages lack a unified object model and coordinate transformation mechanism to support them. Specifically, the data generated during document parsing is difficult to directly map into editable object instances; there is a lack of a unified transformation relationship between the coordinate space used for page rendering and the coordinate space of the interactive editing layer; the appearance flow carried by annotation objects is prone to display offset or distortion after scaling or rotation; and saving editing results often requires transmitting the entire page or file, resulting in low transmission efficiency.

[0004] Because the aforementioned steps are fragmented in terms of data structure and coordinate system, existing solutions struggle to achieve integrated collaborative processing in a browser environment, thus reducing the accuracy of editing PDF files on the web. Summary of the Invention

[0005] This invention provides a web-based PDF file editing method, apparatus, and related media, aiming to solve the technical problem that PDF files are difficult to process in an integrated and collaborative manner in a browser environment in the prior art.

[0006] In a first aspect, embodiments of the present invention provide a web-based PDF file editing method, comprising:

[0007] Obtain the document data of the PDF file to be edited, and perform layered parsing on the document data to obtain pagination resource data;

[0008] The paginated resource data is parsed in an object-oriented manner to restore the graphic elements in each page into object instances, thereby obtaining the page object model;

[0009] The unified display matrix from page space to device space is calculated based on the page object model, and the objects in the page object model are rendered onto the canvas after being transformed by the unified display matrix to obtain the page rendering screen.

[0010] An interactive editing layer is overlaid on the rendered page. The interactive editing layer responds to editing operations and synchronously maps the operation results to the page object model to obtain the edited page object model.

[0011] The annotation objects in the edited page object model are adapted to display transformation parameters to obtain the adapted page object model.

[0012] The adapted page object model is traversed to extract the object operations marked as changed, and incremental operation data is output in page-aggregated form.

[0013] Secondly, embodiments of the present invention provide a web-based PDF file editing device, comprising:

[0014] The data acquisition unit is used to acquire the document data of the PDF file to be edited, and to perform layered parsing of the document data to obtain pagination resource data;

[0015] The data parsing unit is used to perform object-oriented parsing on the paginated resource data to restore the graphic elements in each page into object instances and obtain the page object model;

[0016] The page rendering unit is used to calculate the unified display matrix from page space to device space based on the page object model, and render the objects in the page object model to the canvas after transformation by the unified display matrix to obtain the page rendering screen;

[0017] An interactive editing unit is used to overlay an interactive editing layer on the rendered page, respond to editing operations through the interactive editing layer and synchronously map the operation results to the page object model to obtain the edited page object model;

[0018] The parameter adaptation unit is used to adapt the display transformation parameters of the annotation objects in the edited page object model to obtain the adapted page object model.

[0019] The data output unit is used to traverse the adapted page object model to extract the object operations marked as changed, and output incremental operation data in page aggregation form.

[0020] Thirdly, embodiments of the present invention provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the web-based PDF file editing method of the first aspect.

[0021] Fourthly, embodiments of the present invention provide a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, it implements the web-based PDF file editing method of the first aspect.

[0022] This invention provides a web-based PDF file editing method, including: acquiring document data of the PDF file to be edited; performing layered parsing on the document data to obtain pagination resource data; performing object-oriented parsing on the pagination resource data to restore the primitives in each page into object instances to obtain a page object model; calculating a unified display matrix from page space to device space based on the page object model, and rendering the objects in the page object model onto a canvas after transformation by the unified display matrix to obtain a page rendering screen; overlaying an interactive editing layer on the page rendering screen, responding to editing operations through the interactive editing layer and synchronously mapping the operation results to the page object model to obtain an edited page object model; adapting the display transformation parameters of the annotation objects in the edited page object model to obtain an adapted page object model; traversing the adapted page object model to extract object operations marked as changed, and outputting incremental operation data in a page aggregation format. This invention improves the accuracy of editing PDF files on the Web by using the page object model as a unified data core and integrating multi-threaded collaborative processing that includes layered parsing, object-oriented modeling, unified display matrix transformation rendering, interactive editing synchronous mapping, annotation display transformation parameter adaptation, and incremental operation data output. This ensures that each step maintains consistency in data structure and coordinate system, thereby improving the accuracy of editing PDF files on the Web.

[0023] The present invention also provides a web-based PDF file editing device, computer equipment, and storage medium, which have the same beneficial effects as described above. Attached Figure Description

[0024] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0025] Figure 1A flowchart illustrating a web-based PDF file editing method provided in an embodiment of the present invention;

[0026] Figure 2 This is a schematic block diagram of a web-based PDF file editing device provided in an embodiment of the present invention.

[0027] Explanation of reference numerals in the attached figures:

[0028] 200. Web-based PDF file editing device; 201. Data acquisition unit; 202. Data parsing unit; 203. Page rendering unit; 204. Interactive editing unit; 205. Parameter adaptation unit; 206. Data output unit. Detailed Implementation

[0029] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0030] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0031] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0032] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0033] Please see below. Figure 1 , Figure 1 The flowchart of a web-based PDF file editing method provided in this embodiment of the invention specifically includes steps S101 to S106.

[0034] S101. Obtain the document data of the PDF file to be edited, and perform layered parsing on the document data to obtain pagination resource data;

[0035] S102. The pagination resource data is parsed in an object-oriented manner to restore the graphic elements in each page into object instances, thereby obtaining the page object model;

[0036] S103. Calculate the unified display matrix from page space to device space based on the page object model, and render the objects in the page object model onto the canvas after transformation by the unified display matrix to obtain the page rendering screen.

[0037] S104. An interactive editing layer is superimposed on the rendered page. The interactive editing layer responds to editing operations and synchronously maps the operation results to the page object model to obtain the edited page object model.

[0038] S105. Adapt the display transformation parameters of the annotation objects in the edited page object model to obtain the adapted page object model.

[0039] S106. Traverse the adapted page object model to extract the object operations marked as changed, and output the incremental operation data in page aggregation form.

[0040] In step S101, the document data of the PDF file to be edited is obtained, and the document data is parsed hierarchically. During the hierarchical parsing process, the system splits the document data into two levels: document-level data and page-level data. The document-level data describes the overall document information, while the page-level data describes the content of each individual page. Through the above hierarchical parsing, the system obtains the document entry information and the resource data corresponding to each page, thereby obtaining paginated resource data organized by page, providing a data foundation for subsequent page-by-page processing.

[0041] In step S102, the pagination resource data is parsed in an object-oriented manner, and the graphic elements in each page are restored one by one into object instances that can be processed by the browser. Each page is parsed into an array of objects including text objects, image objects, path objects, and form objects. Each object instance not only retains its display attributes, but also retains data such as position parameters, matrix parameters, status information, and editing tags required for editing, thereby constructing a page object model.

[0042] In one embodiment, step S102 includes:

[0043] Read the single-page binary data from the pagination resource data, and create a page object container based on the single-page binary data;

[0044] The common state data in the page object container is parsed, and the general state, cropping state, graphic state, color state and text state are extracted respectively and merged to obtain the page common state table;

[0045] Based on the preset object type, the page content flow in the page object container is parsed to generate text objects, image objects, path objects and form objects respectively, and then merged to obtain a page object array;

[0046] For each object in the page object array, establish position parameters, matrix parameters, state reference relationships, and editing tags to obtain an editable page object array;

[0047] Parse the page annotation data in the page object container, and generate a page annotation list based on the position parameters of each object in the editable page object array;

[0048] The editable page object array, the page common state table, and the page annotation list are integrated to obtain the page object model.

[0049] In this embodiment, single-page PDF data is not directly converted into a full-page bitmap. Instead, it is first parsed into a page object model, which is then used by subsequent modules such as rendering, hit detection, editing, and saving. To achieve this, the single-page binary data in the paginated resource data is read first. The front-end obtains the binary data stream corresponding to the current page page by page and sequentially reads the page content using a binary reader. After reading the single-page binary data, the system creates a page object container based on the single-page binary data. The page object container is a unified data structure used to carry all the main content objects, state tables, font information, and resource reference information of the current page, denoted as PDPageObjects in this embodiment. This page object container serves as the root node for the current page data organization, providing a unified mounting carrier for subsequent common state parsing, page content stream parsing, and annotation data parsing.

[0050] After the page object container is created, the common state data within it is parsed. This common state data refers to the set of multiple states associated with the current page before the object is formally parsed. The system extracts the general state, clipping state, graphic state, color state, and text state, and merges these states to obtain a page common state table. This common state table does not directly and repeatedly write each state data into each object; instead, it is centrally stored as a state table, which is subsequently referenced by each object using a state number. This centralized management and numbered referencing method effectively reduces data redundancy between objects, laying the foundation for building a lightweight page object model.

[0051] Furthermore, the system parses the page content stream in the page object container based on preset object types. The page content stream refers to the collection of object records arranged in sequence on the current page. The system reads each object record in the page content stream one by one. For each object record, it first reads its object type identifier, and then instantiates an object of the corresponding type according to the type identifier. Text objects (TextObj), image objects (ImgObj), path objects (PathObj), and form objects (FormObj) are generated according to the preset object types. Among them, the image object also includes an embedded image object (InlineImgObj), which is used to process image data directly embedded in the page content stream. It should be noted that if the current object is a form object (FormObj), it can continue to contain a group of page objects. Therefore, the system uses a recursive approach to process the sub-objects within the form object, so that the object model of this invention not only supports a flat object array structure, but also a nested object hierarchy structure, which can express more complex PDF page content. After the above types of objects are parsed, they are added to the object array objectArr of the current page in sequence, thereby merging to obtain the page object array. In other words, the main content of the page is organized as an iterable array of objects, where each element corresponds to a renderable, editable, and saveable PDF content object.

[0052] After obtaining the page object array, the system establishes position parameters, matrix parameters, state reference relationships, and edit tags for each object in the array, resulting in an editable page object array. During parsing, each object reads its own geometric and content parameters. The position parameters include the object's position coordinates and bounding rectangle; the matrix parameters include the object's transformation matrix; and other content parameters related to the object type, such as text content and image identifiers. Simultaneously, the system binds a corresponding state reference relationship to the object, establishing an association between the object and the page's common state table, specifically including a general state number, graphic state number, color state number, and text state number. Through this process, each object forms a lightweight structure consisting of an object body and state references. The object body carries its own position parameters, matrix parameters, and content data, while the state reference relationships point to the corresponding state entries in the page's common state table, avoiding redundant storage of state data among objects. Furthermore, the system sets an edit tag for each object to identify the type of modification in subsequent editing operations, such as addition, deletion, or modification, thus enabling each object in the page object array to be editable, resulting in an editable page object array.

[0053] After the main content object is parsed, the page annotation data in the page object container is further parsed. It is determined whether the current page contains annotation data. If the current page contains annotation data, a separate page annotation list structure is created, denoted as m_annotList in this embodiment. The system parses each annotation object one by one and, based on the position parameters of each object in the editable page object array, determines the spatial position relationship of each annotation object on the page, generating the page annotation list. The page annotation list is independent of the main content object in the editable page object array. In subsequent rendering stages, the appearance of the annotation objects will be appended to the page display context for unified presentation.

[0054] Finally, the editable page object array, page common state table, and page comment list are integrated to obtain the page object model. The final page object model of the current page includes an array of main content objects, a set of state tables, and a list of page-level comments. These data together constitute the unified editing foundation model of the page, which is used by subsequent modules such as rendering output, hit detection, text input, object modification, and incremental saving.

[0055] In step S103, a unified display matrix from page space to device space is calculated based on parameters such as the current page size, rotation state, and scaling ratio in the page object model. Simultaneously, the system sets the logical and actual pixel sizes of the canvas according to the device pixel ratio to ensure the page remains clearly displayed on high-resolution screens. Then, after transforming each object in the page object model using the unified display matrix, they are uniformly appended to the rendering context and output to the canvas to obtain the rendered page image.

[0056] In one embodiment, step S103 includes:

[0057] The page size parameters of the current page in the page object model, as well as the scaling and rotation parameters of the preset viewer, are obtained to obtain the rendering parameter set;

[0058] Based on the device pixel ratio in the set of rendering parameters, the logical size and pixel size of the canvas are set respectively to obtain a canvas with the appropriate size.

[0059] Based on the page size parameter, the scaling parameter, and the rotation parameter in the rendering parameter set, the coordinate mapping relationship from the page space to the device space is calculated to obtain a unified display matrix;

[0060] Create a rendering context and write the unified display matrix into the rendering context to obtain the initial rendering context;

[0061] The main content object in the page object model is appended to the initial rendering context to obtain the complete rendering context;

[0062] Based on the scaling ratio in the set of rendering parameters and the device pixel ratio, the rendering output is performed on the complete rendering context, and the rendering result is drawn onto the canvas after the size is adapted to obtain the page rendering screen.

[0063] In this embodiment, the page size parameters of the current page in the page object model, as well as the scaling and rotation parameters of the preset viewer, are obtained to obtain a rendering parameter set. The page size parameters include the page width and height of the current page, the scaling parameters are the scaling ratio currently set by the preset viewer, and the rotation parameters include the original rotation angle of the page itself and the rotation factor of the viewer. If the viewer containing the current page has a rotation operation, the system adds the rotation factor of the viewer to the original rotation angle of the page itself to obtain the actual rendering angle of the current page. In addition, the rendering parameter set also includes the size information of the current canvas and the device pixel ratio (devicePixelRatio) of the browser. All of the above parameters together constitute the rendering parameter set, providing a complete parameter basis for subsequent canvas initialization, unified display matrix calculation, and rendering output.

[0064] After obtaining the rendering parameter set, the system sets the logical size and pixel size of the canvas based on the device pixel ratio in the rendering parameter set, resulting in a size-adapted canvas. The device pixel ratio (devicePixelRatio) refers to the ratio between the physical pixels of the browser's current device and the logical pixels in the CSS. Based on this device pixel ratio, the system sets the logical display size and actual pixel size of the Canvas. The logical display size determines the CSS display area occupied by the canvas in the page layout, while the actual pixel size is enlarged according to the device pixel ratio to determine the actual drawing resolution within the canvas. By setting the logical size and pixel size separately, the page maintains a clear display effect in high-resolution screen scenarios, avoiding the blurring problem caused by drawing directly according to the CSS size, thus obtaining a size-adapted canvas.

[0065] Furthermore, based on the page size parameter, scaling parameter, and rotation parameter in the rendering parameter set, the coordinate mapping relationship from the page space to the device space is calculated to obtain a unified display matrix. The page space refers to the original page coordinate system defined in the PDF document, and the device space refers to the device display coordinate system corresponding to the browser canvas. The page display matrix calculation logic is invoked, and a mapping matrix from the PDF page coordinate system to the device display coordinate system is generated based on the current page width, page height, canvas area, and the superimposed rendering angle. This unified display matrix is ​​used to uniformly handle various coordinate transformation operations such as page translation, page scaling, page rotation, and coordinate origin transformation, ensuring that all subsequent objects can complete the coordinate mapping from page space to device space through the same matrix during rendering. This guarantees that the display position and display ratio of various objects remain consistent under scaling, rotation, and translation transformations.

[0066] After obtaining the unified display matrix, a rendering context is created, and the unified display matrix is ​​written into the rendering context to obtain the initial rendering context. The rendering context refers to a unified rendering container used to carry all rendering information for this page output; in this embodiment, it is denoted as PDRenderContext. This rendering context not only carries the list of objects to be drawn but also the current unified display matrix, edit state information, and various parameters required for subsequent rendering. After creating the PDRenderContext, the system writes the previously calculated unified display matrix into this rendering context, making it the common coordinate transformation reference for drawing all subsequent objects, thereby obtaining the initial rendering context.

[0067] Furthermore, the system appends the main content objects from the page object model to the initial rendering context to obtain a complete rendering context. The system retrieves the main content object set PDPageObjects from the current page's page object model. This set includes various types of objects such as TextObj, ImgObj, PathObj, and FormObj, which were parsed in step S102. The system then appends these main content objects of each type sequentially to PDRenderContext according to the coordinate transformation rules determined by the unified display matrix. Through this process, although the various objects originate from different object types and have their own independent original coordinate parameters, they are ultimately all organized under the same device coordinate system, thus obtaining a complete rendering context.

[0068] Finally, based on the scaling ratio in the rendering parameter set and the device pixel ratio, the system performs rendering output on the complete rendering context and draws the rendering result onto the size-adapted canvas to obtain the page rendering screen. During the actual Canvas drawing, the viewer's scaling ratio and device pixel ratio are included in the rendering output process to ensure the page ratio is correct when the user zooms in, while also ensuring consistent output precision across different display devices. The system iterates through all types of objects in the complete rendering context, calling the corresponding rendering logic according to the object type, including text drawing, image drawing, and path drawing, and sequentially draws the final rendering result of each object onto the aforementioned size-adapted canvas. Thus, the system completes the full conversion of the current page from the PDF page object model to the browser display result, obtaining the page rendering screen.

[0069] In step S104, at the display level, a canvas can be used to render PDF primitives and text in high fidelity; at the editing level, an interactive editing layer can be overlaid on the rendered page to handle interactive behaviors such as text input, selection operations, drag operations, and hit detection. When a user performs an editing operation through the interactive editing layer, the system responds to the editing operation and synchronously maps the operation result back to the corresponding object instance in the page object model, thereby obtaining the edited page object model.

[0070] In one embodiment, step S104 includes:

[0071] Create an interaction controller and bind it to the canvas corresponding to the page rendering screen. Attach the text editing layer, border operation layer, and image operation layer to the canvas to obtain the interaction editing layer.

[0072] In the interactive editing layer, the text hit detection module and the image hit detection module are initialized respectively to obtain the hit processing module group;

[0073] In response to browser events on the interactive editing layer, the page event coordinates are calculated.

[0074] The page event coordinates are input into the hit processing module group. At the same time, the editing operation mode of text editing, image editing or adding object is determined according to the hit result, and an input control is generated at the position of the hit target object.

[0075] Listen for input events on the input control, and dynamically update the corresponding text boundaries, selection area, and display effect based on the input events to obtain the editing operation result;

[0076] The result of the editing operation is written back to the page object model to obtain the edited page object model.

[0077] In this embodiment, the main content of the page is drawn on the canvas, but user editing is not done directly on the canvas bitmap. Instead, an interactive editing layer is overlaid on top of the rendered page to implement functions such as object selection, text input, selection display, image manipulation, and writing back the editing results. Specifically, the system first creates an interaction controller and binds it to the canvas corresponding to the rendered page. After the page enters the editing state, the system creates an interaction controller CanvasTest and binds it to the Canvas of the current page. The interaction controller CanvasTest is responsible for uniformly managing all subsequent interactive components such as text selection tools, image selection tools, selection boxes, border canvases, and image operation bars. After the interaction controller is created, the system creates additional interactive overlay elements on top of the page display layer, attaching the text editing layer, border operation layer, and image operation layer to the canvas respectively, thus obtaining the interactive editing layer. The text editing layer is a divText container used to hold subsequent text input boxes and text selection areas; the border operation layer is a borderCanvas used to draw the visible border and boundary indicators of the currently selected object; and the image operation layer is an imgActionBar used to provide entry points for operations such as rotating and deleting image objects. All these interactive overlay elements are absolutely positioned and overlaid on the root node of the page view, thus maintaining synchronized display with the underlying PDF Canvas on the same page, collectively forming the interactive editing layer.

[0078] After the interactive editing layer is created, a text hit detection module and an image hit detection module are initialized within the interactive editing layer to obtain a hit processing module group. The text hit detection module is used to detect whether the user's interactive operation hits a text object on the current page, and the image hit detection module is used to detect whether the user's interactive operation hits an image object on the current page. The system calls the above two hit detection modules to initialize the page object model of the current page. During the initialization process, each hit detection module reads the object array, page matrix, and page index information of the current page to accurately convert the user's mouse events into corresponding object hit results on the page. After the above initialization, the text hit detection module and the image hit detection module together constitute the hit processing module group, providing object-level hit determination capabilities for subsequent interactive event processing.

[0079] Furthermore, the system responds to browser events on the interactive editing layer and calculates page event coordinates. When a user performs actions such as clicking, dragging, or selecting on the page, the browser generates corresponding mouse or touch events. The system obtains the pixel coordinates of the mouse on the Canvas and then converts these pixel coordinates to PDF page coordinates using coordinate conversion logic to obtain the page event coordinates. The page event coordinates refer to the event position information that, after coordinate transformation, is in the same coordinate system as the underlying PDF page object model. By converting browser event coordinates to page event coordinates, operations on the interactive editing layer can maintain a unified coordinate system with the underlying PDF object model, thereby avoiding editing offsets under conditions such as scaling and rotation.

[0080] After obtaining the page event coordinates, the coordinates are input into the hit processing module group. Simultaneously, based on the hit result, the system determines the editing operation mode (text editing, image editing, or adding an object) and generates an input control at the hit target object location. The system passes the page event coordinates to the text hit detection module and the image hit detection module respectively. Each module determines whether the coordinate position falls within the valid area of ​​an object on the current page and returns the corresponding hit result. The system determines the type of the current operation object based on the hit result, and then determines the corresponding editing operation mode: if the hit result indicates that the current operation hits a text object, the system enters text editing mode; if the hit result indicates that the current operation hits an image object, the system enters image editing mode and displays an image operation bar in the image operation layer, providing entry points for operations such as rotation and deletion; if the current operation does not hit any existing object, but the current tool is in the text addition state, the system enters the adding object editing operation mode. Different types of editing operation modes trigger different interactive components and editing logic. After determining the editing operation mode, the system generates an input control at the hit target object location. When the system enters text editing mode, it generates one or more input boxes above the target text area using DivTextInput or DivMultiTextInput. The position, size, rotation, and scaling of these input controls are calculated based on the rectangular range of the target text object and the current unified display matrix, ensuring precise alignment between the input controls and the original PDF text.

[0081] After the input control is generated, input events on the input control are listened to, and the corresponding text boundaries, selection range, and display effects are dynamically updated based on the input events to obtain the editing operation result. After the user enters text in the input control, input events are listened to in real time, and the following processing is performed for each input event: updating the text content, recalculating the character position and text bounding box, adjusting the width and height of the input box as needed, drawing the visible boundary of the currently edited object in the border canvas of the border operation layer, and maintaining the cursor position and selection display in multi-line or cross-input box scenarios. For image editing mode, rotation, deletion, and other operations in the image operation layer do not directly modify the bitmap canvas, but rather modify the matrix parameters, rotation angle, or change the state of the corresponding image object. Through the above dynamic update processing, the WYSIWYG display effect is maintained throughout the editing process, thereby obtaining the editing operation result.

[0082] Finally, the system writes the editing results back to the page object model, obtaining the edited page object model. After text or image editing is complete, the system writes the editing results generated in the interactive editing layer back to the corresponding PDF object model. This includes updating text content, updating object positions or boundaries, updating transformation matrices, and marking the addition, modification, or deletion status of objects. Under this mechanism, the interactive editing layer only serves as a medium for user input; the actual basis for subsequent saving remains the page object model itself. After the object data is updated, the system calls the page rendering logic again, redrawing the modified object onto the underlying Canvas, and simultaneously remounting or refreshing the interactive editing layer to ensure that the editing boxes, borders, and toolbars remain consistent with the latest page display, thus obtaining the edited page object model.

[0083] In step S105, the display transformation parameters of the annotation objects in the edited page object model are adapted. Since PDF annotation objects usually have their own appearance flow, the system matches the positional relationship between the annotation rectangle area and the appearance flow bounding box, and selects an appropriate display transformation by calculating indicators such as overlap, so as to reduce the display offset problem caused by the inconsistency between the appearance flow and the actual annotation area, thereby obtaining the adapted page object model.

[0084] In one embodiment, step S105 includes:

[0085] The annotation display parameters are obtained by reading the annotation rectangle region, appearance flow bounding box, appearance flow matrix, and page display matrix from the annotation object, respectively.

[0086] Based on the page display matrix in the annotation display parameters, the annotation rectangle area is mapped to the device space to obtain the target display area;

[0087] Based on the appearance flow bounding box and appearance flow matrix, multiple candidate display transformations that map the appearance flow to the device space are constructed to obtain a set of candidate display transformations;

[0088] Based on the candidate display transformation set, the appearance flow bounding box is transformed to obtain the candidate display area corresponding to each candidate display transformation;

[0089] Calculate the overlap ratio, intersection area, and center distance between each candidate display area and the target display area, and select the optimal candidate display transformation result from the candidate display transformation set according to a preset matching priority rule;

[0090] Based on the optimal candidate display transformation result, the appearance flow of the corresponding annotation object is appended to the rendering context to obtain the adapted page object model.

[0091] In this embodiment, the annotation display parameters are obtained by reading the annotation rectangle region, appearance flow bounding box, appearance flow matrix, and page display matrix from the annotation object. The annotation rectangle region (Rect) refers to the rectangular range defined by the current annotation object in the PDF page coordinate system, used to identify the expected display position of the annotation on the page. The appearance flow bounding box (BBox) refers to the coordinate boundary range defined by the appearance flow associated with the current annotation object, used to describe the effective area of ​​the content drawn within the appearance flow. The appearance flow matrix is ​​the transformation matrix inherent to the appearance flow, used to define the mapping relationship between the coordinates within the appearance flow and the annotation coordinates. The page display matrix is ​​the unified display matrix calculated in step S103, used to map the page coordinate system to device space. If the current annotation object does not have an appearance flow or the page object corresponding to the appearance flow is empty, the system does not execute the subsequent appearance matching process. These four parameters together constitute the annotation display parameters, providing complete data for subsequent target display area determination, candidate display transformation construction, and optimal transformation selection.

[0092] After obtaining the annotation display parameters, the system maps the annotation rectangle region to the device space based on the page display matrix in the annotation display parameters to obtain the target display area. The system transforms the coordinates of the current annotation object's annotation rectangle region (Rect) through the page display matrix, mapping it from the PDF page coordinate system to the device display space to obtain the expected display range of the annotation in the device space, i.e., the target display area. It should be noted that for text markup annotations such as highlighting, underlining, wavy lines, and strikethrough, if the current annotation object contains QuadPoints data, the system prioritizes using the bounding area formed by QuadPoints in the device space as the target display area, rather than directly using the mapping result of the annotation rectangle region (Rect), because QuadPoints are usually closer to the actual coverage of the text annotation than Rect, and can more accurately reflect the actual display position of the annotation.

[0093] Furthermore, based on the appearance flow bounding box and appearance flow matrix, the system constructs multiple candidate display transformations that map the appearance flow to the device space, resulting in a candidate display transformation set. Since different PDF generation tools may have different pre-combination methods for the appearance flow matrix when creating annotation objects, the system does not only attempt a single matrix combination, but constructs multiple possible transformation combinations based on the appearance flow bounding box (BBox) and appearance flow matrix, combined with the page display matrix. The candidate display transformation set includes, for example, combinations of form matrix and page display matrix, appearance flow matrix and page display matrix, form matrix, appearance flow matrix, and page display matrix, as well as a single transformation using only the page display matrix. By constructing these multiple candidate display transformations, the system can accommodate the inconsistency in the pre-combination methods of the annotation appearance flow matrix for different PDF file sources, providing sufficient candidate solutions for subsequent optimal transformation selection.

[0094] After obtaining the candidate display transformation set, the system performs transformation calculations on the appearance flow bounding box based on the candidate display transformation set to obtain the candidate display area corresponding to each candidate display transformation. For each candidate display transformation in the candidate display transformation set, the system maps the appearance flow bounding box (BBox) to device space through the candidate display transformation, and calculates the display area of ​​the appearance flow in device space under that transformation condition. The source of the candidate display area can include the following situations: the result obtained directly from the appearance flow bounding box (BBox) through candidate transformation mapping; the result obtained from the union of the bounding boxes of each page object inside the appearance flow through candidate transformation mapping; if there are nested form objects inside the appearance flow, the system further recursively calculates the union of the bounding boxes of the sub-objects inside the form object, and then obtains the corresponding result through candidate transformation mapping. Through the above processing, the system finally obtains a candidate display area for subsequent scoring comparison for each candidate display transformation.

[0095] Furthermore, the overlap ratio, intersection area, and center distance between each candidate display area and the target display area are calculated, and the optimal candidate display transformation result is selected from the candidate display transformation set according to a preset matching priority rule. Each candidate display area is spatially compared with the previously determined target display area, and the following matching indices are calculated: overlap ratio, which measures the degree of spatial overlap between the candidate display area and the target display area; a higher overlap ratio indicates that the candidate display transformation is closer to the actual display position of the annotation; intersection area, which measures the size of the absolute overlap area between the candidate display area and the target display area; and center distance, which measures the offset between the geometric center of the candidate display area and the geometric center of the target display area. After calculating the above matching indices, the system selects the optimal candidate according to a preset matching priority rule. The preset matching priority rule is to prioritize the candidate display transformation with the largest overlap ratio; if multiple candidate display transformations have the same or similar overlap ratios, then the candidate display transformation with the larger intersection area is selected; if the intersection areas are still similar, then the candidate display transformation with the smaller center distance is selected. Through the hierarchical comparison of the above multi-level matching priority rules, the system can automatically select the candidate display transformation that best matches the target display area from various matrix combination schemes, and obtain the optimal candidate display transformation result.

[0096] Finally, based on the optimal candidate display transformation result, the system appends the appearance flow of the corresponding annotation object to the rendering context, obtaining the adapted page object model. After determining the optimal candidate display transformation result, the system uses this optimal candidate display transformation to append each object in the appearance flow of the current annotation object to the rendering context of the current page, instead of drawing it directly with fixed coordinates. In this way, the appearance flow of the annotation object shares a unified display system with the main content of the page, and uses consistent coordinate transformation rules during rendering output. Through the above matching and adaptation processing, the system can automatically adapt to the most suitable display transformation under different PDF file sources and different annotation appearance flow definition methods, effectively reducing problems such as misalignment, offset, scaling abnormalities, and rotation abnormalities in the annotation appearance during display, thereby obtaining the adapted page object model.

[0097] In step S106, after editing is completed, the adapted page object model is traversed, and object operations marked as added, deleted, or modified are extracted to form page-aggregated content modification data. Resource information such as newly added fonts is extracted separately. The system integrates the page-aggregated content modification data and resource information to output incremental operation data, rather than sending back the entire page or file data, thus achieving efficient incremental saving.

[0098] In one embodiment, step S106 includes:

[0099] Create an incremental data container and traverse each page in the adapted page object model to obtain a page-level traversal sequence;

[0100] Traverse each page in the page-level traversal sequence to filter out the objects marked as savable, and obtain a set of savable objects;

[0101] Extract the object operations marked as changed from the set of savable objects to obtain a set of changed object operations;

[0102] The set of operations on the changed objects is summarized by the current page to obtain a page-level operation array;

[0103] Write the page-level operation array into the corresponding content modification item in the incremental save data container, and extract font resource information from the change object operation set and write it into a preset independent resource set;

[0104] Based on all content modifications in the incrementally saved data container and the independent resource set, the incremental operation data is aggregated and output.

[0105] In this embodiment, an incremental save data container is created, and each page in the adapted page object model is traversed page by page to obtain a page-level traversal sequence. The incremental save data container refers to a unified data structure used to carry the final incremental save result. This container includes at least two top-level components: a font resource information set `Font`, used to store newly added or changed font resources involved in the editing process; and a content modification set organized by page, `ContentModify`, used to store the object operation data that has changed on each page. After the incremental save data container is created, the system traverses the adapted page object model in the current document page by page, obtaining the page object data corresponding to each page, thereby forming a page-level traversal sequence. This provides an ordered processing foundation for subsequent page-by-page extraction of change operations.

[0106] After obtaining the page-level traversal sequence, the system iterates through each page in the sequence to filter out objects marked as savable, resulting in a set of savable objects. For each page in the page-level traversal sequence, the system continues to iterate through each object instance in the page's object array. In the current implementation, the system focuses on processing text objects (TextObj) and image objects (ImgObj). Specifically, the system filters out object instances of these types marked as savable from the current page's object array and aggregates them into the current page's set of savable objects. Through this filtering process, the system focuses subsequent change extraction on the object types actually involved in editing and saving, avoiding unnecessary traversal and processing of objects that do not need to be saved.

[0107] Furthermore, the system extracts the object operations marked as changed from the set of savable objects to obtain a set of changed object operations. For each object in the set of savable objects, the system calls the operation generation logic corresponding to that object to determine whether it has been added, deleted, or modified during the editing process. If the current object has been changed, the system generates corresponding operation description data based on its change type and content; if the current object has not undergone any changes during the editing process, the system does not generate operation description data for that object, nor does it write it into the subsequent save result. In other words, what the system saves are the change operation descriptions for each object, rather than a static snapshot of the entire page of the object, thereby achieving incremental change extraction at the object level. After the above processing, all changed object operations in the current page are aggregated to obtain the set of changed object operations.

[0108] After obtaining the set of changed object operations, the system summarizes these operations by current page to obtain a page-level operation array. The system aggregates all changed object operations within the current page into a single operation array. If no objects on the current page have changed (i.e., the set of changed object operations is empty), that page will not be written into the subsequent content modification set, thus avoiding invalid saved data. By summarizing by page, the system organizes scattered object-level change operations into page-level operation arrays, facilitating subsequent data writing and transmission on a page-by-page basis.

[0109] Furthermore, the system writes the page-level operation array into the corresponding content modification item in the incremental save data container, and extracts font resource information from the change object operation set and writes it into a preset independent resource set. When a page has a change operation, the system creates a corresponding page-level save item, i.e., a content modification item ContentModify, and writes the current page's page index PageIndex and the current page's change operation array modData into it. In this way, all saved data is organized according to the page dimension, which facilitates the subsequent replay of editing operations page by page by the server or local save end according to the page index. At the same time, in the process of writing object operations into page-level save items, the system further checks whether each operation is accompanied by resource dependency information, such as font resource information added during the editing process. If such font resource information exists, the system separates it from the object operation and writes it separately into the preset independent resource set Font in the incremental save data container, instead of repeatedly saving the font resource information in the operation data of each page. By storing font resource information centrally in an independent resource set, the system effectively avoids redundant storage of resource data in each page operation and reduces the overall size of incremental save data.

[0110] Finally, the system aggregates and outputs incremental operation data based on all content modifications in the incremental save data container and the independent resource set. After all pages have been traversed, the incremental save data container contains the complete save result. The content modification set `ContentModify` describes all changes made to each page at the object level, and the independent resource set `Font` describes any new or changed font resources added during the editing process. The system aggregates all content modifications in the incremental save data container with the independent resource set to obtain the final incremental operation data. This incremental operation data can be serialized into JSON format and then sent to the save task service or local save module. The backend service or local program then reconstructs and outputs the final PDF file based on the incremental operation data. Through this incremental save mechanism, the system only transmits the object operations and related resource information that actually changed during the editing process, rather than sending back the entire page or file data, thus significantly reducing the network transmission burden and achieving efficient incremental save.

[0111] In one embodiment, the web-based PDF file editing method further includes:

[0112] Iterate through each object instance in the page object model, extract the font resource identifier, image resource identifier, and form embedded resource identifier associated with each object instance, perform cross-page deduplication, and integrate to obtain a resource dependency list;

[0113] Initiate asynchronous loading requests for the resource dependency list, and register a corresponding loading completion callback function for each asynchronous loading request to obtain a set of resource callback tasks;

[0114] In response to the return results of each callback function in the resource callback task set, the loading completion status of each resource is summarized by page dimension to obtain the page-level resource ready status;

[0115] When the page-level resource ready status indicates that all associated resources of the target page have been loaded, the ready resource data is bound to the corresponding object instance in the target page to obtain the resource-ready page object model.

[0116] In this embodiment, various objects within a PDF file are typically associated with external dependencies such as font resources, image resources, and form-embedded resources. In a browser environment, these resources cannot be synchronously obtained during document parsing and must be loaded asynchronously. Without a unified resource loading and callback mechanism, issues such as missing characters, incomplete images, and partial page flickering can easily occur. To address these problems, the system iterates through all object instances in the page object model, extracting the font resource identifiers, image resource identifiers, and form-embedded resource identifiers associated with each instance, performing cross-page deduplication, and integrating them to obtain a resource dependency list. The system iterates through all object instances in the page object model page by page, extracting the associated resource identifier information for each object instance based on its object type. The font resource identifier refers to the unique identifier of the font file that the text object TextObj depends on during rendering, used to locate and obtain the corresponding font data in the subsequent loading stage; the image resource identifier refers to the unique identifier of the image resource referenced by the image object ImgObj, used to locate and obtain the corresponding image data; the form embedded resource identifier refers to the unique identifier of various resources nested within the form object FormObj, used to locate and obtain the embedded resource data that the form object depends on. Since multiple objects on different pages may reference the same font resource or the same image resource, after extracting the resource identifiers of each object instance, the system further performs cross-page deduplication processing, merging duplicate resource identifiers into a unique entry to avoid initiating duplicate loading requests for the same resource. After the above extraction and deduplication processing, the system integrates all unique resource identifiers to obtain a resource dependency list, which completely records all external resource items depended on by object instances on all pages in the current document.

[0117] After obtaining the resource dependency list, the system initiates asynchronous loading requests for the resource dependency list and registers a corresponding loading completion callback function for each asynchronous loading request, resulting in a resource callback task set. The system sequentially reads each resource item in the resource dependency list and initiates a corresponding asynchronous loading request for each resource. For resource items corresponding to font resource identifiers, the system initiates an asynchronous loading request for font data; for resource items corresponding to image resource identifiers, the system initiates an asynchronous loading request for image data; for resource items corresponding to form embedded resource identifiers, the system initiates an asynchronous loading request for form embedded resource data. Simultaneously with each asynchronous loading request, the system registers a corresponding loading completion callback function for that request. The loading completion callback function is a callback processing logic automatically triggered by the system when the asynchronous loading process of the resource item ends and the resource data is successfully obtained, used to notify the system that the resource has been loaded and to transmit the obtained resource data. After the above processing, all resource items in the resource dependency list are associated with corresponding asynchronous loading requests and loading completion callback functions, thus forming a resource callback task set.

[0118] Furthermore, the system responds to the return results of each callback function in the resource callback task set, summarizing the loading completion status of each resource by page dimension to obtain the page-level resource readiness status. When an asynchronous loading request in the resource callback task set completes, the system automatically triggers the loading completion callback function registered for that request and receives the return result of the callback function. The return result contains the successfully loaded resource data and the resource identifier corresponding to that resource. Based on the resource identifier, the system searches for all pages in the page object model that reference that resource and updates the completion marker of that resource in the resource loading status record of the corresponding page. Since each object instance in the same page may depend on different resource items, the system needs to summarize the loading completion status of each resource by page dimension. Specifically, the system maintains a resource loading status record for each page, recording the loading completion status of each resource in all resource items associated with that page. When a resource completes loading and triggers a callback, the system updates the resource loading status records of each page involved in that resource and determines the current resource readiness level of each page, thereby obtaining the page-level resource readiness status of each page.

[0119] Finally, when the page-level resource readiness status indicates that all associated resources of the target page have been loaded, the system binds the ready resource data to the corresponding object instance in the target page, thus obtaining a resource-ready page object model. The system continuously monitors the page-level resource readiness status of each page. When the page-level resource readiness status of a target page indicates that all font resources, image resources, and form-embedded resources associated with that page have been loaded, the system binds each ready resource data to the corresponding object instance in the target page. Specifically, the loaded font data is bound to the text object instance that references the font, enabling the text object to correctly call the required font for text drawing during rendering; the loaded image data is bound to the image object instance that references the image, enabling the image object to correctly display the corresponding image content during rendering; and the loaded form-embedded resource data is bound to the form object instance that references the resource, ensuring that the nested content within the form object is fully presented. After the above resource binding process, all object instances in the target page have the complete resource data required for rendering, thus obtaining a resource-ready page object model. Only after the page object model is formed with ready resources will the system perform the final rendering output on the target page, thereby effectively avoiding problems such as missing text, blank images, and partial page flickering caused by unread resources, and improving the stability and integrity of PDF file rendering on the web.

[0120] In summary, this application adopts a layered processing structure of document layer-page layer-object layer-rendering layer-editing layer-saving layer. By parsing document data layer by layer to obtain paginated resource data, document-level data and page-level data are separated, allowing each page's data to be loaded and processed on demand. This effectively solves the problems of slow loading of large files, long initial screen response time, and excessive memory consumption caused by parsing the entire PDF file at once in existing technologies. It also reduces front-end computing overhead and is beneficial for improving operating efficiency in scenarios with low performance devices and large-scale online service deployments. By objectifying and parsing the paginated resource data, the primitives in each page are restored into object instances containing position parameters, matrix parameters, state reference relationships, and editing marks, thus constructing a page object model. This enables the system to not only support the browsing and display of PDF documents but also support object-level text editing, image editing, and annotation editing capabilities, providing a more accurate and flexible editing foundation for online PDF editing products. By calculating a unified display matrix from page space to device space based on the page object model and combining it with the device pixel ratio to adapt the canvas size, all kinds of objects on the page are rendered using consistent coordinate transformation rules under conditions such as scaling, rotation and high-resolution screen display. This effectively solves the problem of object display offset and inaccurate editing positioning caused by the inconsistency between rendering coordinates and editing coordinates in the existing technology, and improves the display accuracy of PDF file editing on the Web.

[0121] Furthermore, by overlaying an interactive editing layer on top of the canvas rendering layer, the system leverages the canvas to maintain high-fidelity rendering of PDF primitives and text, while the interactive editing layer handles text input, selection operations, and hit detection. This effectively solves the problems in existing technologies where a pure canvas cannot support input methods and text interactions, and a pure DOM cannot guarantee consistency with the original PDF layout. This improves the editing experience while maintaining rendering accuracy. By constructing multiple candidate display transformations for annotation objects and automatically selecting the optimal candidate display transformation result based on matching indicators such as overlap ratio, intersection area, and center distance, the system effectively solves the problems of display misalignment, scaling abnormalities, and rotational distortion that easily occur in existing technologies under different PDF file sources and different appearance flow definition methods. This improves the display accuracy of annotation objects under various display conditions. By traversing the page object model to extract the object operations marked as changed, and outputting incremental operation data in a page-aggregated form, an object-level incremental saving mechanism is realized. Only the operation data and related resource information that actually changed during the editing process are transmitted, rather than the entire page data or the entire file data is returned. This effectively solves the problems of low saving efficiency and heavy network transmission burden in the existing technology, reduces network transmission costs and server reconstruction pressure, and is more suitable for the deployment needs of large-scale online services.

[0122] Combination Figure 2 As shown, Figure 2 A schematic block diagram of a web-based PDF file editing device provided in this embodiment of the invention. The web-based PDF file editing device 200 includes:

[0123] The data acquisition unit 201 is used to acquire the document data of the PDF file to be edited, and to perform layered parsing on the document data to obtain pagination resource data;

[0124] The data parsing unit 202 is used to perform object-oriented parsing on the pagination resource data to restore the graphic elements in each page into object instances and obtain the page object model;

[0125] The page rendering unit 203 is used to calculate the unified display matrix from page space to device space based on the page object model, and render the objects in the page object model to the canvas after transformation by the unified display matrix to obtain the page rendering screen.

[0126] The interactive editing unit 204 is used to overlay an interactive editing layer on the page rendering screen, respond to editing operations through the interactive editing layer and synchronously map the operation results to the page object model to obtain the edited page object model;

[0127] The parameter adaptation unit 205 is used to adapt the display transformation parameters of the annotation objects in the edited page object model to obtain the adapted page object model.

[0128] The data output unit 206 is used to traverse the adapted page object model to extract the object operations marked as changed, and output incremental operation data in a page-aggregated form.

[0129] In this embodiment, the data acquisition unit 201 acquires the document data of the PDF file to be edited and performs layered parsing on the document data to obtain pagination resource data; the data parsing unit 202 performs object-oriented parsing on the pagination resource data to restore the primitives in each page to object instances, thereby obtaining a page object model; the page rendering unit 203 calculates a unified display matrix from page space to device space based on the page object model, and renders the objects in the page object model onto the canvas after transformation by the unified display matrix, thereby obtaining a page rendering screen; the interactive editing unit 204 overlays an interactive editing layer on the page rendering screen, responds to editing operations through the interactive editing layer, and synchronously maps the operation results to the page object model, thereby obtaining an edited page object model; the parameter adaptation unit 205 adapts the display transformation parameters of the annotation objects in the edited page object model, thereby obtaining an adapted page object model; the data output unit 206 traverses the adapted page object model to extract the object operations marked as changed, and outputs incremental operation data in a page aggregation form.

[0130] In one embodiment, the data parsing unit 202 is specifically used for:

[0131] Read the single-page binary data from the pagination resource data, and create a page object container based on the single-page binary data;

[0132] The common state data in the page object container is parsed, and the general state, cropping state, graphic state, color state and text state are extracted respectively and merged to obtain the page common state table;

[0133] Based on the preset object type, the page content flow in the page object container is parsed to generate text objects, image objects, path objects and form objects respectively, and then merged to obtain a page object array;

[0134] For each object in the page object array, establish position parameters, matrix parameters, state reference relationships, and editing tags to obtain an editable page object array;

[0135] Parse the page annotation data in the page object container, and generate a page annotation list based on the position parameters of each object in the editable page object array;

[0136] The editable page object array, the page common state table, and the page annotation list are integrated to obtain the page object model.

[0137] In one embodiment, the page rendering unit 203 is specifically used for:

[0138] The page size parameters of the current page in the page object model, as well as the scaling and rotation parameters of the preset viewer, are obtained to obtain the rendering parameter set;

[0139] Based on the device pixel ratio in the set of rendering parameters, the logical size and pixel size of the canvas are set respectively to obtain a canvas with the appropriate size.

[0140] Based on the page size parameter, the scaling parameter, and the rotation parameter in the rendering parameter set, the coordinate mapping relationship from the page space to the device space is calculated to obtain a unified display matrix;

[0141] Create a rendering context and write the unified display matrix into the rendering context to obtain the initial rendering context;

[0142] The main content object in the page object model is appended to the initial rendering context to obtain the complete rendering context;

[0143] Based on the scaling ratio in the set of rendering parameters and the device pixel ratio, the rendering output is performed on the complete rendering context, and the rendering result is drawn onto the canvas after the size is adapted to obtain the page rendering screen.

[0144] In one embodiment, the interactive editing unit 204 is specifically used for:

[0145] Create an interaction controller and bind it to the canvas corresponding to the page rendering screen. Attach the text editing layer, border operation layer, and image operation layer to the canvas to obtain the interaction editing layer.

[0146] In the interactive editing layer, the text hit detection module and the image hit detection module are initialized respectively to obtain the hit processing module group;

[0147] In response to browser events on the interactive editing layer, the page event coordinates are calculated.

[0148] The page event coordinates are input into the hit processing module group. At the same time, the editing operation mode of text editing, image editing or adding object is determined according to the hit result, and an input control is generated at the position of the hit target object.

[0149] Listen for input events on the input control, and dynamically update the corresponding text boundaries, selection area, and display effect based on the input events to obtain the editing operation result;

[0150] The result of the editing operation is written back to the page object model to obtain the edited page object model.

[0151] In one embodiment, the parameter adaptation unit 205 is specifically used for:

[0152] The annotation display parameters are obtained by reading the annotation rectangle region, appearance flow bounding box, appearance flow matrix, and page display matrix from the annotation object, respectively.

[0153] Based on the page display matrix in the annotation display parameters, the annotation rectangle area is mapped to the device space to obtain the target display area;

[0154] Based on the appearance flow bounding box and appearance flow matrix, multiple candidate display transformations that map the appearance flow to the device space are constructed to obtain a set of candidate display transformations;

[0155] Based on the candidate display transformation set, the appearance flow bounding box is transformed to obtain the candidate display area corresponding to each candidate display transformation;

[0156] Calculate the overlap ratio, intersection area, and center distance between each candidate display area and the target display area, and select the optimal candidate display transformation result from the candidate display transformation set according to a preset matching priority rule;

[0157] Based on the optimal candidate display transformation result, the appearance flow of the corresponding annotation object is appended to the rendering context to obtain the adapted page object model.

[0158] In one embodiment, the data output unit 206 is specifically used for:

[0159] Create an incremental data container and traverse each page in the adapted page object model to obtain a page-level traversal sequence;

[0160] Traverse each page in the page-level traversal sequence to filter out the objects marked as savable, and obtain a set of savable objects;

[0161] Extract the object operations marked as changed from the set of savable objects to obtain a set of changed object operations;

[0162] The set of operations on the changed objects is summarized by the current page to obtain a page-level operation array;

[0163] Write the page-level operation array into the corresponding content modification item in the incremental save data container, and extract font resource information from the change object operation set and write it into a preset independent resource set;

[0164] Based on all content modifications in the incrementally saved data container and the independent resource set, the incremental operation data is aggregated and output.

[0165] In one embodiment, the web-based PDF file editing device 200 is further configured to:

[0166] Iterate through each object instance in the page object model, extract the font resource identifier, image resource identifier, and form embedded resource identifier associated with each object instance, perform cross-page deduplication, and integrate to obtain a resource dependency list;

[0167] Initiate asynchronous loading requests for the resource dependency list, and register a corresponding loading completion callback function for each asynchronous loading request to obtain a set of resource callback tasks;

[0168] In response to the return results of each callback function in the resource callback task set, the loading completion status of each resource is summarized by page dimension to obtain the page-level resource ready status;

[0169] When the page-level resource ready status indicates that all associated resources of the target page have been loaded, the ready resource data is bound to the corresponding object instance in the target page to obtain the resource-ready page object model.

[0170] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.

[0171] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed, can perform the steps provided in the above embodiments. The storage medium may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0172] This invention also provides a computer device, which may include a memory and a processor. The memory stores a computer program, and when the processor calls the computer program in the memory, it can implement the steps provided in the above embodiments. Of course, the computer device may also include various network interfaces, a power supply, a graphics card, etc., to utilize the graphics card's performance to operate the model, such as for inference and training.

[0173] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.

[0174] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A web-based PDF file editing method, characterized in that, include: Obtain the document data of the PDF file to be edited, and perform layered parsing on the document data to obtain pagination resource data; The paginated resource data is parsed in an object-oriented manner to restore the graphic elements in each page into object instances, thereby obtaining the page object model; The unified display matrix from page space to device space is calculated based on the page object model, and the objects in the page object model are rendered onto the canvas after being transformed by the unified display matrix to obtain the page rendering screen. An interactive editing layer is overlaid on the rendered page. The interactive editing layer responds to editing operations and synchronously maps the operation results to the page object model to obtain the edited page object model. The annotation objects in the edited page object model are adapted to display transformation parameters to obtain the adapted page object model. The adapted page object model is traversed to extract the object operations marked as changed, and incremental operation data is output in page-aggregated form.

2. The PDF file editing method based on a web interface according to claim 1, characterized in that, Also includes: Iterate through each object instance in the page object model, extract the font resource identifier, image resource identifier, and form embedded resource identifier associated with each object instance, perform cross-page deduplication, and integrate to obtain a resource dependency list; Initiate asynchronous loading requests for the resource dependency list, and register a corresponding loading completion callback function for each asynchronous loading request to obtain a set of resource callback tasks; In response to the return results of each callback function in the resource callback task set, the loading completion status of each resource is summarized by page dimension to obtain the page-level resource ready status; When the page-level resource ready status indicates that all associated resources of the target page have been loaded, the ready resource data is bound to the corresponding object instance in the target page to obtain the resource-ready page object model.

3. The PDF file editing method based on a web interface according to claim 1, characterized in that, The step of objectifying and parsing the paginated resource data to restore the primitives in each page into object instances and obtain the page object model includes: Read the single-page binary data from the pagination resource data, and create a page object container based on the single-page binary data; The common state data in the page object container is parsed, and the general state, cropping state, graphic state, color state and text state are extracted respectively and merged to obtain the page common state table; Based on the preset object type, the page content flow in the page object container is parsed to generate text objects, image objects, path objects and form objects respectively, and then merged to obtain a page object array; For each object in the page object array, establish position parameters, matrix parameters, state reference relationships, and editing tags to obtain an editable page object array; Parse the page annotation data in the page object container, and generate a page annotation list based on the position parameters of each object in the editable page object array; The editable page object array, the page common state table, and the page annotation list are integrated to obtain the page object model.

4. The PDF file editing method based on a web interface according to claim 1, characterized in that, The process of calculating a unified display matrix from page space to device space based on the page object model, and then rendering the objects in the page object model onto the canvas after transformation by the unified display matrix to obtain the page rendering screen includes: The page size parameters of the current page in the page object model, as well as the scaling and rotation parameters of the preset viewer, are obtained to obtain the rendering parameter set; Based on the device pixel ratio in the set of rendering parameters, the logical size and pixel size of the canvas are set respectively to obtain a canvas with the appropriate size. Based on the page size parameter, the scaling parameter, and the rotation parameter in the rendering parameter set, the coordinate mapping relationship from the page space to the device space is calculated to obtain a unified display matrix; Create a rendering context and write the unified display matrix into the rendering context to obtain the initial rendering context; The main content object in the page object model is appended to the initial rendering context to obtain the complete rendering context; Based on the scaling ratio in the set of rendering parameters and the device pixel ratio, the rendering output is performed on the complete rendering context, and the rendering result is drawn onto the canvas after the size is adapted to obtain the page rendering screen.

5. The PDF file editing method based on a web interface according to claim 1, characterized in that, The step of overlaying an interactive editing layer on the rendered page, responding to editing operations through the interactive editing layer, and synchronously mapping the operation results to the page object model to obtain the edited page object model includes: Create an interaction controller and bind it to the canvas corresponding to the page rendering screen. Attach the text editing layer, border operation layer, and image operation layer to the canvas to obtain the interaction editing layer. In the interactive editing layer, the text hit detection module and the image hit detection module are initialized respectively to obtain the hit processing module group; In response to browser events on the interactive editing layer, the page event coordinates are calculated. The page event coordinates are input into the hit processing module group. At the same time, the editing operation mode of text editing, image editing or adding object is determined according to the hit result, and an input control is generated at the position of the hit target object. Listen for input events on the input control, and dynamically update the corresponding text boundaries, selection area, and display effect based on the input events to obtain the editing operation result; The result of the editing operation is written back to the page object model to obtain the edited page object model.

6. The PDF file editing method based on a web interface according to claim 1, characterized in that, The step of adapting the display transformation parameters of the annotation objects in the edited page object model to obtain the adapted page object model includes: The annotation display parameters are obtained by reading the annotation rectangle region, appearance flow bounding box, appearance flow matrix, and page display matrix from the annotation object, respectively. Based on the page display matrix in the annotation display parameters, the annotation rectangle area is mapped to the device space to obtain the target display area; Based on the appearance flow bounding box and appearance flow matrix, multiple candidate display transformations that map the appearance flow to the device space are constructed to obtain a set of candidate display transformations; Based on the candidate display transformation set, the appearance flow bounding box is transformed to obtain the candidate display area corresponding to each candidate display transformation; Calculate the overlap ratio, intersection area, and center distance between each candidate display area and the target display area, and select the optimal candidate display transformation result from the candidate display transformation set according to a preset matching priority rule; Based on the optimal candidate display transformation result, the appearance flow of the corresponding annotation object is appended to the rendering context to obtain the adapted page object model.

7. The PDF file editing method based on a web interface according to claim 1, characterized in that, The process of traversing the adapted page object model to extract object operations marked as changed and outputting incremental operation data in a page-aggregated format includes: Create an incremental data container and traverse each page in the adapted page object model to obtain a page-level traversal sequence; Traverse each page in the page-level traversal sequence to filter out the objects marked as savable, and obtain a set of savable objects; Extract the object operations marked as changed from the set of savable objects to obtain a set of changed object operations; The set of operations on the changed objects is summarized by the current page to obtain a page-level operation array; Write the page-level operation array into the corresponding content modification item in the incremental save data container, and extract font resource information from the change object operation set and write it into a preset independent resource set; Based on all content modifications in the incrementally saved data container and the independent resource set, the incremental operation data is aggregated and output.

8. A web-based PDF file editing device, characterized in that, include: The data acquisition unit is used to acquire the document data of the PDF file to be edited, and to perform layered parsing of the document data to obtain pagination resource data; The data parsing unit is used to perform object-oriented parsing on the paginated resource data to restore the graphic elements in each page into object instances and obtain the page object model; The page rendering unit is used to calculate the unified display matrix from page space to device space based on the page object model, and render the objects in the page object model to the canvas after transformation by the unified display matrix to obtain the page rendering screen; An interactive editing unit is used to overlay an interactive editing layer on the rendered page, respond to editing operations through the interactive editing layer and synchronously map the operation results to the page object model to obtain the edited page object model; The parameter adaptation unit is used to adapt the display transformation parameters of the annotation objects in the edited page object model to obtain the adapted page object model. The data output unit is used to traverse the adapted page object model to extract the object operations marked as changed, and output incremental operation data in page aggregation form.

9. A computer device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the web-based PDF file editing method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the web-based PDF file editing method as described in any one of claims 1 to 7.