File repairing method and device, terminal equipment and readable storage medium

By acquiring, parsing, and supplementing missing object blocks in a PDF file, the corrupted PDF file is repaired, its logical structure tree is restored, and the file can be opened normally.

CN117076397BActive Publication Date: 2025-10-17AFIRSTSOFT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310866415.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-13
Publication Date
2025-10-17
Estimated Expiration
2043-07-13

AI Technical Summary

Technical Problem

Existing technologies cannot effectively repair damaged PDF files, making them unable to open normally.

Method used

By obtaining the PDF file to be repaired, extracting the set of missing object blocks, parsing and supplementing the set of missing logical object blocks, modifying the reference relationships, generating a complete set of object blocks and a cross-reference table, and forming a repaired file.

Benefits of technology

The logical structure tree for repairing files is complete, allowing them to be opened normally, thus successfully repairing damaged PDF files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117076397B_ABST
    Figure CN117076397B_ABST
Patent Text Reader

Abstract

The application is suitable for the technical field of repairing, and provides a file repairing method and device, terminal equipment and readable storage medium. Embodiments of the application obtain a complete logical object block set by supplementing a missing logical object block set, thereby supplementing a file logical structure tree of a file to be repaired to be complete, obtaining a complete object set, and obtaining a repaired file according to the complete object set. Since the file logical structure tree in the repaired file is complete, the repaired file can be normally opened, thereby realizing the repairing of a damaged PDF file.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of repairing, and particularly relates to a file repairing method and device, a terminal device and a readable storage medium. BACKGROUND

[0002] PDF (Portable Document Format) is a general document format, which has the advantages of stable format, good compatibility, small size, convenient network transmission and the like, and is therefore widely used. A PDF file usually includes a file header, a file body, a cross-reference table and a file tail, and the file body is a collection of multiple object blocks. In the related art, when a PDF file is damaged, the PDF file cannot be repaired to be normally opened. SUMMARY

[0003] Embodiments of the present application provide a file repairing method and device, a terminal device and a readable storage medium, which can solve the problem that a damaged PDF file cannot be repaired in the related art.

[0004] In a first aspect, embodiments of the present application provide a file repairing method, which includes the following steps.

[0005] Obtaining a file to be repaired, which is a damaged PDF file;

[0006] Extracting a missing object block set in the file to be repaired, which is a set composed of remaining object blocks in the file to be repaired;

[0007] Analyzing the missing object block set to obtain a missing logical object block set and a corresponding missing data object block set, wherein the missing logical object block set and the corresponding object block in the missing data object block set have a reference relationship;

[0008] Supplementing the missing logical object block set to obtain a complete logical object block set;

[0009] Modifying the reference relationship of a complete logical object block in the complete logical object block set to obtain a modified complete logical object block set, and obtaining a complete object block set based on the modified complete logical object block set and the missing data object block set;

[0010] Generating a corresponding cross-reference table and file tail based on the complete object block set;

[0011] Generating a repaired file based on a newly created file header, the complete object block set, the cross-reference table and the file tail, wherein the repaired file is a repaired PDF file.

[0012] In a second aspect, an embodiment of the present application provides a file repairing device, comprising:

[0013] A first obtaining module is configured to obtain a file to be repaired, the file to be repaired being a damaged PDF file.

[0014] An extracting module is configured to extract a missing object block set from the file to be repaired, the missing object block set being a set of remaining object blocks in the file to be repaired.

[0015] An analyzing module is configured to analyze the missing object block set to obtain a missing logical object block set and a corresponding missing data object block set, wherein the missing logical object block set has a reference relationship with corresponding object blocks in the missing data object block set.

[0016] A supplementing module is configured to supplement the missing logical object block set to obtain a complete logical object block set.

[0017] A modifying module is configured to modify a reference relationship of a complete logical object block in the complete logical object block set to obtain a modified complete logical object block set, and obtain a complete object block set based on the modified complete logical object block set and the missing data object block set.

[0018] A first generating module is configured to generate a cross-reference table and a file tail based on the complete object block set.

[0019] A second generating module is configured to generate a repaired file based on a newly created file header, the complete object block set, the cross-reference table and the file tail, the repaired file being a repaired PDF file.

[0020] In a third aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements steps of the file repairing method when executing the computer program.

[0021] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program implements steps of the file repairing method when executed by a processor.

[0022] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, causes the terminal device to perform the file repairing method.

[0023] The advantageous effects of the embodiments of the present application compared to the prior art are as follows: the embodiments of the present application obtain a file to be repaired, extract a set of missing object blocks from the file to be repaired, parse the missing object block set, obtain a set of missing logical object blocks and a corresponding set of missing data object blocks, then supplement the missing logical object block set to obtain a complete logical object block set, modify the reference relationships of the complete logical object blocks in the complete logical object block set to obtain a modified complete logical object block set, then obtain a complete object block set based on the modified complete logical object block set and the set of missing data object blocks, then generate a corresponding cross-reference table and file trailer based on the complete object block set, and finally generate a repair file based on the newly created file header, complete object block set, cross-reference table, and file trailer. The embodiments of the present application supplement the missing logical object block set to obtain a complete logical object block set, thereby completing the file logical structure tree of the file to be repaired, thereby obtaining a complete object set, and then obtaining a repair file based on the complete object set. Because the file logical structure tree in the repaired file is complete, the repaired file can be opened normally, thereby achieving repair of the damaged PDF file. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0025] Figure 1 This is a schematic diagram of an implementation flow of a file repair method provided in an embodiment of the present application;

