A method, apparatus, and medium for segmented loading of PDF preview

By cutting the PDF file into small files and using segmented variables and global variables to manage the merge progress, the problem of long wait time during the download and viewing of PDF is solved, achieving more efficient resource utilization and convenient user experience.

CN119167883BActive Publication Date: 2025-05-13GUANGZHOU BAOLUN ELECTRONICS CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411407818.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-10
Publication Date
2025-05-13
Estimated Expiration
2044-10-10

AI Technical Summary

Technical Problem

The prior art is difficult to optimize during the download and viewing of PDF files, resulting in long wait times for users and high requirements for network bandwidth and server performance.

Method used

By cutting the PDF file into multiple small files, each subfile downloads and merges independently, tracking the merge progress with segmented variables and global variables, dynamically merging the subfiles to reduce resource consumption.

Benefits of technology

It effectively reduces user waiting time, improves usage convenience, optimizes resource utilization efficiency, and reduces dependence on network bandwidth and server performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119167883B_ABST
    Figure CN119167883B_ABST
Patent Text Reader

Abstract

The present invention discloses a segmented loading method, device and medium for previewing a PDF, the method comprising: cutting a PDF file into several sub-files to obtain a file list; downloading the sub-files in the file list, and defining the total number of files when the download is completed as a total number variable; assigning values ​​to the current segmentation variable and the global variable based on the downloaded files, merging the sub-files with the file sequence number being a preset value into the displayed PDF, and downloading the next sub-file in the file list until the value obtained by adding the preset value to the global variable is greater than the total number variable, and obtaining the file loading result. The present invention proposes a segmented loading method, device and medium for previewing a PDF, which can reduce the dependence on the integrity of a single large file through segmented downloading and merging, and the system only needs to load the sub-files that need to be merged into the memory at present, without loading all the sub-files at the same time, which can solve the problem of difficulty in optimizing the PDF download and viewing method and reducing the local PDF loading time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a segmented loading method, device and medium for previewing a PDF. Background Art

[0002] In the modern information society, PDF (Portable Document Format) files are widely used in various fields as a generally accepted document standard. PDF files can ensure that the formats of papers, books, research reports and other materials are consistent across different devices and platforms, avoiding layout confusion or content loss caused by format conversion; its unique characteristics and wide compatibility make downloading PDF files an extremely important activity. At present, the main method is to download the complete PDF file to the local mobile terminal for viewing through the PDF online link.

[0003] However, the existing technology is affected by the size of the PDF file. The larger the PDF is, the longer it takes to download the file, and the longer the user has to wait. In addition, the download speed of the PDF file is limited by the bandwidth of its network connection. For users with low bandwidth, even a medium-sized PDF file may take a long time to download. In addition, in addition to the network conditions on the user side, the performance and bandwidth of the server side will also affect the download speed of the file. If the server has limited ability to handle a large number of concurrent requests, the download time of the file will be extended accordingly. Summary of the invention

[0004] The present invention provides a segmented loading method, device and medium for previewing a PDF, so as to solve the problem that it is difficult to optimize the PDF downloading and viewing mode and reduce the local PDF loading time.

[0005] Cut the pdf file into several sub-files and get a file list;

[0006] By previewing the file list according to the file sequence number, downloading the sub-files in the file list, and defining the total number of files when the downloading is completed as a total number variable;

[0007] Based on the downloaded files, assign values ​​to the current segmentation variables and global variables, merge the sub-files whose file numbers are preset values ​​into the displayed PDF, and download the next sub-file in the file list until the value obtained by adding the preset value to the global variable is greater than the total number variable, thereby obtaining the file loading result consisting of the displayed PDF; wherein the current segmentation variable is used to track the total number of segment merges that have been completed, and the global variable is used to track the file number that has been successfully merged.

[0008] The present invention greatly shortens the loading time of each sub-file by cutting the PDF file into multiple small files. The user can download and preview these sub-files one by one without waiting for the entire file to be loaded, which can effectively reduce the waiting time of the user and improve the convenience of use. During the download process, only the sub-files that need to be previewed or merged at present will be downloaded, which reduces unnecessary resource occupation; and the sub-files are dynamically merged according to the user's operation, which avoids loading a large amount of unused data in the memory at the same time, and improves the resource utilization efficiency. The segmentation variable is used to track the total number of segmented mergers that have been completed, which ensures that the system can accurately know which sub-files have been merged into the current displayed PDF; and the global variable is used to track the file sequence number that has been successfully merged, which helps the system decide when to stop the merging process or start downloading the next sub-file; through the precise control of these two variables, the merging order and progress of the sub-files can be efficiently managed.

[0009] Compared with the prior art, the present invention can reduce the reliance on the integrity of a single large file by downloading and merging in segments. In each segment, the system only needs to load the sub-files that currently need to be merged into the memory without loading all sub-files at the same time. Therefore, it can solve the problem of difficulty in optimizing PDF downloading and viewing methods and reduce local PDF loading time.

