A method and system for splitting a PDF document

By parsing the xref table at the end of the PDF file, calculating the byte size of the object data range, grouping according to user settings, reorganizing the object numbers, and generating a new xref table, the problem of not being able to accurately split PDFs according to user-defined sizes in existing technologies is solved, and a PDF split file with complete structure and independent access is achieved.

CN122174810APending Publication Date: 2026-06-09赛博爱思(上海)软件科技有限公司

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
赛博爱思(上海)软件科技有限公司
Filing Date
2026-03-23
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

Existing PDF splitting tools cannot accurately split files according to the user-defined file size. Directly cutting binary files can easily damage the PDF structure, making the files unusable.

Method used

By parsing the xref table at the end of the PDF file, the correspondence between objects and physical locations is established, the byte size of the object data range is calculated, the objects are grouped according to the target file size set by the user, the object numbers and cross-reference relationships are reorganized, a new xref table and trailer field are generated, and multiple structurally complete PDF split files are output.

Benefits of technology

It achieves precise splitting according to the set size, protects the integrity of the PDF structure, and ensures that the split files are independently accessible and have complete content without missing pages or formatting errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122174810A_ABST
    Figure CN122174810A_ABST
Patent Text Reader

Abstract

The application discloses a PDF document splitting method and system, and belongs to the technical field of PDF document splitting, which comprises the following steps: analyzing an xref table at the end of a PDF file, obtaining all object numbers and their physical file offsets, and establishing the corresponding relationship between the objects and the physical positions; according to the physical offsets in the xref table, the data interval byte size of each object is calculated, if page splitting is needed, the page objects are identified and the total size of all direct and indirect objects contained in a single page is counted, the application supports accurate splitting of the PDF file according to the set byte capacity, and solves the storage, uploading and distribution obstacles of large files; in the splitting process, the underlying structure operations such as PDF objects and cross index tables are used, so that the logical structure and content integrity of the PDF are effectively protected, and there are no invalid pages and unreadable phenomena.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of PDF document splitting technology, specifically referring to a method and system for splitting PDF documents. Background Technology

[0002] PDF (Portable Document Format) is widely used for document storage and transmission due to its device, platform, and operating system independence. However, as file sizes increase, PDF documents are prone to problems such as slow transmission speeds, high storage pressure, and difficulty in distribution during network transmission, storage, and management. Existing PDF splitting tools mainly support splitting by page number, bookmarks, etc., and cannot accurately split according to the user-defined file size. In addition, directly cropping binary files can easily damage the PDF structure, rendering the file unusable. Therefore, how to maintain the integrity of the PDF structure and achieve automatic splitting of a specified size is a technical problem that urgently needs to be solved. To address this, a method and system for PDF document splitting is proposed. Summary of the Invention

[0003] The purpose of this invention is to provide a method and system for splitting PDF documents to solve the problems mentioned in the background art.

[0004] To achieve the above objectives, the present invention provides the following technical solution: a method for splitting PDF documents, comprising the following steps:

[0005] S1. Parse the xref table at the end of the PDF file to obtain all object numbers and their physical file offsets, and establish the correspondence between objects and physical locations;

[0006] S2. Calculate the data range size in bytes for each object based on the physical offset in the xref table. If page splitting is required, identify the page objects and calculate the total size of all direct and indirect objects contained in a single page.

[0007] S3. Based on the target file size set by the user, the size of the objects in bytes is added sequentially, and a preset threshold is used to determine whether the grouping condition is met, and multiple object subsets are formed.

[0008] S4. For each subset of objects, reorganize the numbering of objects within it and the cross-reference relationships between objects, and correct the references across objects.

[0009] S5. Generate a new xref table, trailer field, and necessary header information for the PDF file independently for each subset of objects;

[0010] S6. Integrate the reorganized subset of objects with the newly generated xref table, trailer field, and header information to output multiple structurally complete and independently accessible PDF split files.