[0026] Figure 2 is a schematic diagram of a logical structure tree provided in an embodiment of the present application;

[0027] Figure 3 This is a schematic diagram of the contents of a page object block provided in an embodiment of the present application;

[0028] Figure 4 This is a schematic diagram of an implementation flow for supplementing a missing logical object block set provided by an embodiment of the present application;

[0029] Figure 5 This is a schematic diagram of the implementation process of the parent logical object block of the supplementary page object block provided in an embodiment of the present application;

[0030] Figure 6 This is a schematic diagram of the implementation flow of the child logical object block of the supplementary pages object block provided in an embodiment of the present application;

[0031] Figure 7 is an implementation flowchart of supplementing a father logical object block in a missing logical object block set provided by an embodiment of the present application;

[0032] Figure 8 is another implementation flowchart of supplementing a father logical object block in a missing logical object block set provided by an embodiment of the present application;

[0033] Figure 9 is an implementation flowchart of supplementing a father logical object block of a pages object block provided by an embodiment of the present application;

[0034] Figure 10 is an implementation flowchart of supplementing a child logical object block in a missing logical object block set provided by an embodiment of the present application;

[0035] Figure 11 is a content diagram of a pages object block provided by an embodiment of the present application;

[0036] Figure 12 is an implementation flowchart of modifying a reference relationship of a complete logical object block provided by an embodiment of the present application;

[0037] Figure 13 is an implementation flowchart of generating a cross-reference table and a file tail provided by an embodiment of the present application;

[0038] Figure 14 is a structure diagram of a file repair device provided by an embodiment of the present application;

[0039] Figure 15 is a structure diagram of a terminal device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0040] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and should not be used to limit the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative work belong to the present application.

[0041] It should be noted that the terms "comprise", "comprising", "include", "including", and "have" and "having" in the specification and claims of this application and the above-mentioned attached drawings are intended to cover non-exclusive inclusion. For example, a process, method, terminal, product or device including a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products or devices. In the claims, specification and drawings of this application, the terms such as "first" and "second" and the like relationship terms are only used to distinguish one entity / operation / object from another entity / operation / object, and do not necessarily require or imply any such real-time relationship or order between the entities / operations / objects.

[0042] Reference to "embodiments" herein means that the specific features, structures or characteristics described in connection with the embodiments can be included in at least one embodiment of the application. The phrase appears at various places in the specification does not necessarily all refer to the same embodiment, nor is it necessarily independent or alternative embodiments to other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0043] PDF (Portable Document Format), i.e. portable document format, is a general document format, which has the advantages of stable format, good compatibility, small size, convenient network transmission, etc., and is widely used. A PDF file usually includes a file header, a file body, a cross-reference table and a file tail, etc., wherein the file body is a collection of multiple object blocks. In the related art, when a PDF file is damaged, the PDF file cannot be repaired to enable it to be normally opened.

[0044] In view of this, embodiments of the present application supplement the missing logical object block set to obtain a complete logical object block set, thereby supplementing the file logical structure tree of the file to be repaired to complete, thereby obtaining a complete object set, and obtaining a repaired file according to the complete object set. Since the file logical structure tree in the repaired file is complete, the repaired file can be normally opened, thereby realizing the repair of the damaged PDF file.

[0045] In order to illustrate the technical solutions of the present application, the following will be described by specific embodiments.

[0046] Figure 1An implementation flow diagram of a file repairing method provided by an embodiment of the present application is shown, which can be applied to a terminal device. The terminal device can be a mobile phone, a tablet computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, etc.

[0047] Specifically, the file repairing method can include the following steps S101-S107.

[0048] In step S101, a file to be repaired is obtained.

[0049] The file to be repaired is a damaged PDF file. A PDF file usually includes a file header, a file body, a cross-reference table, a file tail, etc.

[0050] Specifically, the file header is used to identify the standard version of the PDF file.

[0051] In an embodiment of the present application, the file body is a collection of multiple object blocks, which contains objects that constitute the document in the PDF file. The object blocks in the file body can include logical object blocks and data object blocks. The logical object blocks record the association information between the object blocks, i.e., the logical object blocks contain the reference relationship between the corresponding data object blocks and the reference relationship between other logical object blocks. The data object blocks record the key data of the PDF file, such as image information, text information, font information, etc. All the logical object blocks in a complete PDF file constitute a complete logical structure tree, which can be composed of a catalog object block, pages object blocks, and page object blocks. The logical object blocks in the logical structure tree contain the reference relationship between the corresponding data object blocks.

[0052] Figure 2 An exemplary logical structure tree is shown. The catalog object block is the root node of the logical structure tree. The pages object block can be a parent node or a child node. When the pages object block can be a parent node, it can have no child node or have a child node, which can be a pages object block or a page object block. The page object block can only be a child node.