[0010] As a preferred solution, assign values ​​to the current segmentation variables and global variables, and merge the sub-files with the preset file numbers into the displayed PDF, specifically:

[0011] Merge the files when the download is complete, and control the value of the current segment variable to increase by 1 each time a new segment is merged;

[0012] Merge the sub-file with file number 1 into the displayed PDF, and control the value of the global variable to increase by 1;

[0013] Among them, the initial values ​​of the current segmentation variable and the global variable are 0.

[0014] This preferred solution tracks the status by setting clear variables for different stages of the merge process, so that the progress and status of the current merge operation can be clearly understood. By increasing or decreasing the number of variables or modifying their logic, the merge process can be easily adjusted to adapt to different needs or handle different situations. Moreover, during the merge process, if an error such as insufficient disk space occurs, the values ​​of these variables can be checked to determine the exact point where the merge operation stopped, which helps to diagnose the problem and take appropriate recovery measures.

[0015] As a preferred solution, the next sub-file in the file list is downloaded, specifically:

[0016] If the variable value obtained by adding 1 to the global variable is less than or equal to the value of the total number variable, then check whether there is a first sub-file of the PDF file whose file number is the variable value locally;

[0017] If the first sub-file does not exist, the corresponding first sub-file in the file list is downloaded to the displayed PDF.

[0018] This preferred solution can effectively prevent repeated downloading of the same file by checking whether the value of the global variable plus 1 is less than or equal to the value of the total number variable, and downloading only when the sub-file of the corresponding file number does not exist locally, thereby saving network bandwidth and local storage space. In addition, if the sub-file of a certain file number does not exist locally, the process will immediately trigger the download operation. This immediate response mechanism can ensure that the system can quickly recover and continue to execute subsequent tasks in the event of file loss.

[0019] As a preferred solution, before the value obtained by adding the preset value to the global variable is greater than the total number variable, the method further includes:

[0020] When the preset tail page number of the current sub-file is previewed, the second sub-file whose file serial number is the global variable plus 1 and exists locally in the current PDF is merged into the displayed PDF;

[0021] According to the numerical values ​​of the current segmentation variable and the global variable, the current segmentation variable is assigned a value.

[0022] This preferred solution can ensure that the merging process is closely synchronized with the user's preview behavior by triggering the merging operation when the preview reaches the preset tail page number of the current sub-file; and the merging operation is only performed when needed, rather than continuously during the entire document processing process. This helps to reduce the waste of system resources.

[0023] As a preferred solution, the second sub-file whose file number of the current PDF is the global variable plus 1 and is stored locally is merged into the displayed PDF, specifically:

[0024] Check whether there is a second sub-file of the current PDF locally whose file number is the global variable plus 1;

[0025] If it exists, merging the second sub-file into the displayed PDF;

[0026] If it does not exist, then download the corresponding second sub-file from the file list and record the current browsed page number.

[0027] This preferred solution can avoid repeated downloading of already downloaded files by first checking whether the target sub-file exists locally, and this method can effectively save network bandwidth and time.

[0028] As a preferred solution, the current segmentation variable is assigned a value according to the numerical values ​​of the current segmentation variable and the global variable, specifically:

[0029] After the download of the second sub-file is completed, if the value of the global variable plus 1 is not equal to the value of the current segmentation variable, assigning the global variable to the current segmentation variable;

[0030] If the value of the global variable plus 1 is equal to the value of the current segmentation variable, the downloaded second sub-file is merged into the displayed PDF, and a jump operation is performed according to the current browsed page number.

[0031] In this preferred solution, when the value of the global variable plus 1 is equal to the value of the current segmentation variable, the downloaded file is directly merged into the displayed PDF, and a jump operation is performed according to the current number of pages browsed. This logic reduces unnecessary inspection and processing steps and improves processing efficiency. When performing a jump operation, the user is taken to a location to continue reading based on the current number of pages browsed, which can provide users with a smooth and continuous reading experience and ensure that the process of waiting for file download and merging will not be interrupted.

[0032] As a preferred solution, a jump operation is performed according to the current browsing page number, specifically:

[0033] Use the page jump function of the third-party library to jump to the currently browsed page number before the merge operation, load the PDF file and continue to preview;

[0034] The value of the global variable is controlled to be increased by 1, and the pre-download of the next file sequence number is performed.

[0035] This preferred solution uses the page jump function, so that users can directly return to the browsing position before the merging operation and continue to preview the PDF file without having to re-search the last reading position, which greatly improves the reading efficiency and experience.

[0036] As a preferred solution, the total number of files when downloading is completed is defined as a total number variable, specifically:

[0037] Divide the total number of pages of the file when the download is completed by the preset value, and define the calculated integer as the initial total number variable;

[0038] Taking the remainder of the total number of pages of the file with respect to the preset value, if the calculated remainder is greater than 0, controlling the initial total number variable to increase by 1 to obtain the total number variable;

