Document format conversion method and device, computer device and storage medium
By obtaining the header information of the PDF document to determine the number of segments, and using multiple subprocesses to process the segments in parallel, the problem of low efficiency in converting PDF documents to images is solved, and a faster conversion speed is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-15
- Publication Date
- 2026-03-17
AI Technical Summary
Existing technologies for converting PDF documents to images are inefficient, mainly because PDF documents have large data volumes, and single-process conversion takes too long.
By obtaining the header information of the PDF document, the optimal number of segments is determined, and a corresponding number of subprocesses are created. The document is segmented and distributed to the subprocesses for parallel conversion. Multiple subprocesses are used to independently and in parallel process the segments to generate images.
It improves the efficiency of converting PDF documents into images by reducing conversion time and increasing processing speed through parallel processing.
Smart Images

Figure CN114764559B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and more particularly to a method, apparatus, computer device, and storage medium for document format conversion. Background Technology
[0002] Electronic contracts are usually in Portable Document Form (PDF) format. However, in some applications, such as when a PDF electronic contract needs to be referenced in other documents, it is necessary to convert the PDF to an image format.
[0003] In current technology, converting PDF documents to images takes a considerable amount of time. This is because PDF documents are becoming increasingly large in size, and the conversion process is typically a single-process conversion, resulting in excessively long conversion times.
[0004] It is evident that existing methods for converting PDF documents into images are inefficient. Summary of the Invention
[0005] In order to solve the above-mentioned technical problems, or at least partially solve the above-mentioned technical problems, this application provides a document format conversion method, apparatus, computer equipment and storage medium.
[0006] Firstly, a document format conversion method is provided, applied to the main process, the method comprising:
[0007] Obtain the file header information of the portable document format document, wherein the file header information of the portable document format document includes the data size of the portable document format document;
[0008] Based on the file header information of the portable document format document, obtain the optimal number of first fragments;
[0009] Create a subprocess with the same number of the optimal first fragments;
[0010] The portable document format document is divided into multiple first fragments according to the optimal number of first fragments;
[0011] Each of the first segments is sent to one of the sub-processes, and the sub-processes convert the first segments into a first image;
[0012] Receive the first image;
[0013] Based on the first image, generate an image corresponding to the portable document format document.
[0014] In this embodiment of the application, the step of converting the first slice into the first image through a subprocess includes:
[0015] The subprocess determines whether the first fragment needs to be fragmented based on the file header information of the first fragment, where the file header information of the first fragment includes the data size of the first fragment.
[0016] If the first slice does not need to be fragmented, the first slice is sent to a sub-thread, and the sub-thread converts the first slice into the first image.
[0017] In this embodiment of the application, the step of converting the first slice into the first image through a subprocess further includes:
[0018] If the first fragment needs to be fragmented, then the optimal number of second fragments is obtained based on the file header information of the first fragment;
[0019] The first partition is divided into multiple second partitions by the subprocess according to the optimal number of second partitions;
[0020] Obtain child threads from the thread pool that are the same number as the optimal second shard;
[0021] Each of the second slices is sent to a sub-thread by the sub-process, so that the sub-thread can convert the second slices into a second image;
[0022] The second image is received through the subprocess;
[0023] The subprocess generates the first image based on the second image.
[0024] In this embodiment of the application, before obtaining the file header information of the portable document format document, the method further includes:
[0025] Receive parameters and file stream;
[0026] Obtain the portable document format document from the file stream;
[0027] Obtain the image save path parameter and image naming parameter from the parameters.
[0028] In this embodiment of the application, after obtaining the image save path parameter and image naming parameter from the parameters, and before generating the image corresponding to the portable document format document, the method further includes:
[0029] Obtain the local directory based on the image save path parameters, and create a local folder in the local directory;
[0030] After generating the image corresponding to the portable document format document, the method further includes:
[0031] The images corresponding to the portable document format document are named according to the image naming parameters and stored in the local folder.
[0032] In this embodiment of the application, the conversion of the second slice into the second image by multiple sub-threads is independent of each other.
[0033] In this embodiment of the application, the main process is deployed on a host;
[0034] The main process, the child processes acquired by the main process, and the child threads acquired by the child processes are all deployed on the same host.
[0035] In this embodiment of the application, the main process, the child process obtained by the main process, and the sub-thread obtained by the child process are deployed on the conversion service module on the host.
[0036] The local folder is deployed on a host with the same main process and in the application system on that host.
[0037] Secondly, a portable document format conversion device is provided, the device comprising:
[0038] The header parsing unit is used to obtain the header information of the portable document format document, wherein the header information of the portable document format document includes the data size of the portable document format document;
[0039] The first determining unit is used to obtain the optimal number of first segments based on the file header information of the portable document format document;
[0040] A subprocess creation unit is used to create subprocesses with the same number of the optimal first partitions;
[0041] The first segmentation unit is used to segment the portable document format document into multiple first segments according to the optimal number of first segments;
[0042] A sending unit is configured to send each of the first segments to a subprocess, through which the subprocess converts the first segments into a first image;
[0043] A receiving unit is configured to receive the first image;
[0044] The image generation unit is used to generate an image corresponding to the portable document format document based on the first image.
[0045] Thirdly, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor performs the steps of any of the methods described above.
[0046] Fourthly, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described above.
[0047] This application relates to a document format conversion method applied to a main process. The method includes: obtaining the header information of a portable document format (PVM) document, wherein the header information includes the data size of the PVM document; obtaining an optimal number of first fragments based on the header information; creating a subprocess with the same number of first fragments; dividing the PVM document into multiple first fragments according to the optimal number of first fragments; sending each first fragment to one of the subprocesses, whereby the subprocesses convert the first fragments into a first image; receiving the first image; and generating an image corresponding to the PVM document based on the first image. In this embodiment, the PVM document can be distributed to multiple subprocesses for image conversion. Since the subprocesses operate independently and can be executed in parallel, the method of this embodiment is highly efficient. Attached Figure Description
[0048] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0049] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0050] Figure 1 This is a diagram illustrating the application environment of the document format conversion method in the embodiments of this application;
[0051] Figure 2 This is a flowchart illustrating the document format conversion method in an embodiment of this application;
[0052] Figure 3 This is a schematic diagram of the application environment in the embodiments of this application;
[0053] Figure 4 This is a flowchart illustrating the document format conversion method in an embodiment of this application;
[0054] Figure 5 This is a structural block diagram of the document format conversion device in the embodiments of this application;
[0055] Figure 6 This is a structural block diagram of the document format conversion device in the embodiments of this application;
[0056] Figure 7 The diagram shown is an application scenario illustration of the document format conversion method according to an embodiment of this application;
[0057] Figure 8 This is a diagram showing the internal structure of a computer device in an embodiment of this application. Detailed Implementation
[0058] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0059] Figure 1 This is a diagram illustrating the application environment of a document format conversion method in one embodiment. (Refer to...) Figure 1 This document format conversion method is applied to a document format conversion system. The document format conversion system includes a terminal 110 and a server 120. The terminal 110 and server 120 are connected via a network. The terminal 110, which may also be referred to as a host in this application, can be a desktop terminal or a mobile terminal; a mobile terminal can be at least one of a mobile phone, tablet computer, or laptop computer. The server 120 can be implemented using a standalone server or a server cluster composed of multiple servers; in this application, the server 120 can be a deployment server.
[0060] For the sake of brevity, portable document format documents will be referred to as PDF documents in this article.
[0061] like Figure 2 As shown, in one embodiment, a document format conversion method is provided. This embodiment mainly applies this method to the above-mentioned... Figure 1 Let's take terminal 110 as an example. (Refer to...) Figure 2 This document format conversion method is applied to the main process and includes the following steps:
[0062] Step 210: Obtain the file header information of the document, wherein the file header information of the PDF document includes the data size of the PDF document;
[0063] Step 220: Obtain the optimal number of first segments based on the file header information of the PDF document;
[0064] Step 230: Create a subprocess with the same number of the optimal first shards;
[0065] In this embodiment of the application, creating a child process can also be considered as calling an existing child process in the system.
[0066] Step 240: Divide the PDF document into multiple first fragments according to the optimal number of first fragments;
[0067] Step 250: Send each of the first segments to one of the subprocesses, and convert the first segments into a first image through the subprocesses;
[0068] Step 260: Receive the first image;
[0069] Step 270: Generate the image corresponding to the PDF document based on the first image.
[0070] In this embodiment, the optimal number of first fragments is determined based on the data size of the PDF document and the resources of the host running the main process. If the data size of the PDF document is large, a larger number of first fragments is required. If the host has abundant resources, a larger number of first fragments can also be used.
[0071] In this embodiment, the number of first shards can also be determined based on the range of the first data volume and the threshold of the first shard, such as a maximum of ten shards, or the data volume of each first shard being between A and B. When sharding, the data volume of each shard is usually the same or approximately the same.
[0072] In this embodiment, the optimal number of first segments can be obtained based on the header information of the PDF document. The PDF document is then segmented according to this optimal number of first segments. Sub-processes with the same number of first segments are created to convert the first segments into first images. Finally, the first images are used to generate the image corresponding to the required PDF document. In this embodiment, the PDF document can be distributed to multiple sub-processes for image conversion. Since the sub-processes operate independently and in parallel, the method in this embodiment is highly efficient.
[0073] In this embodiment of the application, before step 210, i.e., before obtaining the header information of the PDF document, the method further includes:
[0074] Receive parameters and file stream;
[0075] Obtain the PDF document from the file stream;
[0076] Obtain the image save path parameter and image naming parameter from the parameters.
[0077] In this embodiment, the host receives parameters and file streams from the network, from the server, or from other hosts. The file stream can be a data stream or data packet suitable for network transmission, or a data stream or data packet conforming to a specific transmission protocol. A PDF document can be parsed from the file stream.
[0078] In other embodiments of this application, the file stream may also include data and parameters. In this case, the data may refer to a data stream or data packet suitable for network transmission, or a data stream or data packet conforming to a specific transmission protocol, while the parameters refer to the same parameters as in the above embodiments.
[0079] In this embodiment of the application, step 250, which involves converting the first slice into a first image via a subprocess, includes:
[0080] The subprocess determines whether the first fragment needs to be fragmented based on the file header information of the first fragment, where the file header information of the first fragment includes the data size of the first fragment.
[0081] If the first slice does not need to be fragmented, the first slice is sent to a sub-thread, and the sub-thread converts the first slice into the first image.
[0082] In this embodiment of the application, the step of converting the first slice into the first image through a subprocess further includes:
[0083] If the first fragment needs to be fragmented, then
[0084] Based on the file header information of the first fragment, obtain the optimal number of second fragments;
[0085] The subprocess divides the first fragment into multiple second fragments according to the optimal number of second fragments;
[0086] Obtain child threads from the thread pool that are the same number as the optimal second shard;
[0087] Each second slice is sent to a sub-thread through the sub-process, and the second slice is converted into a second image through the sub-thread;
[0088] The second image is received through the subprocess;
[0089] The subprocess generates the first image based on the second image.
[0090] In this embodiment, the main process divides the PDF document into multiple first fragments and sends one first fragment to a child process for processing. When processing the first fragment, the child process also needs to determine whether further fragmentation is needed based on the data volume of the first fragment.
[0091] If sharding is not required, the child process will call a child thread from the thread pool to handle the transformation of the first shard. If further sharding is required, the child process will determine the number of shards based on the size of the first shard. The number of child threads in the thread pool also needs to be considered when determining the optimal number of second shards.
[0092] A thread pool is a collection of threads provided by the system to handle specific tasks. The number of idle child threads in the thread pool is also limited, and threads for handling other tasks also need to be reserved. Therefore, when considering the optimal number of second shards, more is not necessarily better.
[0093] The number of second shards can be determined based on the size of the data in the first shard, the number of child threads in the thread pool, system resources, etc.
[0094] In this embodiment, the multiple sub-threads convert the second slice into the second image independently. In this embodiment, "multiple sub-threads are independent" means that each sub-thread can execute independently without interfering with or depending on the others; the sub-threads can run in parallel during task execution. Therefore, the method of this application can accelerate processing speed.
[0095] In this application embodiment, parallel operation can refer to multiple sub-threads starting to run at the same time, i.e., starting to run at the same moment; or it can refer to multiple sub-threads starting to run approximately at the same time, without being strictly limited to starting to run at the same moment; or it can refer to multiple sub-threads running in batches due to the limitation on the number of sub-threads that the system can run in parallel or other reasons, and the sub-threads in each batch can start to run at the same time or approximately at the same time.
[0096] In this embodiment of the application, after obtaining the image save path parameter and image naming parameter from the parameters, and before generating the image corresponding to the PDF document, the method further includes:
[0097] Obtain the local directory based on the image save path parameters, and create a local folder in the local directory;
[0098] After generating the image corresponding to the PDF document, the method further includes:
[0099] The images corresponding to the PDF document are named according to the image naming parameters and stored in the local folder.
[0100] In this embodiment of the application, the parameters also include the source of the PDF document and the destination address after the PDF document is converted into an image. After the host stores the image in a local folder, it can also send the image to the destination address according to the parameters.
[0101] In this embodiment of the application, the main process is deployed on a host;
[0102] The main process, the child processes acquired by the main process, and the child threads acquired by the child processes are all deployed on the same host.
[0103] The main process, the child processes obtained by the main process, and the sub-threads obtained by the child processes are deployed on the conversion service module on the host.
[0104] The local folder is deployed on a host with the same main process and in the application system on that host.
[0105] Figure 3 The diagram shown is a schematic representation of the application environment of an embodiment of this application. Figure 3 As shown, after receiving a PDF to image conversion request, server 300 will select a host, for example... Figure 3 One of the hosts 311, 312, and 313 sends the PDF to image conversion request to the host.
[0106] Hosts 311, 312, and 313 are equipped with application systems and conversion modules. The conversion modules are independent of the application systems but can interact with them.
[0107] In this embodiment of the application, the main process, the child process created by the main process, and the child thread obtained by the child process from the thread pool can all be considered as functional modules in the conversion module.
[0108] Taking the example of host 311 receiving a PDF to image conversion request, after the conversion module deployed on host 311 receives the request, it will create a local folder in the application system according to the parameters in the conversion request. After converting the PDF to an image, it will name the image according to the parameters in the conversion request and store it in the local folder.
[0109] In this embodiment, the conversion module is deployed on the host computer but is independent of the application system, does not occupy application system resources, and does not affect other applications on the host computer. The conversion module and the application system can interact, reducing data transmission processes and / or distances. Since image data is significantly larger than PDF data, data transmission and storage are time-consuming and resource-intensive. The method in this application reduces data transmission processes and / or distances, effectively shortening the PDF-to-image conversion time and improving efficiency.
[0110] Figure 4 The diagram shown is a flowchart of a document format conversion method according to an embodiment of this application. Figure 4 As shown, the method includes:
[0111] Step 410: The main process receives parameters and file streams.
[0112] Step 420: The main process creates a local folder;
[0113] Step 430: The main process divides the PDF document into multiple first fragments;
[0114] Step 440: The main process creates child processes, and the number of child processes is the same as the number of the first shards;
[0115] Step 450: The subprocess determines whether further fragmentation is needed. If fragmentation is not needed, proceed to step 460; if fragmentation is needed, proceed to step 470.
[0116] Step 460: The child process calls a child thread to convert the first slice into the first image, then proceeds to step 492.
[0117] Step 470: The subprocess further divides the first fragment into multiple second fragments.
[0118] Step 480: The child process calls child threads from the thread pool, and the number of child threads is the same as the number of second shards.
[0119] Step 490: The child thread converts the second slice into the second image.
[0120] Step 491: The subprocess generates the first image based on the second image.
[0121] Step 492: The child process sends the first image to the main process.
[0122] Step 493: The main process names the first image and stores it in a local folder.
[0123] The method in this application embodiment can determine the number of sub-processes and sub-threads to be called based on the size of the PDF document's data, enabling the sub-processes and sub-threads to convert the PDF document into segments, thereby allowing parallel processing of the PDF document to image conversion task, saving conversion time and improving conversion efficiency.
[0124] Figure 2 , Figure 4 This is a schematic flowchart of a document format conversion method according to an embodiment of this application. It should be understood that, although... Figure 2 , Figure 4 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2 , Figure 4At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
[0125] Corresponding to the above document format conversion method, this application also provides a document format conversion apparatus.
[0126] In one embodiment, such as Figure 5 As shown, a document format conversion device is provided, the device comprising:
[0127] The header parsing unit 510 is used to obtain the header information of the PDF document, wherein the header information of the PDF document includes the data size of the PDF document.
[0128] The first determining unit 520 is used to obtain the optimal number of first segments based on the file header information of the PDF document;
[0129] The subprocess creation unit 530 is used to create subprocesses with the same number of optimal first fragments;
[0130] The first segmentation unit 540 is used to segment the PDF document into multiple first segments according to the optimal number of first segments;
[0131] The sending unit 550 is configured to send each of the first segments to a subprocess, through which the subprocess converts the first segments into a first image;
[0132] The receiving unit 560 is used to receive the first image;
[0133] Image generation unit 570 is used to generate images corresponding to the PDF document based on the first image.
[0134] Figure 6 The diagram shown is a schematic representation of a document format conversion apparatus according to an embodiment of this application. Figure 6 and Figure 5 In this context, units with the same label have the same or similar functions, which will not be elaborated further here.
[0135] like Figure 6 As shown in the embodiments of this application, the device further includes:
[0136] The judgment unit 580 is used to determine whether the first fragment needs to be fragmented based on the file header information of the first fragment through the subprocess. The file header information of the first fragment includes the data volume of the first fragment.
[0137] The sending unit 550 is further configured to send the first fragment to a sub-thread if the first fragment does not need to be fragmented, and to convert the first fragment into the first image through the sub-thread.
[0138] In this embodiment of the application, a second fragmentation unit 590 is also included, which is used to: if the first fragment needs to be fragmented, then:
[0139] Based on the file header information of the first fragment, obtain the optimal number of second fragments;
[0140] The subprocess divides the first fragment into multiple second fragments according to the optimal number of second fragments;
[0141] Obtain child threads from the thread pool that are the same number as the optimal second shard;
[0142] Each second slice is sent to a sub-thread through the sub-process, and the second slice is converted into a second image through the sub-thread;
[0143] The second image is received through the subprocess;
[0144] The subprocess generates the first image based on the second image.
[0145] In this embodiment of the application, the receiving unit 560 is further configured to: before obtaining the header information of the PDF document,
[0146] Receive parameters and file stream;
[0147] Obtain the PDF document from the file stream;
[0148] Obtain the image save path parameter and image naming parameter from the parameters.
[0149] In this embodiment of the application, the device further includes:
[0150] The directory creation unit 591 is used to obtain the local directory according to the image saving path parameters and create a local folder in the local directory;
[0151] Storage unit 592 is used to name the images corresponding to the PDF document according to the image naming parameters and store them in the local folder.
[0152] Figure 5 , Figure 6 In this document, the connections between the functional units are only illustrative of the direction of data transmission, but some connections and data transmission directions are not fully shown.
[0153] In this embodiment of the application, when the multiple sub-threads convert the second slice into the second image, they run independently and in parallel.
[0154] In this embodiment of the application, the main process is deployed on a host;
[0155] The main process, the child processes acquired by the main process, and the child threads acquired by the child processes are all deployed on the same host.
[0156] In this embodiment of the application, the main process, the child process obtained by the main process, and the sub-thread obtained by the child process are deployed on the conversion service module on the host.
[0157] The local folder is deployed on a host with the same main process and in the application system on that host.
[0158] The PDF document to image conversion apparatus of this application embodiment can improve conversion efficiency.
[0159] Figure 7 The diagram shown is an application scenario illustration of the document format conversion method according to an embodiment of this application. Figure 7 As shown, the user uploads a PDF file to the main application system.
[0160] The main application system receives a PDF file and parses the file stream containing the PDF file. After parsing, the services requested by the user may include a conversion service and a non-conversion service, Task A. Task A can be executed within the main application system; the conversion service is executed by the auxiliary conversion system.
[0161] The main application system sends the key parameters required for the conversion service to the service conversion system. The auxiliary conversion system then performs PDF document format conversion service according to the method described in the above embodiments of this application, saves the converted images to the parameter directory specified in the key parameters, and feeds back the execution results to the main application system.
[0162] The main application system confirms the processing results of Task A and the conversion service, confirms the operation is complete, and sends the completed results back to the user.
[0163] In the above application scenarios, the auxiliary conversion system can be the conversion service module in the above embodiments, and the main application system can be the application system in the above embodiments.
[0164] Figure 8 An internal structural diagram of a computer device in one embodiment is shown. Specifically, this computer device may be... Figure 1 Terminal 110 (or server 120) in the middle. For example... Figure 8As shown, the computer device includes a processor, memory, network interface, input device, and display screen connected via a system bus. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores an operating system and may also store computer programs. When executed by the processor, these programs enable the processor to perform document format conversion methods. The internal memory may also store computer programs, which, when executed by the processor, enable the processor to perform document format conversion methods. The display screen can be an LCD screen or an e-ink screen. The input device can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device's casing, or an external keyboard, touchpad, or mouse.
[0165] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0166] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps: obtaining header information of a PDF document, the header information including the data size of the PDF document; obtaining an optimal number of first fragments based on the header information; creating a subprocess with the same number of first fragments; dividing the PDF document into multiple first fragments according to the optimal number of first fragments; sending each first fragment to one of the subprocesses, and having the subprocesses convert the first fragments into first images; receiving the first images; and generating an image corresponding to the PDF document based on the first images.
[0167] In one embodiment, the processor also implements the steps of the above method when executing the computer program, which will not be repeated here.
[0168] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, it performs the following steps: obtaining the header information of a PDF document, wherein the header information of the PDF document includes the data size of the PDF document; obtaining an optimal number of first fragments based on the header information of the PDF document; creating a subprocess with the same number of first fragments; dividing the PDF document into multiple first fragments according to the optimal number of first fragments; sending each first fragment to one of the subprocesses, and having the subprocesses convert the first fragments into first images; receiving the first images; and generating an image corresponding to the PDF document based on the first images.
[0169] In one embodiment, the computer program, when executed by a processor, also implements the steps of the above method, which will not be repeated here.
[0170] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, causing the computer device to perform the following steps: obtaining header information of a PDF document, the header information including the data size of the PDF document; obtaining an optimal number of first fragments based on the header information of the PDF document; creating a subprocess with the same number of optimal first fragments; fragmenting the PDF document into multiple first fragments according to the optimal number of first fragments; sending each first fragment to one of the subprocesses, and having the subprocesses convert the first fragments into first images; receiving the first images; and generating an image corresponding to the PDF document based on the first images.
[0171] In one embodiment, the computer program product or computer program, when executed, also implements the steps of the above method, which will not be repeated here.
[0172] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0173] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0174] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A document format conversion method characterized by, The method applied to a main process comprises: obtaining file header information of a portable document format (PDF) document, wherein the file header information of the PDF document comprises a data amount of the PDF document; obtaining an optimal first number of fragments according to the file header information of the PDF document, wherein the optimal first number of fragments is determined according to the data amount of the PDF document and resources of a host running the main process, or the optimal first number of fragments is determined according to a range of a first data amount of each fragment, or the optimal first number of fragments is determined according to a number threshold of the first fragments; creating a same number of sub-processes as the optimal first number of fragments; sharding the PDF document into a plurality of first fragments according to the optimal first number of fragments; sending each first fragment to a sub-process to convert the first fragment into a first picture by the sub-process, comprising: confirming, by the sub-process, whether the first fragment needs to be sharded according to file header information of the first fragment, wherein the file header information of the first fragment comprises a data amount of the first fragment; if the first fragment needs to be sharded, obtaining an optimal second number of fragments according to the file header information of the first fragment; dividing the first fragment into a plurality of second fragments according to the optimal second number of fragments by the sub-process; obtaining a same number of sub-threads as the optimal second number of fragments from a thread pool; sending each second fragment to a sub-thread by the sub-process to convert the second fragment into a second picture by the sub-thread; receiving the second picture by the sub-process; and generating a first picture according to the second picture by the sub-process; receiving the first picture; generating a picture corresponding to the PDF document according to the first picture; wherein the main process, the sub-process obtained by the main process, and the sub-thread obtained by the sub-process are deployed on a conversion service module on a same host, and the conversion service module is independent of an application system of the host.
2. The method of claim 1, wherein, The converting the first fragment into the first picture by the sub-process comprises: if the first fragment does not need to be sharded, sending the first fragment to a sub-thread to convert the first fragment into the first picture by the sub-thread.
3. The method of claim 1, wherein, Before the obtaining the file header information of the PDF document, the method further comprises: receiving parameters and a file stream; obtaining the PDF document from the file stream; obtaining a picture storage path parameter and a picture naming parameter from the parameters.
4. The method of claim 3, wherein, After the obtaining the picture storage path parameter and the picture naming parameter from the parameters and before the generating the picture corresponding to the PDF document, the method further comprises: obtaining a local directory according to the picture storage path parameter, and creating a local folder under the local directory; after the generating the picture corresponding to the PDF document, the method further comprises: naming the picture corresponding to the PDF document according to the picture naming parameter, and storing the picture in the local folder.
5. The method of claim 1, wherein, The multiple sub-threads convert the second slice into a second picture independently and in parallel.
6. The method of claim 4, wherein, The local folder is deployed on a same host as the main process and in an application system deployed on the host.
7. An apparatus for converting a portable document format document to an image, the apparatus comprising: The apparatus comprises: A header file parsing unit configured to acquire file header information of a portable document format (PDF) document, wherein the file header information of the PDF document comprises a data amount of the PDF document; A first determining unit configured to acquire an optimal first slice number according to the file header information of the PDF document, wherein the optimal first slice number is determined according to a data amount of the PDF document and resources of a host running a main process, or the optimal first slice number is determined according to a range of a first data amount of each slice, or the optimal first slice number is determined according to a number threshold of the first slice; A sub-process creating unit configured to create a same number of sub-processes as the optimal first slice number; A first slicing unit configured to slice the PDF document into multiple first slices according to the optimal first slice number; A sending unit configured to send each first slice to a sub-process, convert the first slice into a first picture by the sub-process, including: confirming, by the sub-process, whether the first slice needs to be sliced according to file header information of the first slice, wherein the file header information of the first slice comprises a data amount of the first slice; if the first slice needs to be sliced, acquiring an optimal second slice number according to the file header information of the first slice; dividing, by the sub-process, the first slice into multiple second slices according to the optimal second slice number; acquiring a same number of sub-threads as the optimal second slice number from a thread pool; sending each second slice to a sub-thread by the sub-process, to convert the second slice into a second picture by the sub-thread; receiving, by the sub-process, the second picture; generating, by the sub-process, the first picture according to the second picture; wherein the main process, the sub-process acquired by the main process, and the sub-thread acquired by the sub-process are deployed on a same conversion service module on a host, and the conversion service module runs independently of an application system of the host; A receiving unit configured to receive the first picture; A picture generating unit configured to generate a picture corresponding to the PDF document according to the first picture.
8. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the computer program to implement the steps of the method of any one of claims 1 to 6.
9. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 6.
Citation Information
Patent Citations
Parallel data processing method based on latent dirichlet allocation model
CN101359333A
System and method for realizing cross-platform document reading
CN104239426A
Heterogeneous data source standardized processing method and device and server
CN108038239A
Data processing method and device applied to webpage front end and storage medium
CN110020359A