[0053] Through the logical structure tree, the data object block corresponding to any logical object block can be found, and the data recorded in the data object block can be obtained. When part of the logical data blocks in the PDF file are lost, the logical structure tree of the PDF file is no longer complete. At this time, all the data recorded in the PDF file can not be found through the logical structure tree, so that the PDF file cannot be opened and becomes a damaged PDF file.

[0054] The cross-reference table is used to record the starting position of all object blocks in the offset position in the PDF file, and the offset position represents the position of the corresponding object block in the file to be repaired.

[0055] The file trailer is used to record the offset position of the cross-reference table and the corresponding information (such as the number) of the directory object block.

[0056] In the embodiments of the present application, the terminal device can directly obtain the user input file to be repaired, or directly call the file to be repaired stored in the memory, and the present application does not limit the way of obtaining the file to be repaired.

[0057] Step S102, extracting the missing object block set in the file to be repaired.

[0058] In the file to be repaired, part of the object blocks have been lost, and the remaining object blocks are the missing object blocks, and the missing object block set is a set composed of the remaining object blocks in the file to be repaired.

[0059] In the embodiments of the present application, the terminal device can scan the file to be repaired, and when a data string of the type "nnn ggg obj... endobj" is scanned, the data string is extracted and marked as a missing object block and put into the missing object block set.

[0060] Figure 3 The content of an exemplary page object block is shown, and one page object block can include the following parts: the preceding nnn ggg are all numbers, for example Figure 3The nnn in the object block is 2, representing the number of the object block, which is used to uniquely mark an object block. The ggg is 0, representing the generation number. According to the PDF specification, when the PDF file is modified, the generation number is accumulated, and the generation number and the object number together mark whether the corresponding object block is the original object block or the modified object block. The obj and endobj are the definition range of the object block, which can be abstractly understood as a left parenthesis and a right parenthesis. The part between the obj and the endobj is any legal object specified by the PDF file, which can include, for example, booleam (Boolean), represented by the keywords true or false; numeric (numeric), including integer and real type; string (string), composed of a series of bytes between 0-255; name (name), composed of a leading / and a series of characters, with a maximum length of 127; array (array), a group of objects contained in 【】 and can be any pdf object (including array); dictionary (dictionary), a number of entries contained in << and >>, each entry is composed of key and value, where the key must be a name object, and the key in a dictionary is unique; the value can be any legal object of pdf (including dictionary object); nnn ggg R (reference), such as 2 0R, which refers to the object block 2 0obj, which is a reference syntax used to describe the association between objects. The R keyword can refer to an already defined object, or it can refer to an object that does not exist, and the effect is similar to referring to an empty object; NULL (null object), represented by null, representing empty, if the value of a key is null, the key can be ignored; if an object that does not exist is referenced, it is equivalent to referencing an empty object; stream (stream), composed of a dictionary and a series of bytes contained in the stream and endstream keywords that follow the dictionary.

[0061] In step S103, the missing object block set is parsed to obtain a missing logical object block set and a corresponding missing data object block set.

[0062] The missing logical object block set and the corresponding object block in the missing data object block set have a reference relationship.

[0063] In the embodiments of the present application, the terminal device can parse each missing object block in the missing object block set and classify it into a missing logical object block set and a corresponding missing data object block set. The missing logical object block and the corresponding missing data object block have a reference relationship, and the corresponding missing data object block can be found through the missing logical object block.

[0064] Step S104, the missing logical object block set is supplemented to obtain a complete logical object block set.

[0065] Wherein, after the missing logical object block is supplemented, all the logical object blocks in the to-be-repaired file are complete logical object blocks. The complete logical object block set is a set of all the complete logical object blocks in the to-be-repaired file.

[0066] In the embodiments of the present application, the missing logical object block records the reference relationship between the corresponding missing data object block and the reference relationship between other logical object blocks. These other logical object blocks can be the remaining logical object blocks in the to-be-repaired file, or the missing logical object blocks in the to-be-repaired file. According to the reference relationship between the missing logical object block and the missing logical object block, the missing logical object block can be supplemented to obtain all the missing logical object blocks, thereby obtaining the complete logical object block set.

[0067] For example, Figure 3 The / Parent 1 0R in the missing logical object block is the reference relationship between the missing logical object block and other logical object blocks. The reference relationship indicates that the missing logical object block has a father logical object block, which is object block 1 0obj. When the father logical object block is missing, the terminal device can supplement the father logical object block. By analogy, the terminal device can supplement the missing logical object block set according to the missing logical object block in the to-be-repaired file and the reference relationship between the missing logical object block and other object blocks, to obtain the complete logical object block set.

[0068] Step S105, modify the reference relationship of the complete logical object block in the complete logical object block set to obtain a modified complete logical object block set, and obtain a complete object block set based on the modified complete logical object block set and the missing data object block set.

[0069] It should be understood that each object block in the PDF file has a unique number to facilitate the search for the corresponding object block. The reference relationship of the logical object block records the number of the referenced object block (including logical object block and / or data object block).