[0039] If the remainder is less than or equal to 0, the initial total number variable is defined as the total number variable.

[0040] This preferred solution can ensure that the value of the total number variable can be accurately adjusted by checking whether the remainder is greater than 0 when the total number of pages in the file cannot be divided by the preset value. This precise processing method helps to avoid data omissions during the grouping process.

[0041] The present invention also provides a segmented loading device for previewing PDF, comprising a cutting module, a preliminary loading module and a complete loading module;

[0042] The cutting module is used to cut the PDF file into several sub-files to obtain a file list;

[0043] The preliminary loading module is used to preview the file list according to the file sequence number, download the sub-files in the file list, and define the total number of files when the download is completed as a total number variable;

[0044] The complete loading module is used to assign values ​​to the current segmentation variable and the global variable based on the downloaded file, merge the sub-files with the file number as the preset value into the displayed PDF, and download the next sub-file in the file list until the value obtained by adding the preset value to the global variable is greater than the total number variable, thereby obtaining the file loading result consisting of the displayed PDF; wherein the current segmentation variable is used to track the total number of segment mergers that have been completed, and the global variable is used to track the file number that has been successfully merged.

[0045] As a preferred solution, the fully loaded module includes a merging unit and a value unit;

[0046] The merging unit is used to merge the files when the download is completed, and each time a new segment is merged, the value of the current segment variable is controlled to increase by 1;

[0047] The numerical unit is used to merge the sub-file with the file number 1 into the displayed PDF, and control the value of the global variable to be increased by 1;

[0048] Among them, the initial values ​​of the current segmentation variable and the global variable are 0.

[0049] As a preferred solution, the fully loaded module includes a file unit and a display unit;

[0050] The file unit is used to check whether there is a first sub-file of the pdf file whose file number is the variable value locally if the variable value obtained by adding 1 to the global variable is less than or equal to the value of the total number variable;

[0051] The display unit is used to download the first sub-file corresponding to the first sub-file in the file list to the displayed PDF if the first sub-file does not exist.

[0052] As a preferred solution, before the value obtained by adding the preset value to the global variable is greater than the total number variable, the method further includes:

[0053] When the preset tail page number of the current sub-file is previewed, the second sub-file whose file number is the global variable plus 1 and exists locally in the current PDF is merged into the displayed PDF;

[0054] According to the numerical values ​​of the current segmentation variable and the global variable, the current segmentation variable is assigned a value.

[0055] As a preferred solution, the second sub-file whose file number of the current PDF is the global variable plus 1 and stored locally is merged into the displayed PDF, specifically:

[0056] Check whether there is a second sub-file of the current PDF locally whose file number is the global variable plus 1;

[0057] If it exists, merging the second sub-file into the displayed PDF;

[0058] If it does not exist, then download the corresponding second sub-file from the file list and record the current browsed page number.

[0059] As a preferred solution, the current segmentation variable is assigned a value according to the numerical values ​​of the current segmentation variable and the global variable, specifically:

[0060] After the download of the second sub-file is completed, if the value of the global variable plus 1 is not equal to the value of the current segmentation variable, assigning the global variable to the current segmentation variable;

[0061] If the value of the global variable plus 1 is equal to the value of the current segmentation variable, the downloaded second sub-file is merged into the displayed PDF, and a jump operation is performed according to the current browsed page number.

[0062] As a preferred solution, a jump operation is performed according to the current browsing page number, specifically:

[0063] Use the page jump function of the third-party library to jump to the currently browsed page number before the merge operation, load the PDF file and continue to preview;

[0064] The value of the global variable is controlled to be increased by 1, and the pre-download of the next file sequence number is performed.

[0065] As a preferred solution, the preliminary loading module includes an integer unit, a remainder unit and a variable unit;

[0066] The integer unit is used to divide the total number of pages of the file when the download is completed by a preset value, and define the integer obtained by the calculation as the initial total number variable;

[0067] The remainder unit is used to calculate the remainder of the total number of pages of the file with respect to the preset value, and if the calculated remainder is greater than 0, control the initial total number variable to add 1 to obtain the total number variable;

[0068] The variable unit is used to define the initial total number variable as the total number variable if the remainder is less than or equal to 0.

[0069] The present application also provides a storage medium, on which a computer program is stored. The computer program is called and executed by a computer to implement the segmented loading method for previewing a PDF as described above. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] Figure 1 It is a flowchart of a segmented loading method for previewing a PDF provided in an embodiment of the present application;

[0071] Figure 2 It is a structural schematic diagram of a segmented loading device for previewing PDF provided in an embodiment of the present application. DETAILED DESCRIPTION

[0072] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0073] In the description of the present application, it should be understood that the terms "first", "second" and "third" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first", "second" and "third" may explicitly or implicitly include one or more of the features. In the description of the present application, unless otherwise specified, "several" means two or more.

