Method and device for processing picture surround mode and surround margin in pdf-to-word process, and medium
The Apache PDFBOX framework analyzes PDF files, recognizes and calculates the surround method and margins of pictures, solves the challenge of image surround mode processing during PDF to Word, realizes format mapping and layout consistency, and improves processing effect and user experience.
Patent Information
- Application Number
- CN202411213517.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2024-12-17
AI Technical Summary
During the PDF conversion to Word, there are challenges in the surround mode and surround margin processing of images, and the existing technology has not effectively solved it.
Use the Apache PDFBOX framework to parse PDF files, traverse image information, obtain four corner coordinate points, identify and set the surround method of the image and calculate the surround margin, including suspended, up and down, embedded and surrounding surround modes, and save the set surround Method and margins.
It realizes format mapping and layout maintenance during PDF conversion to Word, accurately handles various surround modes, and improves processing effect and user experience.
Smart Images

Figure CN119150801A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of PDF parsing, and in particular, relates to a method, device and medium for processing image wrapping mode and wrapping margin in the process of converting PDF to Word. Background Art
[0002] When processing PDF files to Word documents, due to the differences between PDF and Word in file structure and content expression, especially for PDF documents containing images, the image wrapping mode and wrapping margins pose challenges to the conversion process. In the prior art, there is no technical precedent for processing image wrapping modes and wrapping margins in the process of converting PDF to Word. Summary of the invention
[0003] The purpose of the present invention is to provide a method for processing image wrapping mode and wrapping margin in the process of converting PDF to Word, so as to solve the technical problems existing in the prior art.
[0004] In order to achieve the above object, the technical solution adopted by the present invention is as follows: A method for processing image wrapping mode and wrapping margin in a PDF to Word conversion process, comprising the following steps: Step 1: Use Apache's open source PDFBOX framework to parse PDF files containing images and text; Step 2: Traverse all the image information obtained by parsing, and obtain the four corner coordinates of the currently processed image in each traversal; Step 3: According to the four corner coordinate points, obtain a list of elements that intersect with the top, bottom, left, right and of the currently processed image; Step 4: Identify and set the image wrapping method: (41) If the intersecting element list is not empty, set the image to float above the text in wrap mode; (42) If there are elements above and below the image but not on the left and right, set the image to top and bottom wrap mode, calculate the top and bottom wrap margins, and set the calculated wrap margins to the image object; (43) If there are elements on the left or right of the image, determine whether the elements are in the same row: if they are in the same row, set the image to embedded surround; if they are not in the same row, set the image to surround all around, calculate the surround margin, and set the calculated surround margin to the image object; Step S5: saving the picture with the set wrapping mode and wrapping margin; Step S6: Repeat steps 3 to 5 until all images are processed.
[0005] Preferably, the method for calculating the upper and lower surrounding margins in (42) is as follows: (421) obtaining the minimum y-coordinate value y1 of the current image and the maximum y-value y2 in the element set above the image, and calculating the upper surrounding margin of the image: |y1-y2| is the upper surrounding margin; (422) obtaining the maximum y-coordinate value y1 of the current image and the minimum y-value y2 in the element set below the image, and calculating the lower surrounding margin of the image: |y2-y1| is the lower surrounding margin.
[0006] Preferably, the method for calculating the wrapping margin in (43) is as follows: (431) Obtain the minimum y-coordinate value y1 of the current image and the maximum y-value y2 in the element set above the image, and calculate the upper wrapping margin of the image: |y1-y2| is the upper wrapping margin; (432) Obtain the maximum y-coordinate value y1 of the current image and the minimum y-value y2 in the element set below the image, and calculate the lower wrapping margin of the image: |y2-y1| is the lower wrapping margin; (433) Obtain the minimum x-coordinate value x1 of the current image and the maximum x-value x2 in the element set on the left side of the image, and calculate the left wrapping margin of the image: |x1-x2| is the left wrapping margin; (434) Obtain the maximum x-coordinate value x1 of the current image and the minimum x-value x2 in the element set on the right side of the image, and calculate the lower wrapping margin of the image: |x2-x1| is the right wrapping margin.
[0007] In order to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium on which a computer program is stored, and the computer program is executed by a processor to implement the method of processing image wrapping mode and wrapping margin in the process of converting PDF to Word.
[0008] In order to achieve the above-mentioned purpose, the present invention also provides a device for processing image wrapping mode and wrapping margin during the PDF to Word process, comprising: a processor and a memory; the memory is used to store a computer program; the processor is connected to the memory, and is used to execute the computer program stored in the memory, so that the device for processing image wrapping mode and wrapping margin during the PDF to Word process executes the method for processing image wrapping mode and wrapping margin during the PDF to Word process.
[0009] Compared with the prior art, the present invention has the following beneficial effects: By processing the wrapping mode of the image and calculating the wrapping margin, the present invention can roughly maintain the layout and format of the original document during the process of converting PDF to Word, thereby achieving accurate format mapping; the present invention not only handles the situations of upper and lower wrapping and surrounding wrapping, but also processes the modes of image embedding between lines and image floating above text, so that it can more comprehensively cope with the needs of various wrapping modes; the flexible and comprehensive processing method of the present invention greatly improves the processing effect and user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 This is a schematic diagram of the process of Example 1 of the present invention.
[0011] Figure 2 This is a principle block diagram of Example 3 of the present invention. DETAILED DESCRIPTION
[0012] In order to enable those skilled in the art to have a clearer understanding and knowledge of the present invention, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described below are only used to explain the present invention, and are convenient for understanding. The technical solutions provided by the present invention are not limited to the technical solutions provided by the following embodiments, and the technical solutions provided by the embodiments should not limit the protection scope of the present invention.
[0013] It should be noted that the illustrations provided in the following embodiments are only used to illustrate the basic concept of the present invention in a schematic manner. Therefore, the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the form, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0014] Example 1 like Figure 1 As shown, this embodiment provides a method for processing image wrapping mode and wrapping margin in the process of converting PDF to Word. The method is based on processing the image wrapping mode and calculating the wrapping margin to ensure the format accuracy and layout consistency when converting PDF to Word, thereby solving the problem of image wrapping processing in the process of converting PDF to Word.
[0015] In this embodiment, the method for processing the image wrapping mode and wrapping margin in the process of converting PDF to Word mainly includes the following steps: 1. Step 1: Parse PDF file Use Apache's open source PDFBOX framework to parse PDF files containing images and text; the PDFBOX framework is a Java-based, easy-to-integrate project with good compatibility and scalability, and can support complex PDF file parsing.
[0016] 2. Step 2: Traverse all the image information obtained by parsing In each traversal, the four corner coordinate points of the currently processed image, that is, the four corners of the rectangle where the image is located, are obtained. After the traversal of all images is completed, the four corner coordinate points of all images are obtained.
[0017] 3. Step 3: Based on the four corner coordinate points, get the list of elements that intersect above, below, left, and right of the currently processed image.
[0018] 4. Step 4: Identify the image wrapping method and calculate the wrapping margin This step is one of the core steps of the present invention, which mainly includes the following: (41) If there are elements that intersect with the image, that is, the "intersecting element list" obtained in step 3 is not empty, it proves that there are elements that overlap with the image. In this case, the image is set to float above the text in wrapping mode. In this case, there is no need to calculate the wrapping margin. (42) If there are elements above and below the image but not on the left and right, set the image to top and bottom wrap mode, calculate the top and bottom wrap margins, and set the calculated wrap margins to the image object. The specific calculation method is as follows: (421) Get the minimum y coordinate value y1 of the current image and the maximum y value y2 in the element set above the image, and calculate the top wrapping margin of the image: |y1-y2| is the top wrapping margin; (422) Get the maximum y coordinate value y1 of the current image and the minimum y value y2 in the element set below the image, and calculate the bottom wrapping margin of the image: |y2-y1| is the bottom wrapping margin.
[0019] (43) If there are elements on the left or right of the image, determine whether the elements are in the same row: if they are in the same row, set the image to embedded surround; if they are not in the same row, set the image to surround all around, calculate the surround margin, and set the calculated surround margin to the image object. The specific calculation method is as follows: (431) Get the minimum y coordinate value y1 of the current image and the maximum y value y2 in the element set above the image, and calculate the top wrapping margin of the image: |y1-y2| is the top wrapping margin; (432) Get the maximum y coordinate value y1 of the current image and the minimum y value y2 in the element set below the image, and calculate the bottom wrapping margin of the image: |y2-y1| is the bottom wrapping margin; (433) Get the minimum x-coordinate value x1 of the current image and the maximum x-value x2 in the element set on the left side of the image, and calculate the left surround margin of the image: |x1-x2| is the left surround margin; (434) Get the maximum x-coordinate value x1 of the current image and the minimum x-value x2 in the element set on the right side of the image, and calculate the bottom wrapping margin of the image: |x2-x1| is the right wrapping margin.
[0020] 5. Step 5: Save the picture with the wrapping mode and wrapping margin set.
[0021] 6. Step 6: Process all images according to the above steps 3 to 5 until all images are processed.
[0022] The processed image has the correct wrapping method and wrapping margin, which can be used for subsequent operation steps in the PDF to Word process.
[0023] Example 2 This embodiment provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the method for processing image wrapping mode and wrapping margin in the process of converting PDF to Word provided in Embodiment 1. A person of ordinary skill in the art can understand that all or part of the steps of implementing the method provided in Embodiment 1 can be completed by hardware related to the computer program, and the above-mentioned computer program can be stored in a computer-readable storage medium, and when the program is executed, the steps of the method provided in Embodiment 1 are executed; and the above-mentioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.
[0024] Example 3 like Figure 2 As shown, this embodiment provides a device for processing image wrapping mode and wrapping margin during PDF to Word conversion, including: a processor and a memory; the memory is used to store a computer program; the processor is connected to the memory, and is used to execute the computer program stored in the memory, so that the device for processing image wrapping mode and wrapping margin during PDF to Word conversion executes the method for processing image wrapping mode and wrapping margin during PDF to Word conversion provided in Example 1.
[0025] Specifically, the memory includes: ROM, RAM, disk, USB flash drive, memory card or CD and other media that can store program codes.
[0026] Preferably, the processor can be a general-purpose processor, including a central processing unit, a network processor, etc.; it can also be a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component.
[0027] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A method for processing image wrapping mode and wrapping margin in the process of converting PDF to Word, characterized in that: The following steps are involved: Step 1: Use Apache's open source PDFBOX framework to parse PDF files containing images and text; Step 2: Traverse all the image information obtained by parsing, and obtain the four corner coordinates of the currently processed image in each traversal; Step 3: According to the four corner coordinate points, obtain a list of elements that intersect with the top, bottom, left, right and of the currently processed image; Step 4: Identify and set the image wrapping method: (41) If the intersecting element list is not empty, set the image to float above the text in wrap mode; (42) If there are text or images above and below the image, but not on the left and right, set the image to top and bottom wrap mode, calculate the top and bottom wrap margins, and set the calculated wrap margins to the image object; (43) If there are elements on the left or right of the image, determine whether the elements are in the same row: if they are in the same row, set the image to embedded surround; if they are not in the same row, set the image to surround all around, calculate the surround margin, and set the calculated surround margin to the image object; Step S5: saving the picture with the set wrapping mode and wrapping margin; Step S6: Repeat steps 3 to 5 until all images are processed.
2. The method for processing image wrapping mode and wrapping margin in the process of converting PDF to Word according to claim 1, characterized in that: The method for calculating the upper and lower surrounding margins in (42) is as follows: (421) Obtain the minimum y-coordinate value y1 of the current image and the maximum y-value y2 in the element set above the image, and calculate the upper surrounding margin of the image: |y1-y2| is the upper surrounding margin; (422) Obtain the maximum y-coordinate value y1 of the current image and the minimum y-value y2 in the element set below the image, and calculate the lower surrounding margin of the image: |y2-y1| is the lower surrounding margin.
3. The method for processing image wrapping mode and wrapping margin in the process of converting PDF to Word according to claim 2, characterized in that: The method for calculating the wrapping margin in (43) is as follows: (431) Obtain the minimum y-coordinate value y1 of the current image and the maximum y-value y2 in the element set above the image, and calculate the upper wrapping margin of the image: |y1-y2| is the upper wrapping margin; (432) Obtain the maximum y-coordinate value y1 of the current image and the minimum y-value y2 in the element set below the image, and calculate the lower wrapping margin of the image: |y2-y1| is the lower wrapping margin; (433) Obtain the minimum x-coordinate value x1 of the current image and the maximum x-value x2 in the element set on the left side of the image, and calculate the left wrapping margin of the image: |x1-x2| is the left wrapping margin; (434) Obtain the maximum x-coordinate value x1 of the current image and the minimum x-value x2 in the element set on the right side of the image, and calculate the lower wrapping margin of the image: |x2-x1| is the right wrapping margin.
4. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program is executed by a processor to implement the method for processing image wrapping mode and wrapping margin in the PDF to Word conversion process as described in any one of claims 1 to 3.
5. A device for processing image wrapping mode and wrapping margin in the process of converting PDF to Word, characterized in that: include: Processor and memory; The memory is used to store computer programs; The processor is connected to the memory and is used to execute the computer program stored in the memory, so that the device for processing the image wrapping mode and wrapping margin during the PDF to Word conversion process performs the method for processing the image wrapping mode and wrapping margin during the PDF to Word conversion process as described in any one of claims 1 to 3.
