Method and device for analyzing flow chart in pdf and medium
Through the Apache PDFBOX framework and depth-first search algorithm, the flow charts in PDF documents are extracted and processed, and the accuracy of analyzing flow charts in the prior art is solved, and the ability to efficiently and accurately extract and handle complex situations is achieved.
Patent Information
- Application Number
- CN202411213516.4
- 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
The failure of prior art to accurately and effectively parse and extract flow charts in PDF documents, especially in complex flow charts, can lead to coherence problems.
The Apache PDFBOX framework is combined with the depth-first search (DFS) algorithm, and the page element information is extracted, closed graphics are obtained, deduplication is performed, and the longest link is merged, the rectangular image size is determined and intercepted, and the rectangular image is output.
It realizes efficient and accurate extraction of flow charts in complex PDF documents, can handle complex situations such as graph nesting and intersection, ensures the accuracy of the extraction results, and is modular in the flow chart elements, which are easy to update and expand.
Smart Images

Figure CN119152535A_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 parsing a flow chart in PDF. Background Art
[0002] PDF plays a vital role in information transmission and data storage. However, the complexity of PDF makes the extraction and parsing of content challenging, especially for flowcharts in PDF documents. Flowcharts are a special and important element in PDF documents due to their closed graphic characteristics and their key role in logic and process. However, for the extraction of flowcharts in PDF documents, the existing technology cannot accurately and effectively identify them. Most of them are assembled according to the identified elements in PDF, and then generated one by one into the word document according to the sequence of line segments. In this way, the continuity of the flowchart may be problematic, and the extraction effect of complex flowcharts is not satisfactory. Therefore, how to better parse the flowchart in PDF has become a top priority in data-driven decision-making and applications. Summary of the invention
[0003] The purpose of the present invention is to provide a method for parsing a flow chart in a PDF 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 parsing a flowchart in a PDF comprises the following steps: Step 1: Use Apache's open source framework PDFBOX to parse the PDF file containing the flowchart; Step 2: Use operators to extract the element information of the page from the file and construct an element list. The elements are straight lines and curves containing coordinate values. Step 3: Based on the element list, a closed graph is obtained according to the element information, and the elements constituting the closed graph are deleted from the element list; Step 4: performing deduplication processing on the closed graph; Step 5: Add the closed graph after deduplication to the original element set; Step 6: Sort the original element set to obtain the sorted original element set; Step 7: Based on the sorted original element set, use the depth-first search algorithm to obtain several longest links; Step 8: Determine whether there are repeated elements in the longest link. If there are repeated elements, merge the intersecting links and obtain the minimum start coordinate and maximum end coordinate of the intersecting links. If there are no repeated elements, it means that the link is disconnected and proceed directly to the next step. Step 9: Determine the size of the rectangular image according to the obtained minimum start coordinate and maximum end coordinate; Step 10: loop through steps 8 to 9, merge all the longest links, obtain several rectangular images, and intercept the rectangular images; Step 11: Output all the captured rectangular images.
[0005] Preferably, the specific method of step 3 is as follows: first, obtain all straight lines and curves from the element list; then, use a depth-first search algorithm to identify elements that can be merged into closed figures, and merge the elements that can be merged into closed shapes into closed figures; finally, delete the elements that have been merged into closed figures from the element list.
[0006] Preferably, the deduplication process in step 4 includes: (41) if there is nested closed graphics, only retaining the outermost closed graphics; (42) if there are intersections of closed graphics, merging the intersecting closed graphics.
[0007] Preferably, the sorting method in step 6 is to sort from top to bottom and from left to right.
[0008] Preferably, in step 7, a depth-first search algorithm is used, with the intersection, continuity or inclusion within the error range of the rectangular area where the element is located as the search condition.
[0009] 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 parsing the flowchart in PDF.
[0010] In order to achieve the above-mentioned purpose, the present invention also provides a device for parsing a flowchart in PDF, 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 parsing a flowchart in PDF executes the method for parsing a flowchart in PDF.
[0011] Compared with the prior art, the present invention has the following beneficial effects: (1) The present invention can efficiently and accurately extract flowcharts from complex PDF documents by combining the PDFBOX framework and the depth-first search (DFS) algorithm.
[0012] (2) The present invention can handle various complex situations, including but not limited to problems such as nesting and intersection of graphs, thereby ensuring the accuracy of the extraction results.
[0013] (3) The present invention modularizes the flowchart elements and other elements, which can be easily updated, expanded or modified to adapt to different needs and scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 This is a schematic diagram of the process of Example 1 of the present invention.
[0015] Figure 2 This is a principle block diagram of Example 3 of the present invention. DETAILED DESCRIPTION
[0016] 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.
[0017] 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.
[0018] Example 1 like Figure 1 As shown, this embodiment provides a method for parsing a flowchart in a PDF, which mainly includes the following steps: 1. Step 1: Parse the PDF file containing the flowchart The PDF file containing the flowchart is parsed with the help of Apache's open source framework PDFBOX. The PDFBOX framework is a Java-based, easy-to-integrate project with good compatibility and scalability, and can support complex PDF file parsing.
[0019] 2. Step 2: Extract element information of the page Use operators to extract the element information of the page from the file and build an element list. The elements are straight lines and curves containing coordinate values. In a PDF document, there is no way to directly identify the flowchart graphics contained in the document. Therefore, it is necessary to extract the element information. All the extracted page elements are simple elements (paths, points, etc.).
[0020] 3. Step 3: Get closed graphics based on element information Based on the element list, a closed figure is obtained according to the element information, and the elements constituting the closed figure are deleted from the element list; the specific method is as follows: first, all straight lines and curves are obtained from the element list; then, a depth-first search algorithm is used to identify elements that can be merged into a closed figure, and the elements that can be merged into a closed shape are merged into a closed figure; the DFS algorithm is used to identify the closed figure, and the element set containing straight lines and curves is searched according to the coordinate points. The closed figure can be understood as several lines that can form a complete figure; such as: the four sides of a square, the five sides of a pentagon, etc. The merging step is to put the sides that can form a closed figure into a set; finally, the elements that have been merged into a closed figure are deleted from the element list.
[0021] Step 4: De-duplication of closed graphics In this step, the deduplication process includes: (41) if there is nested closed graphs, only the outermost closed graph is retained; (42) if the closed graphs intersect, the intersecting closed graphs are merged.
[0022] 5. Step 5: Add the closed figures after deduplication to the original element set.
[0023] 6. Step 6: Sort the original element set to obtain a sorted original element set; in this step, the sorting method adopted is as follows: sort from top to bottom and from left to right.
[0024] VII. Step 7: Get several longest links Based on the sorted original element set, a depth-first search algorithm is used to obtain several longest links with the intersection, continuity or inclusion within the error range of the rectangular area where the elements are located as the search condition.
[0025] 8. Step 8: Merge and process the longest link Determine whether there are repeated elements in the longest link. If there are repeated elements, the links are considered to be intersecting, the intersecting links are merged, and the minimum starting coordinates and maximum ending coordinates of the intersecting links are obtained; if there are no repeated elements, it means that the link is disconnected, and proceed directly to the next step.
[0026] 9. Step 9: Determine the size of the rectangular image The size of the rectangular image is determined according to the minimum starting coordinate and the maximum ending coordinate. The minimum starting coordinate and the maximum ending coordinate are obtained. In a coordinate system, the minimum starting coordinate and the maximum ending coordinate can determine a rectangular area. Therefore, the size of the rectangular image, that is, the size of the rectangular area, can be determined.
[0027] 10. Step 10: Repeat steps 8 to 9 to merge all the longest links, obtain several rectangular images, and intercept the rectangular images.
[0028] 11. Step 11: Output all captured rectangular images.
[0029] Through the above settings, the flowchart of the PDF file can be parsed. Compared with the existing technology, it has the advantages of high efficiency and accuracy, ability to handle various complex situations, and easy expansion.
[0030] 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 parsing a flowchart in a PDF provided in Embodiment 1. A person skilled 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.
[0031] Example 3 like Figure 2 As shown, this embodiment provides a device for parsing a flowchart in PDF, 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 parsing a flowchart in PDF executes the method for parsing a flowchart in PDF provided in Example 1.
[0032] Specifically, the memory includes: ROM, RAM, disk, USB flash drive, memory card or CD and other media that can store program codes.
[0033] 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.
[0034] 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 parsing a flowchart in PDF, characterized in that: The following steps are involved: Step 1: Use Apache's open source framework PDFBOX to parse the PDF file containing the flowchart; Step 2: Use the operator to extract the page element list from the file. The element list is a number of straight lines or curves containing coordinate values. Step 3: Based on the element list, obtain closed graphic elements according to element information, and delete the elements constituting the closed graphic from the element list; Step 4: performing deduplication processing on the closed graphic elements; Step 5: Add the closed graph elements after deduplication to the element list after deleting the elements constituting the closed graph in step 3; Step 6: Sort the element set of the closed graph after deduplication in step 5 to obtain a sorted element set; Step 7: Based on the set of elements sorted in step 6, use the depth-first search algorithm to obtain several longest links; Step 8: Determine whether there are repeated elements in the longest link. If there are repeated elements, merge the intersecting links and obtain the minimum start coordinates and maximum end coordinates of the intersecting links; if there are no repeated elements, it means that the link is disconnected, and the minimum start coordinates and maximum end coordinates are the minimum start coordinates and maximum end coordinates of the longest link, and proceed directly to the next step; Step 9: Determine the size of the rectangular image according to the obtained minimum start coordinate and maximum end coordinate; Step 10: loop through steps 8 and 9, merge all the longest links, obtain several rectangular images, and intercept the rectangular images; Step 11: Output all the captured rectangular images.
2. The method for parsing a flowchart in PDF according to claim 1, characterized in that: The specific method of step 3 is as follows: first, obtain all straight lines and curves from the element list; then, use a depth-first search algorithm to identify elements that can be merged into a closed figure, and merge the elements that can be merged into a closed shape into a closed figure; finally, delete the elements that have been merged into a closed figure from the element list.
3. The method for parsing a flowchart in PDF according to claim 2, characterized in that: The deduplication process in step 4 includes: (41) if there is nested closed graphs, only the outermost closed graph is retained; (42) if the closed graphs intersect, the intersecting closed graphs are merged.
4. The method for parsing a flowchart in PDF according to claim 3, characterized in that: The sorting method in step 6 is: sorting from top to bottom and from left to right.
5. The method for parsing a flowchart in PDF according to claim 4, characterized in that: In step 7, a depth-first search algorithm is used, with the intersection, continuity or inclusion of closed graphic elements and straight line and curve elements that do not belong to the closed graphic and contain coordinate values within the error range of the rectangular area as the search condition.
6. 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 parsing a flowchart in a PDF as described in any one of claims 1 to 5.
7. A device for parsing a flowchart in PDF, 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 parsing the flowchart in PDF executes the method for parsing the flowchart in PDF as described in any one of claims 1 to 5.