[0074] The embodiment of the present application provides a segmented loading method for previewing a PDF, which is mainly used in situations where it is necessary to optimize the PDF downloading and viewing method to reduce the waiting time for users to view the PDF, and to download PDF sub-files in segments, thereby reducing the storage space occupied by the local cache.

[0075] Embodiment 1:

[0076] See also Figure 1The embodiment of the present application provides a segmented loading method for previewing a PDF, including S1 to S3, and the specific implementation steps are as follows:

[0077] S1. Cut the pdf file into several sub-files and get a file list.

[0078] Step S1 of the embodiment of the present application is specifically as follows:

[0079] The control server cuts the PDF file at every 50 pages as the critical point, and obtains a file list consisting of several sub-files;

[0080] A rule of "name followed by file number.pdf" is established for sub-files in the file list for mobile terminals to download PDF files; wherein, the file numbers of sub-files in the file list start from 1 by default.

[0081] S2. Preview the file list according to the file sequence number, download the sub-files in the file list, and define the total number of files when the download is completed as a total number variable.

[0082] Step S2 of the embodiment of the present application includes S2.1 to S2.2, specifically:

[0083] S2.1, control the mobile terminal to obtain the file list of the PDF file by requesting the server, so as to obtain the total number of pages of the PDF file;

[0084] By clicking on the PDF file to preview it, the initial sub-file with the PDF file number 1 is downloaded; at the same time, the position value of the sub-file in the file list needs to be recorded.

[0085] S2.2, after the initial sub-file is downloaded, the corresponding PDF file is opened by the position value;

[0086] Divide the total number of pages of the file when the download is completed by 50 to get the number of files with 50 complete pages. Define the number of files with 50 complete pages as the initial total number variable fileNum;

[0087] Take the remainder of the total number of pages in the file with respect to 50. If the calculated remainder is greater than 0, then control the initial total number variable plus 1, that is, set fileNum = fileNum + 1, and get the total number variable;

[0088] If the remainder is less than or equal to 0, the initial total number variable fileNum is defined as the total number variable.

[0089] In this embodiment S2.2, by checking whether the remainder is greater than 0, it can ensure that when the total number of pages in the file cannot be divided by the preset value, the value of the total number variable can be accurately adjusted. This precise processing method helps to avoid data omissions during the grouping process.

[0090] S3. Based on the downloaded file, assign values ​​to the current segmentation variable and the global variable, merge the sub-files whose file numbers are preset values ​​into the displayed PDF, and download the next sub-file in the file list until the value obtained by adding the preset value to the global variable is greater than the total number variable, and obtain the file loading result consisting of the displayed PDF; wherein the current segmentation variable is used to track the total number of segment merges that have been completed, and the global variable is used to track the file number that has been successfully merged.

[0091] Step S3 of the embodiment of the present application includes S3.1 to S3.5, specifically:

[0092] S3.1. Merge the files when downloading is complete. Whenever a new segment is merged, control the value of the current segment variable to increase by 1, i.e., set currentSplitIndex=currentSplitIndex+1.

[0093] Merge the sub-file with file number 1 into the newly created display PDF, and control the value of the global variable to increase by 1, that is, set currentMergeNumber = currentMergeNumber + 1;

[0094] Among them, the initial values ​​of the current segmentation variable currentSplitIndex and the global variable currentMergeNumber are both 0. The current segmentation variable currentSplitIndex is used to track the total number of segment mergers that have been completed, and the global variable currentMergeNumber is used to track the file number that has been successfully merged.

[0095] S3.2. After assigning a value to currentMergeNumber, perform a pre-download operation for the next sub-file; wherein the file number of the next sub-file is currentMergeNumber+1;

[0096] If the variable value obtained by adding 1 to the global variable (currentMergeNumber+1) is less than or equal to the value of the total number variable fileNum, then check whether there is a first subfile of the pdf file with the file number of the variable value locally;

[0097] If the first sub-file does not exist, the corresponding first sub-file in the file list is downloaded to the displayed PDF; if the first sub-file exists, no processing is performed.

[0098] In this embodiment S3.2, by checking whether the value of the global variable plus 1 is less than or equal to the value of the total number variable, and downloading only when the sub-file of the corresponding file number does not exist locally, it can effectively prevent repeated downloading of the same file, thereby saving network bandwidth and local storage space. In addition, if the sub-file of a certain file number does not exist locally, the process will immediately trigger the download operation. This immediate response mechanism can ensure that in the case of file loss, the system can quickly recover and continue to execute subsequent tasks.

[0099] S3.3, when the user operation is detected to slide to the last five pages of the currently displayed sub-file, check whether there is a second sub-file of the current PDF whose file number is the global variable plus 1 (currentMergeNumber+1) locally;

[0100] If it exists, merge the second subfile into the displayed PDF;

[0101] If it does not exist, the corresponding second sub-file is downloaded from the file list, and the current browsing page number page is recorded for automatically jumping to the current browsing page number page after merging the next sub-file.