[0070] In the embodiments of the present application, after the missing logical object block in the to-be-repaired file is supplemented, all object blocks in the supplemented to-be-repaired file need to be renumbered. After renumbering, the reference relationship of the logical object block needs to be modified to ensure that the modified reference relationship of the logical object block is correct. After the reference relationship of all complete logical object blocks is modified, the modified complete logical object block set is obtained. After the modified complete logical object block set is obtained, the terminal device can add the modified complete logical object block set and the missing data object block set to the complete object block set. At this time, the complete object block set includes all object blocks.

[0071] In step S106, the corresponding cross-reference table and file tail are generated based on the complete object block set.

[0072] In the embodiments of the present application, after the complete object block set (i.e., file body) is obtained, the terminal device can obtain the offset position of the complete object block in the complete object block set, obtain the cross-reference table, and then obtain the offset position of the cross-reference table to obtain the file tail.

[0073] In step S107, the repaired file is generated based on the newly created file head, complete object block set, cross-reference table, and file tail.

[0074] The repaired file is a repaired PDF file.

[0075] In the embodiments of the present application, the terminal device can create a new PDF file and a universal file head, and then input the file head, file body (complete object block set), complete object block set, cross-reference table, and file tail into the new PDF file to obtain the repaired file. The logical object block in the repaired file is complete and can form a complete logical structure tree, so that the data in the repaired file can be found, and the repaired file can be normally opened, thereby achieving the repair of the to-be-repaired file.

[0076] Compared with the prior art, the embodiment of the present application has the beneficial effects that: the embodiment of the present application obtains a to-be-repaired file, extracts a missing object block set in the to-be-repaired file, and analyzes the missing object block set to obtain a missing logical object block set and a corresponding missing data object block set, then supplements the missing logical object block set to obtain a complete logical object block set, modifies the reference relationship of the complete logical object block in the complete logical object block set to obtain a modified complete logical object block set, then obtains a complete object block set based on the modified complete logical object block set and the missing data object block set, generates a corresponding cross-reference table and a file tail based on the complete object block set, and finally generates a repaired file based on the newly created file head, the complete object block set, the cross-reference table and the file tail. The embodiment of the present application supplements the missing logical object block set to obtain the complete logical object block set, thereby supplementing the file logical structure tree of the to-be-repaired file to be complete, and then obtaining the complete object set, and obtaining the repaired file according to the complete object set. Since the file logical structure tree in the repaired file is complete, the repaired file can be normally opened, thereby realizing the repair of the damaged PDF file.

[0077] As shown in Figure 4 In some embodiments of the present application, the missing logical object block set can include a father logical object block and a child logical object block, and the supplementing of the missing logical object block set to obtain the complete logical object block set can specifically include steps S401 to S403.

[0078] Step S401: supplementing the father logical object block in the missing logical object block set.

[0079] The father logical object block is an object block corresponding to the parent node of a logical object block.

[0080] In the embodiments of the present application, in the to-be-repaired file, the parent nodes of some logical object blocks are lost, at this time, the father logical object blocks corresponding to these lost parent nodes need to be supplemented to be complete, so that each logical object block in the missing logical object block set has a parent node. Specifically, the father logical object block of the logical object block can be created according to the reference relationship of the logical object block corresponding to the child node.

[0081] For example, as shown in Figure 5 In the left graph, the page object block a is a child logical object block without a father logical object block, by supplementing the parent node of the page object block a, the pages object block A in the right graph can be obtained, which is the father logical object block of the page object block a.

[0082] Step S402: supplementing the child logical object block in the missing logical object block set.

[0083] The child logical object block is an object block corresponding to a child node of the logical object block.

[0084] In the embodiments of the present application, if the child nodes of some logical object blocks are missing in the file to be repaired, it is necessary to complete the child logical object blocks corresponding to these missing child nodes so that each logical object block in the set of missing logical object blocks has a child node. Specifically, the child logical object blocks of each logical object block can be created based on the reference relationship between the logical object blocks corresponding to the parent node.

[0085] For example, Figure 6 As shown, the pages object block B in the left figure is a father logical object block without child logical object blocks. By supplementing the child nodes of pages object block B, we can obtain the page object block b shown in the upper right figure and the pages object block A shown in the lower right figure. Page object block b and pages object block A are both child logical object blocks of pages object block B.

[0086] Step S403 : obtaining a complete logical object block set based on the missing logical object block set, the father logical object block, and the child logical object blocks.

[0087] In the embodiments of the present application, after the parent logical object block and the child logical object blocks in the missing logical object block set are supplemented, the logical object blocks in the file to be repaired are complete. The terminal device can add the missing logical object block set and the supplemented parent logical object block and child logical object blocks to the same set to form a complete logical object block set.

[0088] like Figure 7 As shown, in some embodiments of the present application, the missing logic object block set may include a page object block, and the above-mentioned supplementation of the parent logic object block in the missing logic object block set may specifically include steps S701 and S702.

[0089] Step S701 : searching for the parent logical object block of the page object block based on the parent reference relationship of the page object block.

[0090] The parent reference relationship can be used to determine the parent logical object block of the page object block. The parent reference relationship records relevant information of the parent logical object block of the page object block, such as the number of the parent logical object block.