[0011] Preferably, in step S1, parsing the xref table at the end of the PDF file specifically includes: extracting the starting offset address of the xref table from the trailer field at the end of the PDF file, and locating the xref table storage area based on the offset address; parsing the segmented structure in the xref table according to the PDF file format specification, extracting the starting value of the object number, the number of objects, and the physical file offset of each object contained in each segment; traversing the object information of all segments, summarizing the unique object numbers of all direct and indirect objects in the PDF file, and recording the physical offset corresponding to each object number; and establishing an object information index table, which uses the object number as a unique identifier and stores the corresponding physical offset, object type marker, and initial state marker.

[0012] Preferably, in step S2, calculating the data interval size in bytes for each object specifically includes: for adjacent objects stored contiguously, subtracting the physical offset of the current object from the physical offset of the object to obtain the data interval size in bytes for the current object; for objects not stored contiguously, determining the end position of the data interval by parsing the end marker of the object, and calculating the difference between the physical offset of the current object and the end position as the byte size;

[0013] When identifying page objects, the resource objects, content objects, and annotation objects associated with the page objects are traced by finding the corresponding type identifiers in the PDF file. When calculating the total size of objects on a single page, the data range in bytes of all objects in the page object set is summed, excluding the byte size of objects that are referenced repeatedly.

[0014] Preferably, in step S3, generating an object set by grouping according to the target capacity specifically includes: the target file size set by the user supports multiple units, and the system automatically converts them into a unified unit for calculation; the preset threshold is user-defined and adjustable, and when the byte size of the accumulated objects reaches a reasonable range of the target file size, the current accumulation is stopped and the object subset is completed; if the total size of a certain page object exceeds the sum of the target file size and the threshold, then the page is treated as a separate object subset.

[0015] Preferably, in step S3, the user simultaneously sets the maximum capacity threshold for a single page and the total target file size. First, page object identification and single page size statistics are performed to filter out pages that exceed the maximum capacity threshold for a single page and group them separately. The remaining pages are then grouped according to an accumulation rule. In the composite splitting mode, the preset threshold is automatically adjusted to a reasonable range. If a group contains multiple pages, a page association tag is added to the new xref table.

[0016] Preferably, in step S4, reorganizing object numbers and interactive reference relationships specifically includes: for each object subset, reassigning new object numbers according to the storage order of objects within the subset, with the new object numbers being consecutively numbered starting from the initial sequence number to form an independent object numbering system within the subset; traversing the content data of each object within the subset, identifying the object reference markers contained therein, querying the mapping relationship between the original object number and the new object number, and replacing the original object number in the reference marker with the corresponding new object number; for cross-object subset references, adding external reference markers and recording the file identifier of the target subset; establishing a reference correction log to record the original reference, corrected reference, and mapping relationship of each object for use in verifying the integrity of the split files.

[0017] Preferably, in step S5, generating a new xref table, trailer field, and header information specifically includes: the structure of the new xref table is compatible with the xref table format of the original PDF, arranged in the order of the new object numbers within the subset, and recording the physical offset and status identifier corresponding to each new object number; and performing logical verification on the generated xref table and trailer field.

[0018] Preferably, in step S6, outputting the PDF split files specifically includes: assigning a filename to each split file according to the naming rules set by the user; integrating the recombined object subset with the newly generated xref table, trailer field and header information, writing it to the storage medium via streaming, performing integrity checks on the split files before outputting, and outputting in standard PDF format.

[0019] Preferably, in step S6, all split files can be opened by a standard PDF reader without missing pages, garbled content, or formatting errors; the split files retain the core content and layout of the original PDF, and the visual effect is consistent with the corresponding parts of the original file; the interactive functions of the split files remain effective, clicking links can jump to the corresponding target, and bookmarks can be expanded and positioned normally.

[0020] Preferably, a PDF document splitting system includes an xref table parsing and object location module, an object size calculation module, a target capacity basic grouping module, an object number sorting and reference correction module, a new xref table supporting information generation module, and an integrated output integrity detection module.

[0021] Compared with the prior art, the beneficial effects of the present invention are:

[0022] 1. This invention supports precise splitting of PDF files according to a set byte size, solving obstacles in the storage, uploading, and distribution of large files;

[0023] 2. During the splitting process, this invention operates based on the underlying structure of PDF objects, cross-reference tables, etc., effectively protecting the logical structure and content integrity of the PDF, with no invalid pages or unreadable phenomena;

[0024] 3. This invention further supports a composite mode, which splits the data by both page and capacity, extending its application to electronic document archiving, academic paper distribution, and other applications. Attached Figure Description

[0025] Figure 1 The operation flow of a PDF document splitting method according to the present invention Figure 1 ;

[0026] Figure 2 The operation flow of a PDF document splitting method according to the present invention Figure 2 ;

[0027] Figure 3 This is a schematic diagram of the structure of a PDF document splitting system according to the present invention. Detailed Implementation

[0028] 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 embodiments of the present invention, and not all embodiments. 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.

[0029] Example

[0030] Please see Figures 1-3 As shown, the present invention provides a technical solution comprising the following steps:

[0031] S1. Parse the xref table at the end of the PDF file to obtain all object numbers and their physical file offsets, and establish the correspondence between objects and physical locations;

[0032] S2. Calculate the data range size in bytes for each object based on the physical offset in the xref table. If page splitting is required, identify the page objects and calculate the total size of all direct and indirect objects contained in a single page.

[0033] S3. Based on the target file size set by the user, the size of the objects in bytes is added sequentially, and a preset threshold is used to determine whether the grouping condition is met, and multiple object subsets are formed.

[0034] S4. For each subset of objects, reorganize the numbering of objects within it and the cross-reference relationships between objects, and correct the references across objects.

[0035] S5. Generate a new xref table, trailer field, and necessary header information for the PDF file independently for each subset of objects;

[0036] S6. Integrate the reorganized subset of objects with the newly generated xref table, trailer field, and header information to output multiple structurally complete and independently accessible PDF split files.

[0037] In this embodiment, step S1, parsing the xref table at the end of the PDF file, specifically includes: extracting the starting offset address of the xref table from the trailer field at the end of the PDF file.

[0038] The xref table storage area is located based on the offset address; the segmented structure in the xref table is parsed according to the PDF file format specification, and the starting value of the object number, the number of objects, and the physical file offset of each object in each segment are extracted; the object information of all segments is traversed, and the unique object number of all direct and indirect objects in the PDF file is obtained by summarizing, and the physical offset corresponding to each object number is recorded.

[0039] Specifically, an object information index table is established. The object information index table uses the object number as a unique identifier and stores the corresponding physical offset, object type tag, and initial state tag. The initial state tag is used to distinguish whether the object has been included in subsequent group calculations.

[0040] In this embodiment, S2 specifically includes calculating the data range byte size of each object: for adjacent objects stored consecutively, the physical offset of the object is subtracted from the physical offset of the current object to obtain the data range byte size of the current object; for objects that are not stored consecutively or have cross-references, the termination position of the data range is determined by parsing the end marker of the object, and the difference between the physical offset of the current object and the termination position is calculated as the byte size.

[0041] Specifically, when identifying page objects, the corresponding type identifiers in the PDF file are searched to trace the resource objects, content objects, and annotation objects associated with the page objects. All directly related objects and related objects pointed to through indirect references are included in the page's object set. When calculating the total size of objects on a single page, the data range in bytes of all objects in the page object set is accumulated, and the byte size of objects with duplicate references is excluded to avoid statistical redundancy.

[0042] In this embodiment, step S3, generating an object set by grouping according to the target capacity, specifically includes: the target file size set by the user supports multiple units, and the system automatically converts them into a unified unit for calculation; the preset threshold is user-defined and adjustable, and when the byte size of the accumulated objects reaches a reasonable range of the target file size, the current accumulation is stopped and the formation of the object subset is completed.