[0102] In this embodiment S3.3, by first checking whether the target sub-file exists locally, it is possible to avoid repeated downloading of the downloaded file, which can effectively save network bandwidth and time;

[0103] Furthermore, by triggering the merge operation when the preview reaches the preset end page number of the current sub-file, the merge process can be closely synchronized with the user's preview behavior; and the merge operation is only performed when needed, rather than continuously during the entire document processing process. This helps to reduce the waste of system resources.

[0104] S3.4. After the second sub-file is downloaded, if the value of the global variable plus 1 (currentMergeNumber+1) is not equal to the value of the current segmentation variable currentSplitIndex, it means that the merge operation has been performed or the value of the file index number currentFileIndex currently being processed is wrong. It is necessary to assign the global variable currentMergeNumber to the current segmentation variable currentSplitIndex; and use the return statement to terminate the execution of the function in advance to ensure the correct sequence number of the next sub-file;

[0105] If the value of the global variable plus 1 (currentMergeNumber+1) is equal to the value of the current segmentation variable currentSplitIndex, the downloaded second sub-file will be merged into the displayed PDF.

[0106] Use the page jump function of the third-party library to jump to the currently browsed page before the merge operation, load the PDF file and continue previewing;

[0107] The value of the control global variable is increased by 1, that is, currentMergeNumber=currentMergeNumber+1, and the pre-download of the next file number is performed.

[0108] The page number of the currently displayed sub-file is continuously monitored, and each time the page is slid to the last five pages of the displayed sub-file, steps S3.3-S3.4 are repeated.

[0109] In this embodiment S3.4, when the value of the global variable plus 1 is equal to the value of the current segmentation variable, the downloaded file is directly merged into the displayed PDF, and a jump operation is performed according to the current number of pages browsed. Through the page jump function, the user can directly return to the browsing position before the merge operation and continue to preview the PDF file without having to find the last reading position again, which greatly improves the reading efficiency and experience. This logic reduces unnecessary inspection and processing steps and improves processing efficiency. When performing a jump operation, the user is determined to which position to continue reading according to the current number of pages browsed, which can provide users with a smooth and continuous reading experience and ensure that the process of waiting for file downloads and merging will not be interrupted.

[0110] S3.5. If the value obtained by adding 1 to the global variable (currentMergeNumber+1) is greater than the total number variable fileNum, it means that all PDF files have been loaded, and the file loading result consisting of displayed PDF is obtained;

[0111] After finishing viewing, traverse all sub-files and displayed PDF files in the download path, perform deletion operations, and release memory usage.

[0112] In this embodiment S3, by setting clear variables to track the status at different stages of the merge process, the progress and status of the current merge operation can be clearly understood. By increasing or decreasing the number of variables or modifying their logic, the merge process can be easily adjusted to adapt to different needs or handle different situations. In addition, during the merge process, if an error such as insufficient disk space occurs, the values ​​of these variables can be checked to determine the exact location where the merge operation stopped, which helps to diagnose the problem and take appropriate recovery measures.

[0113] Overall, this embodiment has the following beneficial effects:

[0114] The present invention greatly shortens the loading time of each sub-file by cutting the PDF file into multiple small files. The user can download and preview these sub-files one by one without waiting for the entire file to be loaded, which can effectively reduce the waiting time of the user and improve the convenience of use. During the download process, only the sub-files that need to be previewed or merged at present will be downloaded, which reduces unnecessary resource occupation; and the sub-files are dynamically merged according to the user's operation, which avoids loading a large amount of unused data in the memory at the same time, and improves the resource utilization efficiency. The segmentation variable is used to track the total number of segmented mergers that have been completed, which ensures that the system can accurately know which sub-files have been merged into the current displayed PDF; and the global variable is used to track the file sequence number that has been successfully merged, which helps the system decide when to stop the merging process or start downloading the next sub-file; through the precise control of these two variables, the merging order and progress of the sub-files can be efficiently managed.

[0115] In addition, the present invention optimizes the local PDF loading mode, divides the waiting time for loading into segments, speeds up the loading and previewing of the PDF, and pre-downloads the second sub-file while the user is previewing. As a whole, it only needs to wait for the downloading time of the first sub-file. The storage space occupied by the local PDF changes with the increase in the number of preview pages. It will not occupy the storage space of the entire complete PDF until all sub-files are viewed, which can effectively reduce the storage space occupied. In addition, each processed sub-file is relatively small, and this processing method speeds up the file processing speed and improves the practical performance of the present solution.

[0116] Embodiment 2:

[0117] See also Figure 2 , an embodiment of the present application provides a segmented loading device for previewing a PDF, comprising a cutting module 10, a preliminary loading module 20 and a complete loading module 30;

[0118] The cutting module 10 is used to cut the PDF file into several sub-files to obtain a file list;

[0119] A preliminary loading module 20 is used to preview the file list according to the file sequence number, download the sub-files in the file list, and define the total number of files when the download is completed as a total number variable;