[0091] In an embodiment of the present application, the terminal device may search for the parent logical object block of the page object block in the missing logical object block set according to the relevant information of the parent logical object block.

[0092] Step S702, when the parent logical object block of the page object block does not exist in the missing logical object block set, creating the parent logical object block of the page object block based on the parent reference relationship of the page object block.

[0093] In embodiments of the present application, when the parent logical object block of the page object block does not exist in the missing logical object block set, it means that the parent logical object block of the page object block is missing. At this time, the parent logical object block of the page object block can be created according to the parent reference relationship in the page object block.

[0094] For example, as shown in FIG. 7, if the parent logical object block of the page object block is missing, the terminal device can create a parent logical object block of the 10 obj according to the parent reference relationship ( / Parent 10R) of the page object block, set the Type field of the parent logical object block to pages, and add a child reference relationship ( / Kids 10R) and a count attribute key-value pair. Figure 3 For example, as shown in FIG. 7, if the parent logical object block of the page object block is missing, the terminal device can create a parent logical object block of the 10 obj according to the parent reference relationship ( / Parent 10R) of the page object block, set the Type field of the parent logical object block to pages, and add a child reference relationship ( / Kids 10R) and a count attribute key-value pair.

[0095] For example, as shown in FIG. 7, if the parent logical object block of the page object block is missing, the terminal device can create a parent logical object block of the 10 obj according to the parent reference relationship ( / Parent 10R) of the page object block, set the Type field of the parent logical object block to pages, and add a child reference relationship ( / Kids 10R) and a count attribute key-value pair. Figure 8 For example, as shown in FIG. 7, if the parent logical object block of the page object block is missing, the terminal device can create a parent logical object block of the 10 obj according to the parent reference relationship ( / Parent 10R) of the page object block, set the Type field of the parent logical object block to pages, and add a child reference relationship ( / Kids 10R) and a count attribute key-value pair.

[0096] Step S801, finding the parent logical object block of the pages object block based on the parent reference relationship of the pages object block.

[0097] Step S802, when the parent logical object block of the pages object block does not exist in the missing logical object block set, creating the parent logical object block of the pages object block based on the parent reference relationship of the pages object block.

[0098] The parent reference relationship can be used to determine the parent logical object block of the pages object block. The parent reference relationship records the relevant information of the parent logical object block of the pages object block, such as the number of the parent logical object block.

[0099] In embodiments of the present application, some pages object blocks also have parent logical object blocks, and the parent logical object block of the pages object block can be another pages object block. The specific steps of creating the parent logical object block of the pages object block can refer to the above steps S701 and S702, which will not be described here.

[0100] For example, as shown in FIG. 7, if the parent logical object block of the page object block is missing, the terminal device can create a parent logical object block of the 10 obj according to the parent reference relationship ( / Parent 10R) of the page object block, set the Type field of the parent logical object block to pages, and add a child reference relationship ( / Kids 10R) and a count attribute key-value pair. Figure 9As shown in the left part of the figure, the pages object block A is a child logical object block without a father logical object block. By supplementing the parent node of the pages object block A, the pages object block B in the right part of the figure can be obtained, which is the father logical object block of the pages object block A.

[0101] As shown in the left part of the figure, the pages object block A is a child logical object block without a father logical object block. By supplementing the parent node of the pages object block A, the pages object block B in the right part of the figure can be obtained, which is the father logical object block of the pages object block A. Figure 10 As shown in the left part of the figure, the pages object block A is a child logical object block without a father logical object block. By supplementing the parent node of the pages object block A, the pages object block B in the right part of the figure can be obtained, which is the father logical object block of the pages object block A.

[0102] Step S1001: finding the child logical object block of the pages object block based on the child reference relationship of the pages object block.

[0103] The child reference relationship can be used to determine the father logical object block of the pages object block, and the child reference relationship records the relevant information of the child logical object block of the pages object block, such as the number of the child logical object block.

[0104] In the embodiments of the present application, the terminal device can find the child logical object block of the pages object block in the missing logical object block set according to the relevant information of the child logical object block.

[0105] Step S1002: when the child logical object block of the pages object block does not exist in the missing logical object block set, creating the child logical object block of the pages object block based on the child reference relationship of the pages object block.

[0106] In the embodiments of the present application, when the child logical object block of the pages object block does not exist in the missing logical object block set, it means that the child logical object block of the pages object block is lost. At this time, the child logical object block of the pages object block can be created according to the child reference relationship in the pages object block.

[0107] For example, as shown in the left part of the figure, the child logical object block of the pages object block is lost. Figure 11 As shown in the left part of the figure, the child logical object block of the pages object block is lost.

[0108] As shown in the left part of the figure, the child logical object block of the pages object block is lost. Figure 12As shown, in some embodiments of the present application, the step of modifying the reference relationship of the complete logical object blocks in the complete logical object block set to obtain a modified complete logical object block set, and obtaining the complete object block set based on the modified complete logical object block set and the missing data object block set can include steps S1201 to S1203.

[0109] In step S1201, the complete logical object blocks in the complete logical object block set and the missing data object blocks in the missing data object block set are renumbered to obtain renumbered complete logical object blocks and missing data object blocks.

