Method, device, computer equipment and storage medium for editing PDF files
There is provided a device for editing a PDF file, including a display, a non-volatile storage medium, a memory and a processor. The non-volatile storage medium stores a computer program. The memory provides an environment for operations of the computer program in the non-volatile storage medium. The processor runs the computer program to parse the PDF file to obtain information of characters, generate character sets according to features of the characters, generate line sets according to heights and horizontal positions of the character sets, generate paragraph sets according to a height and a horizontal position of each line of the line sets, generate text region sets according a height and a horizontal position of each paragraph of the paragraph sets, and control the display to show the text region sets in the PDF file as editable text regions.
1 . A method for recognizing a portable document format (PDF) file, comprising:
parsing text objects of the PDF file to obtain information of characters;
identifying features of adjacent characters in a horizontal direction, and merging characters having identical features to obtain character sets, wherein one character set is generated upon encountering a space, which indicates a feature change;
determining line sets according to first vertical pitches and first horizontal pitches of adjacent character sets to group the adjacent character sets within a first predetermined height distance and within a first predetermined horizontal distance as one line set using corresponding points of boundaries of the adjacent character sets;
determining paragraph sets according to second vertical pitches and second horizontal pitches of adjacent lines of the line sets to group adjacent line sets within a second predetermined height distance and within a second predetermined horizontal distance as one paragraph set using corresponding points of boundaries of the adjacent line sets;
determining text region sets according to third vertical pitches and third horizontal pitches of adjacent paragraphs of the paragraph sets;
calculating an intersection set of boundaries of all characters in the character sets to obtain first set boundaries of the character sets, wherein the first set boundaries are configured for a processor to sequentially store every character set in a memory using a self-defining data structure;
calculating an intersection set of boundaries of all character sets in each line of the line sets to obtain a second set boundary of said each line, wherein the second set boundaries are configured for the processor to sequentially store every line set in the memory using the self-defining data structure; and
calculating an intersection set of boundaries of all lines in each paragraph of the paragraph sets to obtain a third set boundary of said each paragraph, wherein the third set boundaries are configured for the processor to sequentially store every paragraph set in the memory using the self-defining data structure,
wherein in the self-defining data structure stored in the memory, information of said each line comprises information of the all character sets therein plus a coordinate of a line boundary of said each line, and information of said each paragraph comprises information of all lines therein plus a coordinate of a paragraph boundary of said each paragraph.
2 . The method as claimed in claim 1 , further comprising:
parsing graphic objects of the PDF file and taking each picture as a graphic region.
3 . The method as claimed in claim 1 , wherein
the first vertical pitches and the first horizontal pitches are calculated according to two corresponding points of two first set boundaries of the adjacent character sets;
the second vertical pitches and the second horizontal pitches are calculated according to two corresponding points of two second set boundaries of the adjacent lines of the line sets; and
the third vertical pitches and the third horizontal pitches are calculated according to two corresponding points of two third set boundaries of the adjacent paragraphs of the paragraph sets.
4 . The method as claimed in claim 1 , further comprising:
sequentially arranging the all character sets of the PDF file from top to bottom and from left to right according to lower sides of the first set boundaries of the every character set;
sequentially arranging all lines of the PDF file from top to bottom and from left to right according to lower sides of the second set boundaries of every line; and
sequentially arranging all paragraphs of the PDF file from top to bottom and from left to right according to lower sides of the third set boundaries of every paragraph.
5 . The method as claimed in claim 1 , wherein the features comprise a font, a size and a color of the characters.
6 . A device configured to provide an editable PDF file, the device comprising:
a display, configured to show a PDF file;
a non-volatile storage medium, configured to record a computer program;
a memory, configured to provide an environment for operations of the computer program in the non-volatile storage medium; and
a processor, configured to
run the computer program to parse the PDF file to obtain information of characters,
generate character sets according to features of the characters, wherein one character set is generated upon encountering a space, which indicates a feature change,
generate line sets according to heights and horizontal positions of the character sets to group adjacent character sets within a first predetermined height distance and within a first predetermined horizontal distance as one line set using corresponding points of boundaries of the adjacent character sets,
generate paragraph sets according to a height and a horizontal position of each line of the line sets to group adjacent line sets within a second predetermined height distance and within a second predetermined horizontal distance as one paragraph set using corresponding points of boundaries of the adjacent line sets,
generate text region sets according to a height and a horizontal position of each paragraph of the paragraph sets,
calculate an intersection set of boundaries of all characters in the character sets to obtain first set boundaries of the character sets, wherein the first set boundaries are configured for a processor to sequentially store every character set in the memory using a self-defining data structure,
calculate an intersection set of boundaries of all character sets in each line of the line sets to obtain a second set boundary of said each line, wherein the second set boundaries are configured for the processor to sequentially store every line set in the memory using the self-defining data structure,
calculate an intersection set of boundaries of all lines in each paragraph of the paragraph sets to obtain a third set boundary of said each paragraph, wherein the third set boundaries are configured for the processor to sequentially store every paragraph set in the memory using the self-defining data structure, and
control the display to show the text region sets as editable text regions in the PDF file,
wherein in the self-defining data structure stored in the memory, information of said each line comprises information of the all character sets therein plus a coordinate of a line boundary of said each line, and information of said each paragraph comprises information of all lines therein plus a coordinate of a paragraph boundary of said each paragraph.
7 . The device as claimed in claim 6 , wherein the processor is further configured to
parse graphic objects in the PDF file and take each picture parsed from the PDF file as one graphic region, and
control the display to show the one graphic region as an editable graphic region in the PDF file.
8 . A computer equipment, comprising
a storage device, configured to record a computer program; and
a processor, configured to run the computer program recorded in the storage device to perform a method for recognizing a PDF file, comprising:
parsing text objects of the PDF file to obtain information of characters;
identifying features of adjacent characters in a horizontal direction, and merging characters having identical features to obtain character sets, wherein one character set is generated upon encountering a space, which indicates a feature change;
determining line sets according to first vertical pitches and first horizontal pitches of adjacent character sets to group the adjacent character sets within a first predetermined height distance and within a first predetermined horizontal distance as one line set using corresponding points of boundaries of the adjacent character sets;
determining paragraph sets according to second vertical pitches and second horizontal pitches of adjacent lines of the line sets to group adjacent line sets within a second predetermined height distance and within a second predetermined horizontal distance as one paragraph set using corresponding points of boundaries of the adjacent line sets;
determining text region sets according to third vertical pitches and third horizontal pitches of adjacent paragraphs of the paragraph sets;
calculating an intersection set of boundaries of all characters in the character sets to obtain first set boundaries of the character sets, wherein the first set boundaries are configured for a processor to sequentially store every character set in a memory using a self-defining data structure;
calculating an intersection set of boundaries of all character sets in each line of the line sets to obtain a second set boundary of said each line, wherein the second set boundaries are configured for the processor to sequentially store every line set in the memory using the self-defining data structure; and
calculating an intersection set of boundaries of all lines in each paragraph of the paragraph sets to obtain a third set boundary of said each paragraph, wherein the third set boundaries are configured for the processor to sequentially store every paragraph set in the memory using the self-defining data structure,
wherein in the self-defining data structure stored in the memory, information of said each line comprises information of the all character sets therein plus a coordinate of a line boundary of said each line, and information of said each paragraph comprises information of all lines therein plus a coordinate of a paragraph boundary of said each paragraph.
9 . The computer equipment as claimed in claim 8 , wherein the method further comprises:
parsing graphic objects of the PDF file and taking each picture as a graphic region.
10 . The computer equipment as claimed in claim 8 , wherein
the first vertical pitches and the first horizontal pitches are calculated according to two corresponding points of two first set boundaries of the adjacent character sets;
the second vertical pitches and the second horizontal pitches are calculated according to two corresponding points of two second set boundaries of the adjacent lines of the line sets; and
the third vertical pitches and the third horizontal pitches are calculated according to two corresponding points of two third set boundaries of the adjacent paragraphs of the paragraph sets.
11 . The computer equipment as claimed in claim 8 , wherein the method further comprises:
sequentially arranging the all character sets of the PDF file from top to bottom and from left to right according to lower sides of the first set boundaries of the every character set;
sequentially arranging all lines of the PDF file from top to bottom and from left to right according to lower sides of the second set boundaries of every line; and
sequentially arranging all paragraphs of the PDF file from top to bottom and from left to right according to lower sides of the third set boundaries of every paragraph.
12 . The computer equipment as claimed in claim 8 , wherein the features comprise a font, a size and a color of the characters.
13 . A non-transitory content accessible memory, the non-transitory content accessible memory being recorded with a computer program, wherein the computer program is run by a processor to perform a method for recognizing a PDF file, comprising:
parsing text objects of the PDF file to obtain information of characters;
identifying features of adjacent characters in a horizontal direction, and merging characters having identical features to obtain character sets, wherein one character set is generated upon encountering a space, which indicates a feature change;
determining line sets according to first vertical pitches and first horizontal pitches of adjacent character sets to group the adjacent character sets within a first predetermined height distance and within a first predetermined horizontal distance as one line set using corresponding points of boundaries of the adjacent character sets;
determining paragraph sets according to second vertical pitches and second horizontal pitches of adjacent lines of the line sets to group adjacent line sets within a second predetermined height distance and within a second predetermined horizontal distance as one paragraph set using corresponding points of boundaries of the adjacent line sets;
determining text region sets according to third vertical pitches and third horizontal pitches of adjacent paragraphs of the paragraph sets;
calculating an intersection set of boundaries of all characters in the character sets to obtain first set boundaries of the character sets, wherein the first set boundaries are configured for a processor to sequentially store every character set in the content accessible memory using a self-defining data structure;
calculating an intersection set of boundaries of all character sets in each line of the line sets to obtain a second set boundary of said each line, wherein the second set boundaries are configured for the processor to sequentially store every line set in the content accessible memory using the self-defining data structure; and
calculating an intersection set of boundaries of all lines in each paragraph of the paragraph sets to obtain a third set boundary of said each paragraph, wherein the third set boundaries are configured for the processor to sequentially store every paragraph set in the content accessible memory using the self-defining data structure,
wherein in the self-defining data structure stored in the content accessible memory, information of said each line comprises information of the all character sets therein plus a coordinate of a line boundary of said each line, and information of said each paragraph comprises information of all lines therein plus a coordinate of a paragraph boundary of said each paragraph.
14 . The content accessible memory as claimed in claim 13 , wherein the method further comprises:
parsing graphic objects of the PDF file and taking each picture as a graphic region.
15 . The content accessible memory as claimed in claim 13 , wherein
the first vertical pitches and the first horizontal pitches are calculated according to two corresponding points of two first set boundaries of the adjacent character sets;
the second vertical pitches and the second horizontal pitches are calculated according to two corresponding points of two second set boundaries of the adjacent lines of the line sets; and
the third vertical pitches and the third horizontal pitches are calculated according to two corresponding points of two third set boundaries of the adjacent paragraphs of the paragraph sets.
16 . The content accessible memory as claimed in claim 13 , wherein the method further comprises:
sequentially arranging the all character sets of the PDF file from top to bottom and from left to right according to lower sides of the first set boundaries of the every character set;
sequentially arranging all lines of the PDF file from top to bottom and from left to right according to lower sides of the second set boundaries of every line; and
sequentially arranging all paragraphs of the PDF file from top to bottom and from left to right according to lower sides of the third set boundaries of every paragraph.
17 . The content accessible memory as claimed in claim 13 , wherein the features comprise a font, a size and a color of the characters.