[0120] The complete loading module 30 is used to assign values ​​to the current segmentation variable and the global variable based on the downloaded file, merge the sub-files with the file number as the preset value into the displayed PDF, and download the next sub-file in the file list until the value obtained by adding the preset value to the global variable is greater than the total number variable, and obtain the file loading result consisting of the displayed PDF; wherein the current segmentation variable is used to track the total number of segment merges that have been completed, and the global variable is used to track the file number that has been successfully merged.

[0121] In one embodiment, the cutting module 10 is specifically:

[0122] The control server cuts the PDF file at every 50 pages as the critical point, and obtains a file list consisting of several sub-files;

[0123] A rule of "name followed by file number.pdf" is established for sub-files in the file list for mobile terminals to download PDF files; wherein, the file numbers of sub-files in the file list start from 1 by default.

[0124] In one embodiment, the preliminary loading module 20 includes a download unit, an integer unit, a remainder unit, and a variable unit;

[0125] The download unit is used to control the mobile terminal to obtain the file list of the PDF file by requesting the server, so as to obtain the total number of pages of the PDF file;

[0126] The download unit is also used to download the initial sub-file of the PDF file with the serial number 1 by clicking on the PDF file for preview; at the same time, the position value of the sub-file in the file list needs to be recorded.

[0127] Integer unit, used to open the corresponding PDF file by position value after the initial sub-file is downloaded;

[0128] The integer unit is also used to divide the total number of pages of the file when the download is completed by 50 to obtain the number of files with 50 complete pages, and define the number of files with 50 complete pages as the initial total number variable fileNum;

[0129] The remainder unit is used to obtain the remainder of the total number of pages of the file to 50. If the calculated remainder is greater than 0, the initial total number variable is controlled to be increased by 1, that is, fileNum=fileNum+1, to obtain the total number variable;

[0130] The variable unit is used to define the initial total number variable fileNum as the total number variable if the remainder is less than or equal to 0.

[0131] In this embodiment, the integer unit, remainder unit and variable unit can ensure that the value of the total number variable can be accurately adjusted when the total number of pages in the file cannot be divided by the preset value by checking whether the remainder is greater than 0. This precise processing method helps to avoid data omissions during the grouping process.

[0132] In one embodiment, the full load module 30 includes a merging unit, a value unit, a file unit, a display unit, a sliding unit, an assignment unit, and a result unit;

[0133] The merging unit is used to merge the files when the download is completed. Whenever a new segment is merged, the value of the current segment variable is controlled to increase by 1, that is, currentSplitIndex=currentSplitIndex+1;

[0134] The numerical unit is used to merge the sub-file with file number 1 into the newly created display PDF, and control the value of the global variable to add 1, that is, currentMergeNumber = currentMergeNumber + 1;

[0135] Among them, the initial values ​​of the current segmentation variable currentSplitIndex and the global variable currentMergeNumber are both 0. The current segmentation variable currentSplitIndex is used to track the total number of segment mergers that have been completed, and the global variable currentMergeNumber is used to track the file number that has been successfully merged.

[0136] The file unit is used to perform the pre-download operation of the next sub-file after assigning a value to currentMergeNumber; wherein the file number of the next sub-file is currentMergeNumber+1;

[0137] The file unit is also used to check whether there is a first subfile of the pdf file whose file number is the variable value locally if the variable value obtained after adding 1 to the global variable (currentMergeNumber+1) is less than or equal to the value of the total number variable fileNum;

[0138] The display unit is used to download the corresponding first sub-file in the file list to the displayed PDF if the first sub-file does not exist; if the first sub-file exists, no processing is performed.

[0139] In this embodiment, the file unit and the display unit check whether the value of the global variable plus 1 is less than or equal to the value of the total number variable, and download only when the sub-file of the corresponding file number does not exist locally, which can effectively prevent repeated downloading of the same file, thereby saving network bandwidth and local storage space. In addition, if the sub-file of a certain file number does not exist locally, the process will immediately trigger the download operation. This immediate response mechanism can ensure that in the case of file loss, the system can quickly recover and continue to execute subsequent tasks.

[0140] The sliding unit is used to check whether there is a second sub-file of the current PDF whose file number is the global variable plus 1 (currentMergeNumber+1) locally when the user operation slides to the last five pages of the currently displayed sub-file;

[0141] The sliding unit is further used to merge the second sub-file into the displayed PDF if it exists;

[0142] The sliding unit is also used to download the corresponding second sub-file from the file list if it does not exist, record the current browsing page number page, and automatically jump to the current browsing page number page after merging the next sub-file.

[0143] In this embodiment, the sliding unit can avoid repeated downloading of the downloaded file by first checking whether the target sub-file exists locally, which can effectively save network bandwidth and time;

[0144] Furthermore, by triggering the merge operation when the preview reaches the preset end page number of the current sub-file, the merge process can be closely synchronized with the user's preview behavior; and the merge operation is only performed when needed, rather than continuously during the entire document processing process. This helps to reduce the waste of system resources.