[0110] In embodiments of the present application, after the missing logical object blocks in the to-be-repaired file are supplemented, all object blocks in the supplemented to-be-repaired file need to be renumbered, including the extracted logical object blocks, data object blocks and supplemented logical object blocks in the to-be-repaired file.

[0111] Specifically, the terminal device can give each object block an id in the memory, and then give each object block a new number starting from 0, and record the number of each object block in a renumbering table. The renumbering table can record the previous number and the current number of each object block.

[0112] In step S1202, the reference relationship of the renumbered complete logical object blocks is modified according to the reference relationship of the complete logical object blocks before renumbering to obtain a modified complete logical object block.

[0113] In embodiments of the present application, after renumbering, since the numbers of the object blocks have changed, the reference relationship in the original logical object blocks will correspond to the new numbers of the corresponding object blocks, and at this time the logical object blocks cannot correctly reference the corresponding object blocks. The terminal device can modify the previous number of the corresponding object block in the reference relationship in the logical object block to the current number of the corresponding object block through the previous number and the current number of the object block in the renumbering table, to obtain a modified complete logical object block.

[0114] For example, it is assumed that the number of the referenced data object block in the reference relationship of a logical object block before modification is recorded as 1, and after the number of the referenced data object block is modified to 2, the number of the referenced data object block in the reference relationship of the logical object block needs to be modified to 2 to ensure that the reference relationship of the modified logical object block is correct, so that the logical object block can correctly reference the corresponding data object block.

[0115] In step S1203, the complete object block set is obtained based on the modified complete logical object block and the renumbered missing data object block.

[0116] In the embodiments of the present application, the modified complete object block and the renumbered missing data object block are put into a set, that is, a complete object block set, and the complete object block set can be regarded as a file body.

[0117] As shown in the figure, in some embodiments of the present application, the above-mentioned generation of the corresponding cross-reference table and the file tail based on the complete object block set can include steps S1301 and S1302. Figure 13

[0118] Step S1301 records the offset positions of all object blocks in the complete object block set to obtain a cross-reference table.

[0119] In the embodiments of the present application, the terminal device can output the object blocks one by one according to the new numbers of each object block after modification, and record the offset positions of all object blocks in the cross-reference table.

[0120] Step S1302 records the numbers of the directory object blocks in the complete object block set and the offset positions of the cross-reference table to obtain a file tail.

[0121] In the embodiments of the present application, when the directory object block is output, the terminal device can record the number of the directory object block in the file tail, so that the terminal device can find the offset position of the target object block in the cross-reference table according to the number of the directory object block. Meanwhile, after all object blocks are output, the cross-reference table can be output, and the offset position of the cross-reference table can be recorded in the startxref field of the file tail.

[0122] Figure 14 A structure schematic diagram of a file repair device provided by an embodiment of the present application is shown, and the above-mentioned file repair device 14 can be configured on a terminal device. Specifically, the above-mentioned file repair device 14 can include:

[0123] The first acquisition module 1401 is configured to acquire a to-be-repaired file, and the to-be-repaired file is a damaged PDF file.

[0124] The extraction module 1402 is configured to extract a missing object block set in the to-be-repaired file, and the missing object block set is a set composed of the remaining object blocks in the to-be-repaired file.

[0125] The analysis module 1403 is configured to analyze the missing object block set to obtain a missing logical object block set and a corresponding missing data object block set, wherein the missing logical object block set and the corresponding object block in the missing data object block set have a reference relationship.

[0126] The supplement module 1404 is configured to supplement the missing logical object block set to obtain a complete logical object block set.​

[0127] The modification module 1405 is configured to modify the reference relationship of the complete logical object blocks in the complete logical object block set to obtain a modified complete logical object block set, and obtain the complete object block set based on the modified complete logical object block set and the missing data object block set.

[0128] The first generation module 1406 is configured to generate a corresponding cross-reference table and a file tail based on the complete object block set.

[0129] The second generation module 1407 is configured to generate a repaired file based on the newly created file header, the complete object block set, the cross-reference table and the file tail, and the repaired file is a repaired PDF file.

[0130] Compared with the prior art, the embodiments of the present application have the beneficial effects that: the embodiments of the present application obtain a to-be-repaired file, extract a missing object block set in the to-be-repaired file, analyze the missing object block set to obtain a missing logical object block set and a corresponding missing data object block set, supplement the missing logical object block set to obtain a complete logical object block set, modify the reference relationship of the complete logical object blocks in the complete logical object block set to obtain a modified complete logical object block set, obtain the complete object block set based on the modified complete logical object block set and the missing data object block set, generate a corresponding cross-reference table and a file tail based on the complete object block set, and finally generate a repaired file based on the newly created file header, the complete object block set, the cross-reference table and the file tail. The embodiments of the present application supplement the missing logical object block set to obtain the complete logical object block set, thereby supplementing the file logical structure tree of the to-be-repaired file to be complete, and then obtaining the complete object set, and generating the repaired file according to the complete object set. Since the file logical structure tree in the repaired file is complete, the repaired file can be normally opened, thereby realizing the repair of the damaged PDF file.