[0043] Specifically, during the grouping process, the integrity of page objects is prioritized. If the total size of a page object exceeds the sum of the target file size and the threshold, the page is treated as a separate subset of objects. If the remaining objects do not meet the grouping criteria, they are reasonably selected to be merged into the previous subset of objects or treated as a separate subset of objects based on the ratio of their total size to the target file size, ensuring that no excessively small files are generated after the split.

[0044] In this embodiment, in step S3, the user simultaneously sets the maximum capacity threshold for a single page and the total target file size. First, page object identification and single page size statistics are performed to filter out pages that exceed the maximum capacity threshold for a single page and group them separately. The remaining pages are then grouped according to an accumulation rule to ensure that the total size of each group does not exceed the total target file size, while also ensuring that all objects on the same page belong to the same group.

[0045] Specifically, in the composite splitting mode, the preset threshold is automatically adjusted to a reasonable range. If a group contains multiple pages, a page association tag is added to the new xref table.

[0046] In this embodiment, S4, reorganizing the object numbers and interactive reference relationships specifically includes: for each object subset, reassigning new object numbers according to the storage order of the objects in the subset, with the new object numbers being consecutively arranged starting from the starting sequence number to form an independent object numbering system within the subset.

[0047] Specifically, the process involves traversing the content data of each object within a subset, identifying the object reference markers contained therein, querying the mapping relationship between the original object number and the new object number, and replacing the original object number in the reference marker with the corresponding new object number. For references across object subsets, external reference markers are added and the file identifier of the target subset is recorded to ensure that the references are traceable. A reference correction log is established to record the original references, corrected references, and mapping relationships of each object, which are used for integrity verification of the split files.

[0048] In this embodiment, S5, generating a new xref table, trailer field, and header information specifically includes: the structure of the new xref table is compatible with the xref table format of the original PDF, arranged in the order of new object numbers within the subset, and recording the physical offset and status identifier corresponding to each new object number.

[0049] Specifically, the trailer field contains the starting offset address of the new xref table, the largest object number in the subset, the root object number, and encryption information; the necessary header information for the PDF file includes the file identifier, version information, and cross-reference start marker, and the version information is consistent with the original PDF file to ensure compatibility.

[0050] Logical validation is performed on the generated xref table and trailer field to ensure that the root object number exists and points to a valid directory object, and that the physical offset of all objects is within the storage range of the split file.

[0051] In this embodiment, step S6, outputting the PDF split files, specifically includes: assigning a filename to each split file according to the naming rules set by the user; and integrating the recombined object subset with the newly generated xref table, trailer field, and header information.

[0052] By streaming to the storage medium, memory overflow is avoided. Before output, the split files are checked for integrity, including verifying the validity of object references, the consistency between the xref table and the actual location of the object, and the correctness of the trailer field parameters. Batch output to specified storage paths is supported, and the output format is standard PDF, compatible with mainstream PDF readers.

[0053] In this embodiment, in step S6, all split files can be opened by a standard PDF reader without missing pages, garbled content, or formatting errors; the split files retain the core content and layout of the original PDF, and the visual effect is consistent with the corresponding parts of the original file; the interactive functions of the split files remain effective, clicking links can jump to the corresponding target, and bookmarks can be expanded and located normally; the integrity of the split file content is verified by a verification algorithm to ensure that no data has been tampered with or lost.

[0054] In this embodiment, a PDF document splitting system includes an xref table parsing and object location module, an object size calculation module, a target capacity basic grouping module, an object number sorting and reference correction module, a new xref table supporting information generation module, and an integrated output integrity detection module.

[0055] Working principle: The xref table in the PDF file is the core index that records the physical location of all objects. By first extracting the starting offset address of the xref table from the trailer field at the end of the file, the storage area of ​​the xref table is accurately located. Then, its segmented structure is parsed according to the PDF format specification, and the unique object number and corresponding physical offset of all direct and indirect objects are collected. Finally, an index table with the object number as the unique identifier is established to retain key information such as object type and initial state.