[0145] The assignment unit is used to assign the global variable currentMergeNumber to the current segmentation variable currentSplitIndex after the second sub-file is downloaded. If the value of the global variable plus 1 (currentMergeNumber+1) is not equal to the value of the current segmentation variable currentSplitIndex, it means that the merge operation has been performed or the value of the file index number currentFileIndex currently being processed is wrong. The global variable currentMergeNumber needs to be assigned to the current segmentation variable currentSplitIndex; and the return statement is used to terminate the execution of the function in advance to ensure the correctness of the next sub-file sequence number;

[0146] The assignment unit is also used to merge the downloaded second sub-file into the displayed PDF if the value of the global variable plus 1 (currentMergeNumber+1) is equal to the value of the current segmentation variable currentSplitIndex.

[0147] The assignment unit is also used to use the page jump function of the third-party library to jump to the current browsing page number before the merge operation, and load the PDF file to continue previewing;

[0148] The assignment unit is also used to control the value of the global variable to add 1, that is, to set currentMergeNumber=currentMergeNumber+1, and to perform pre-download of the next file number.

[0149] The assignment unit is also used to continuously monitor the page number of the currently displayed sub-file, and whenever the page number of the last five pages of the displayed sub-file is slid to, the sliding unit and the assignment unit are repeatedly executed.

[0150] In the assignment unit of this embodiment, when the value of the global variable plus 1 is equal to the value of the current segmentation variable, the downloaded file is directly merged into the displayed PDF, and a jump operation is performed according to the current number of pages browsed. Through the page jump function, the user can directly return to the browsing position before the merge operation and continue to preview the PDF file without having to find the last reading position again, which greatly improves the reading efficiency and experience. This logic reduces unnecessary inspection and processing steps and improves processing efficiency. When performing a jump operation, the user is determined to which position to continue reading according to the current number of pages browsed, which can provide users with a smooth and continuous reading experience and ensure that the process of waiting for file downloads and merging will not be interrupted.

[0151] The result unit is used to obtain the file loading result consisting of the displayed PDF file if the value obtained by adding 1 to the global variable (currentMergeNumber+1) is greater than the total number variable fileNum, indicating that all PDF files have been loaded;

[0152] The result unit is also used to traverse all sub-files and displayed PDF files in the download path after the viewing is completed, perform deletion operations, and release memory usage.

[0153] The full loading module 30 of this embodiment tracks the status by setting clear variables for different stages of the merge process, so that the progress and status of the current merge operation can be clearly understood. By increasing or decreasing the number of variables or modifying their logic, the merge process can be easily adjusted to adapt to different needs or handle different situations. In addition, during the merge process, if an error such as insufficient disk space occurs, the values ​​of these variables can be checked to determine the exact location where the merge operation stopped, which helps to diagnose the problem and take appropriate recovery measures.

[0154] Overall, this embodiment has the following beneficial effects:

[0155] The present invention greatly shortens the loading time of each sub-file by cutting the PDF file into multiple small files. The user can download and preview these sub-files one by one without waiting for the entire file to be loaded, which can effectively reduce the waiting time of the user and improve the convenience of use. During the download process, only the sub-files that need to be previewed or merged at present will be downloaded, which reduces unnecessary resource occupation; and the sub-files are dynamically merged according to the user's operation, which avoids loading a large amount of unused data in the memory at the same time, and improves the resource utilization efficiency. The segmentation variable is used to track the total number of segmented mergers that have been completed, which ensures that the system can accurately know which sub-files have been merged into the current displayed PDF; and the global variable is used to track the file sequence number that has been successfully merged, which helps the system decide when to stop the merging process or start downloading the next sub-file; through the precise control of these two variables, the merging order and progress of the sub-files can be efficiently managed.

[0156] In addition, the present invention optimizes the local PDF loading mode, divides the waiting time for loading into segments, speeds up the loading and previewing of the PDF, and pre-downloads the second sub-file while the user is previewing. As a whole, it only needs to wait for the downloading time of the first sub-file. The storage space occupied by the local PDF changes with the increase in the number of preview pages. It will not occupy the storage space of the entire complete PDF until all sub-files are viewed, which can effectively reduce the storage space occupied. In addition, each processed sub-file is relatively small, and this processing method speeds up the file processing speed and improves the practical performance of the present solution.

[0157] Embodiment three:

[0158] The embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the segmented loading method of the preview PDF;

[0159] Wherein, the segmented loading method for previewing PDF, if implemented in the form of a software functional unit and used as an independent product, can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc.

[0160] The above are preferred embodiments of the present invention. It should be noted that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.

Claims