[0131] In some embodiments of the present application, the missing logical object block set includes a father logical object block and a child logical object block, and the supplement module 1404 is further configured to: supplement the father logical object block in the missing logical object block set; supplement the child logical object block in the missing logical object block set; and obtain the complete logical object block set based on the missing logical object block set, the father logical object block and the child logical object block.

[0132] In some embodiments of the application, the set of missing logical object blocks includes a page object block, and the supplementing module 1404 is further configured to: find a parent logical object block of the page object block based on a parent reference relationship of the page object block; and create the parent logical object block of the page object block based on the parent reference relationship of the page object block when the parent logical object block of the page object block does not exist in the set of missing logical object blocks.

[0133] In some embodiments of the application, the set of missing logical object blocks includes a pages object block, and the supplementing module 1404 is further configured to: find a parent logical object block of the pages object block based on a parent reference relationship of the pages object block; and create the parent logical object block of the pages object block based on the parent reference relationship of the pages object block when the parent logical object block of the pages object block does not exist in the set of missing logical object blocks.

[0134] In some embodiments of the application, the set of missing logical object blocks includes a pages object block, and the supplementing module 1404 is further configured to: find a child logical object block of the pages object block based on a child reference relationship of the pages object block; and create the child logical object block of the pages object block based on the child reference relationship of the pages object block when the child logical object block of the pages object block does not exist in the set of missing logical object blocks.

[0135] In some embodiments of the application, the modifying module 1405 is further configured to: renumber the complete logical object blocks in the set of complete logical object blocks and the missing data object blocks in the set of missing data object blocks to obtain renumbered complete logical object blocks and missing data object blocks; modify reference relationships of the renumbered complete logical object blocks based on reference relationships of the complete logical object blocks before renumbering to obtain modified complete logical object blocks; and obtain the set of complete object blocks based on the modified complete logical object blocks and the renumbered missing data object blocks.

[0136] In some embodiments of the application, the first generating module 1406 is further configured to: record offset positions of all object blocks in the set of complete object blocks to obtain a cross-reference table; and record a number of a directory object block in the set of complete object blocks and an offset position of the cross-reference table to obtain a file tail.

[0137] As Figure 15As shown, a schematic diagram of a terminal device provided by an embodiment of the present application is shown. The terminal device 15 can include a processor 1501, a memory 1502, and a computer program 1503 stored in the memory 1502 and executable on the processor 1501, for example, a file repair program. The processor 1501 implements the steps in the above various file repair method embodiments when executing the computer program 1503, for example Figure 1 The steps S101 to S107 shown. Alternatively, the processor 1501 implements the functions of each module / unit in the above various device embodiments when executing the computer program 1503, for example Figure 14 The first acquisition module 1401, the extraction module 1402, the parsing module 1403, the supplement module 1404, the modification module 1405, the first generation module 1406, and the second generation module 1407 shown.

[0138] The computer program can be divided into one or more modules / units, which are stored in the memory 1502 and executed by the processor 1501 to complete the present application. The one or more modules / units can be a series of computer program instruction segments capable of completing a specific function, which are used to describe the execution process of the computer program in the terminal device.

[0139] The terminal device can include, but is not limited to, the processor 1501 and the memory 1502. Those skilled in the art can understand that Figure 15 It is only an example of the terminal device and does not constitute a limitation on the terminal device, which can include more or fewer components than shown, or combine certain components, or different components, for example, the terminal device can also include an input / output device, a network access device, a bus, etc.

[0140] The processor 1501 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.

[0141] The memory 1502 can be an internal storage unit of the terminal device, for example, a hard disk or a memory of the terminal device. The memory 1502 can also be an external storage device of the terminal device, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device. Further, the memory 1502 can include both the internal storage unit and the external storage device of the terminal device. The memory 1502 is used to store the computer program and other programs and data required by the terminal device. The memory 1502 can also be used to temporarily store data that has been output or will be output.

[0142] It should be noted that, for the convenience and brevity of description, the structure of the terminal device can also refer to the specific description of the structure in the method embodiments, which will not be described here.

[0143] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above functional units and modules is exemplified, and in actual application, the above functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of software functional unit. In addition, the specific name of each functional unit and module is only for easy distinction, and does not limit the protection scope of the present application. The specific working process of the unit and module in the system can refer to the corresponding process in the foregoing method embodiments, which will not be described here.

[0144] The embodiment of the present application also provides a computer readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the file repair method described above can be implemented.

[0145] The embodiment of the present application provides a computer program product. When the computer program product is run on a mobile terminal, the mobile terminal can execute the steps of the file repair method described above.

[0146] In the above embodiments, the description of each embodiment has its own emphasis, and the parts not described or recorded in detail in a certain embodiment can be referred to the related description of other embodiments.

[0147] Those skilled in the art can understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0148] In the embodiments provided by the present application, it should be understood that the disclosed apparatus / terminal device and method can be implemented in other ways. For example, the apparatus / terminal device embodiments described above are merely schematic, and the division of the modules or units is merely a logical function division, and there can be another division manner in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between the units can be indirect couplings or communication connections through some interfaces, devices or units, and can be electrical, mechanical or in other forms.

[0149] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. can be located in one place, or can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.