[0056] Based on the acquired physical offset of the objects, differentiated calculation logic is applied to objects in different storage states to determine the data range byte size of each object, avoiding size statistics deviations caused by differences in storage methods. Simultaneously, page objects are locked by identifying specific type identifiers, tracing their associated resources, content, and annotation objects to construct a complete single-page object set. Then, by accumulating the object sizes within the set and excluding duplicate references, the total single-page size is accurately calculated. Using the user-defined target file size as the core benchmark, target sizes in different units are first uniformly converted before calculation. Combined with user-defined preset thresholds, group boundaries are determined by sequentially accumulating object byte sizes. Create object subsets; during grouping, prioritize the integrity of page objects, group pages exceeding the threshold separately, and handle remaining objects that do not meet the grouping criteria proportionally to avoid generating excessively small files; in composite splitting mode, simultaneously combine the maximum capacity threshold for a single page and the total target size, first filter pages exceeding the threshold and group them separately, then group the remaining pages according to rules and add association tags, balancing the independence of a single page with overall size compliance; re-arrange object numbers for each subset, constructing an independent numbering system within the subset to ensure unique object identifiers; identify reference tags by traversing object content, and correct reference pointers based on the mapping relationship between the original and new object numbers to avoid reference invalidation; for Cross-subset references are marked with external identifiers and target file information to ensure traceability. A reference correction log is also established to retain key information before and after correction. A new xref table compatible with the original PDF format is generated for each object subset, recording physical offsets and status identifiers in the order of the new object numbers. A trailer field containing key information such as the xref table start address, maximum object number, and root object number is also generated, along with standard-compliant file header information, maintaining version consistency with the original file to ensure compatibility. Finally, logical checks confirm the validity of the root object and the reasonableness of the object offsets. Each split file is assigned a name according to user-defined naming rules. The system then integrates the recombined subset of objects with the newly generated xref table, trailer field, and header information, and uses a streaming write method to write the data to the storage medium to avoid memory overflow due to excessive data volume. Before output, the system checks the file integrity from multiple dimensions, including the validity of object references, the consistency between the xref table and object locations, and the correctness of trailer field parameters. It supports batch output to specified paths and outputs in standard PDF format to be compatible with mainstream readers. At the same time, it verifies the integrity of the content through a verification algorithm to ensure that the split files can be opened normally, the core content and layout format are preserved in their original state, the interactive functions are effective, and there is no data tampering or loss.

[0057] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their likenesses.

[0058] The present invention and its embodiments have been described above. This description is not restrictive, and the accompanying drawings are only one embodiment of the present invention; the actual structure is not limited thereto. In conclusion, if those skilled in the art are inspired by this description and design similar structures and embodiments without departing from the spirit of the invention, such designs should fall within the protection scope of the present invention.

Claims

1. A method for splitting PDF documents, characterized in that, Includes the following steps: S1. Parse the xref table at the end of the PDF file to obtain all object numbers and their physical file offsets, and establish the correspondence between objects and physical locations; S2. Calculate the data range size in bytes for each object based on the physical offset in the xref table. If page splitting is required, identify the page objects and calculate the total size of all direct and indirect objects contained in a single page. S3. Based on the target file size set by the user, the size of the objects in bytes is added sequentially, and a preset threshold is used to determine whether the grouping condition is met, and multiple object subsets are formed. S4. For each subset of objects, reorganize the numbering of objects within it and the cross-reference relationships between objects, and correct the references across objects. S5. Generate a new xref table, trailer field, and necessary header information for the PDF file independently for each subset of objects; S6. Integrate the reorganized subset of objects with the newly generated xref table, trailer field, and header information to output multiple structurally complete and independently accessible PDF split files.

2. The method for splitting a PDF document according to claim 1, characterized in that: In step S1, parsing the xref table at the end of the PDF file specifically includes: extracting the starting offset address of the xref table from the trailer field at the end of the PDF file, and locating the xref table storage area based on the offset address; parsing the segmented structure in the xref table according to the PDF file format specification, extracting the starting value of the object number, the number of objects, and the physical file offset of each object contained in each segment; traversing the object information of all segments, summarizing to obtain the unique object number of all direct and indirect objects in the PDF file, and recording the physical offset corresponding to each object number; and establishing an object information index table, which uses the object number as a unique identifier and stores the corresponding physical offset, object type tag, and initial state tag.