1. A segmented loading method for previewing a PDF, characterized in that: include: Cut the pdf file into several sub-files and get a file list; By previewing the file list according to the file sequence number, downloading the sub-files in the file list, and defining the total number of files when the downloading is completed as a total number variable; Based on the downloaded file, assign values ​​to the current segmentation variable and the global variable, merge the subfiles whose file numbers are preset values ​​into the displayed PDF, and download the next subfile in the file list until the value obtained by adding the preset value to the global variable is greater than the total number variable, and obtain the file loading result consisting of the displayed PDF; wherein the current segmentation variable is used to track the total number of segment merges that have been completed, and the global variable is used to track the file number that has been successfully merged; Among them, based on the downloaded file, assign values ​​to the current segmentation variables and global variables, merge the sub-files with the preset file numbers into the displayed PDF, specifically: Merge the files when the download is complete, and control the value of the current segment variable to increase by 1 each time a new segment is merged; Merge the sub-file with file number 1 into the displayed PDF, and control the value of the global variable to increase by 1; Among them, the initial values ​​of the current segmentation variable and the global variable are 0.

2. A segmented loading method for previewing a PDF as claimed in claim 1, characterized in that: And download the next sub-file in the file list, specifically: If the variable value obtained by adding 1 to the global variable is less than or equal to the value of the total number variable, then check whether there is a first sub-file of the PDF file whose file number is the variable value locally; If the first sub-file does not exist, the corresponding first sub-file in the file list is downloaded to the displayed PDF.

3. A segmented loading method for previewing a PDF as claimed in claim 1, characterized in that: Before the value obtained by adding the preset value to the global variable is greater than the total number variable, the method further includes: When the preset tail page number of the current sub-file is previewed, the second sub-file whose file number is the global variable plus 1 and exists locally in the current PDF is merged into the displayed PDF; According to the numerical values ​​of the current segmentation variable and the global variable, the current segmentation variable is assigned a value.

4. A segmented loading method for previewing a PDF as claimed in claim 3, characterized in that: The second sub-file whose file number of the current PDF is the global variable plus 1 and exists locally is merged into the displayed PDF, specifically: Check whether there is a second sub-file of the current PDF locally whose file serial number is the global variable plus 1; If it exists, merging the second sub-file into the displayed PDF; If it does not exist, then download the corresponding second sub-file from the file list and record the current browsed page number.

5. A segmented loading method for previewing a PDF as claimed in claim 4, characterized in that: The current segmentation variable is assigned a value according to the numerical values ​​of the current segmentation variable and the global variable, specifically: After the download of the second sub-file is completed, if the value of the global variable plus 1 is not equal to the value of the current segmentation variable, assigning the global variable to the current segmentation variable; If the value of the global variable plus 1 is equal to the value of the current segmentation variable, the downloaded second sub-file is merged into the displayed PDF, and a jump operation is performed according to the current browsed page number.

6. A segmented loading method for previewing a PDF as claimed in claim 5, characterized in that: The jump operation is performed according to the current browsing page number, specifically: Use the page jump function of the third-party library to jump to the currently browsed page number before the merge operation, load the PDF file and continue to preview; The value of the global variable is controlled to be increased by 1, and the pre-download of the next file sequence number is performed.

7. A segmented loading method for previewing a PDF as claimed in claim 1, characterized in that: The total number of files when downloading is complete is defined as the total number variable, specifically: Divide the total number of pages of the file when the download is completed by the preset value, and define the calculated integer as the initial total number variable; Taking the remainder of the total number of pages of the file with respect to the preset value, if the calculated remainder is greater than 0, controlling the initial total number variable to increase by 1 to obtain the total number variable; If the remainder is less than or equal to 0, the initial total number variable is defined as the total number variable.

8. A segmented loading device for previewing PDF, characterized in that: It includes cutting module, preliminary loading module and full loading module; The cutting module is used to cut the PDF file into several sub-files to obtain a file list; The preliminary loading module is used to preview the file list according to the file sequence number, download the sub-files in the file list, and define the total number of files when the download is completed as a total number variable; The complete loading module is used to assign values ​​to the current segmentation variable and the global variable based on the downloaded file, merge the sub-files with the file number being the preset value into the displayed PDF, and download the next sub-file in the file list until the value obtained by adding the preset value to the global variable is greater than the total number variable, thereby obtaining the file loading result consisting of the displayed PDF; wherein the current segmentation variable is used to track the total number of segment merges that have been completed, and the global variable is used to track the file number that has been successfully merged; Among them, based on the downloaded file, assign values ​​to the current segmentation variables and global variables, merge the sub-files with the preset file numbers into the displayed PDF, specifically: Merge the files when the download is complete, and control the value of the current segment variable to increase by 1 each time a new segment is merged; Merge the sub-file with file number 1 into the displayed PDF, and control the value of the global variable to increase by 1; Among them, the initial values ​​of the current segmentation variable and the global variable are 0.

9. A storage medium, characterized in that: The storage medium stores a computer program, which is called and executed by a computer to implement a segmented loading method for previewing a PDF as described in any one of claims 1 to 7 above.

Citation Information

Patent Citations

  • Method and system for previewing large file and storage medium

    CN115828847A