[0150] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically independently, or two or more units can be integrated into one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.

[0151] The integrated module / unit, if implemented in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the above-mentioned embodiment methods can also be completed by a computer program instructing related hardware, and the computer program can be stored in a computer readable storage medium. The computer program can implement the steps of each method embodiment when executed by a processor. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or some intermediate forms. The computer readable medium can 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), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the contents included in the computer readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, the computer readable medium does not include electrical carrier signals and telecommunication signals.

[0152] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.

Claims

1. A method for repairing a file, characterized in that: include: Obtaining a file to be repaired, where the file to be repaired is a damaged PDF file; Extracting a missing object block set from the file to be repaired, where the missing object block set is a set consisting of remaining object blocks in the file to be repaired; Parsing the missing object block set to obtain a missing logical object block set and a corresponding missing data object block set, wherein a reference relationship exists between the missing logical object block set and the corresponding object blocks in the missing data object block set; Supplementing the missing logical object block set to obtain a complete logical object block set; Modifying the reference relationship of the complete logical object blocks in the complete logical object block set to obtain a modified complete logical object block set, and obtaining a complete object block set based on the modified complete logical object block set and the missing data object block set; generating a corresponding cross-reference table and a file trailer based on the complete object block set; A repair file is generated based on the newly created file header, the complete object block set, the cross-reference table, and the file tail, where the repair file is a repaired PDF file.

2. The file repair method according to claim 1, characterized in that: The missing logical object block set includes a father logical object block and a child logical object block, and the missing logical object block set is supplemented to obtain a complete logical object block set, including: Supplementing the father logical object block in the missing logical object block set; Supplementing the child logical object blocks in the missing logical object block set; A complete logical object block set is obtained based on the missing logical object block set, the father logical object block, and the child logical object block.

3. The file repair method according to claim 2, characterized in that: The missing logical object block set includes page object blocks, and the step of supplementing the parent logical object block in the missing logical object block set includes: Find the parent logical object block of the page object block based on the parent reference relationship of the page object block; When the parent logical object block of the page object block does not exist in the missing logical object block set, the parent logical object block of the page object block is created based on the parent reference relationship of the page object block.

4. The file repair method according to claim 2, wherein: The missing logical object block set includes pages object blocks, and the method of supplementing the father logical object block in the missing logical object block set further includes: Finding the parent logical object block of the pages object block based on the parent reference relationship of the pages object block; When the parent logical object block of the pages object block does not exist in the missing logical object block set, the parent logical object block of the pages object block is created based on the parent reference relationship of the pages object block.

5. The file repair method according to claim 2, wherein: The missing logical object block set includes pages object blocks, and the step of supplementing the child logical object blocks in the missing logical object block set includes: Finding the child logical object blocks of the pages object block based on the child reference relationship of the pages object block; When the missing logical object block set does not contain a child logical object block of the pages object block, a child logical object block of the pages object block is created based on the child reference relationship of the pages object block.

6. The file repair method according to claim 1, wherein: The step of modifying the reference relationship of the complete logical object blocks in the complete logical object block set to obtain a modified complete logical object block set, and obtaining a complete object block set based on the modified complete logical object block set and the missing data object block set, includes: renumbering the complete logical object blocks in the complete logical object block set and the missing data object blocks in the missing data object block set to obtain renumbered complete logical object blocks and missing data object blocks; Modifying the reference relationship of the complete logical object block after renumbering according to the reference relationship of the complete logical object block before renumbering, to obtain a modified complete logical object block; A complete object block set is obtained based on the modified complete logical object block and the renumbered missing data object blocks.

7. The file repair method according to claim 1, characterized in that: Generating a corresponding cross-reference table and a file trailer based on the complete object block set includes: Recording the offset positions of all object blocks in the complete object block set to obtain the cross-reference table; The numbers of the directory object blocks in the complete object block set and the offset positions of the cross-reference table are recorded to obtain the file tail.

8. A file repair device, characterized in that: include: A first acquisition module is used to acquire a file to be repaired, where the file to be repaired is a damaged PDF file; an extraction module, configured to extract a set of missing object blocks from the file to be repaired, wherein the set of missing object blocks is a set of remaining object blocks in the file to be repaired; a parsing module, configured to parse the missing object block set to obtain a missing logical object block set and a corresponding missing data object block set, wherein a reference relationship exists between the missing logical object block set and the corresponding object blocks in the missing data object block set; A supplementing module, configured to supplement the missing logical object block set to obtain a complete logical object block set; a modification module, configured to modify the reference relationship of the complete logical object blocks in the complete logical object block set to obtain a modified complete logical object block set, and obtain a complete object block set based on the modified complete logical object block set and the missing data object block set; A first generating module, configured to generate a corresponding cross-reference table and a file trailer based on the complete object block set; The second generating module is used to generate a repair file based on the newly created file header, the complete object block set, the cross-reference table and the file tail, where the repair file is a repaired PDF file.

9. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the file repair method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the file repair method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • PDF document recovery device and method

    CN105956477A

  • PDF (Portable Document Format) repairing method based on non-standard mapping fonts, storage medium and equipment

    CN114529930A