3. The method for splitting a PDF document according to claim 2, characterized in that: In step S2, calculating the data interval size in bytes for each object specifically includes: for adjacent objects stored contiguously, subtracting the physical offset of the current object from the physical offset of the object to obtain the data interval size in bytes for the current object; for objects not stored contiguously, determining the end position of the data interval by parsing the end marker of the object, and calculating the difference between the physical offset of the current object and the end position as the byte size; When identifying page objects, the resource objects, content objects, and annotation objects associated with the page objects are traced by finding the corresponding type identifiers in the PDF file. When calculating the total size of objects on a single page, the data range in bytes of all objects in the page object set is summed, excluding the byte size of objects that are referenced repeatedly.

4. The method for splitting a PDF document according to claim 3, characterized in that: In S3, generating object sets by grouping according to target capacity specifically includes: the target file size set by the user supports multiple units, and the system automatically converts them into a unified unit for calculation; the preset threshold is user-defined and adjustable, and when the byte size of the accumulated objects reaches a reasonable range of the target file size, the current accumulation is stopped and the object subset is completed; if the total size of a certain page object exceeds the sum of the target file size and the threshold, the page is treated as a separate object subset.

5. The method for splitting a PDF document according to claim 4, characterized in that: In step S3, the user simultaneously sets the maximum capacity threshold for a single page and the total target file size. First, page object identification and single page size statistics are performed to filter out pages that exceed the maximum capacity threshold for a single page and group them separately. The remaining pages are then grouped according to an accumulation rule. In the composite splitting mode, the preset threshold is automatically adjusted to a reasonable range. If a group contains multiple pages, a page association tag is added to the new xref table.

6. The method for splitting a PDF document according to claim 5, characterized in that: In step S4, reorganizing object numbers and cross-reference relationships specifically includes: for each object subset, reassigning new object numbers according to the storage order of objects within the subset, with the new object numbers sequentially arranged starting from the initial sequence number to form an independent object numbering system within the subset; traversing the content data of each object within the subset, identifying the object reference markers contained therein, querying the mapping relationship between the original object number and the new object number, and replacing the original object number in the reference marker with the corresponding new object number; for cross-object subset references, adding external reference markers and recording the file identifier of the target subset; and establishing a reference correction log to record the original reference, corrected reference, and mapping relationship of each object for integrity verification of the split files.

7. The method for splitting a PDF document according to claim 6, characterized in that: In step S5, generating a new xref table, trailer field, and header information specifically includes: the structure of the new xref table is compatible with the xref table format of the original PDF, arranged in the order of the new object numbers within the subset, and recording the physical offset and status identifier corresponding to each new object number; and performing logical verification on the generated xref table and trailer field.

8. The method for splitting a PDF document according to claim 7, characterized in that: In step S6, outputting the PDF split files specifically includes: assigning a filename to each split file according to the naming rules set by the user; integrating the recombined object subset with the newly generated xref table, trailer field and header information, writing it to the storage medium via streaming, performing integrity checks on the split files before output, and outputting the standard PDF format.

9. A method for splitting a PDF document according to claim 8, characterized in that: In S6, all split files can be opened by a standard PDF reader without missing pages or garbled content. The split file retains the core content and layout of the original PDF, and the visual effect is consistent with the corresponding part of the original file; the interactive functions of the split file remain effective, clicking on links will jump to the corresponding target, and bookmarks can be expanded and positioned normally.

10. A system for splitting PDF documents according to the method of claim 9, characterized in that: It includes an xref table parsing and object location module, an object size calculation module, a target capacity basic grouping module, an object number sorting and reference correction module, a new xref table supporting information generation module, and an integrated output integrity detection module.