ePub file format conversion method, device, equipment and readable storage medium
By automatically processing file content and generating ePub format files, the problem of complex and inefficient ePub format conversion in the existing technology is solved, and efficient conversion and content integrity of multi-format files are achieved.
Patent Information
- Application Number
- CN202111406312.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-24
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2041-11-24
AI Technical Summary
The existing ePub format file conversion process is complex and inefficient, easily loses file content, and requires a lot of manual participation.
By obtaining the content of the file to be converted, performing keyword filtering and splitting text elements and image elements, generating a directory of chapters and a directory of contents, and generating an ePub format file based on the directory combination, the algorithm is used for automatic conversion.
It realizes the automatic conversion of multi-format files, reduces manual processing, improves conversion efficiency, and ensures the integrity of file content.
Smart Images

Figure CN114116603B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to an ePub file format conversion method, device, equipment and readable storage medium. Background Art
[0002] ePub (Electronic Publication) is a free, open standard for content that can be "automatically re-formatted," meaning that text can be displayed in the most suitable format based on the characteristics of the reading device. Therefore, many reading clients currently only support ePub files, requiring users to convert other formats to ePub before uploading.
[0003] Currently, the conversion of ePub format files involves complex calculations and code conversion. Not only is the process cumbersome, but it is also prone to loss of file content. It also requires a lot of manual participation, resulting in very low efficiency. Summary of the Invention
[0004] To solve the above technical problems, the present invention provides an ePub file format conversion method, device, equipment and readable storage medium, which are compatible with multi-format file conversion, reduce manual processing and improve conversion efficiency.
[0005] One aspect of the present invention provides a method for converting an ePub file format, comprising:
[0006] Get the file content contained in the file to be converted;
[0007] Perform keyword filtering on the file content to obtain filtered file content;
[0008] Splitting the text elements and image elements in the filtered file content, and generating a directory of chapters and a directory of contents corresponding to the directory of chapters;
[0009] The text elements and the image elements are combined according to the chapter directory and the content directory to generate an ePub format file.
[0010] Preferably, the keyword filtering of the file content to obtain filtered file content includes:
[0011] Comparing the words in the document content with the keywords in the preset corpus one by one to obtain similarity comparison results;
[0012] The words that meet the preset conditions in the similarity comparison results are replaced with random characters to obtain the filtered file content.
[0013] Preferably, after performing keyword filtering on the file content to obtain filtered file content, the method further includes:
[0014] The filtered file content is parsed to obtain the file encoding and file size corresponding to the filtered file content.
[0015] Preferably, the combining of the text elements and the image elements according to the chapter directory and the content directory to generate an ePub format file includes:
[0016] According to the chapter directory and the content directory, the text element and the image element are placed into a preset HTML template to generate an HTML format file;
[0017] Generate an ePub format file based on the HTML format file.
[0018] Preferably, the method further comprises:
[0019] An image that meets a preset rule is selected from the image elements to generate a cover for the ePub format file.
[0020] Another aspect of the present invention provides an ePub file format conversion device, comprising:
[0021] An acquisition module is used to obtain the file content contained in the file to be converted;
[0022] A filtering module, configured to filter the file content by keywords to obtain filtered file content;
[0023] A splitting module, configured to split the text elements and image elements in the filtered file content, and generate a directory of chapters and a directory of contents corresponding to the directory of chapters;
[0024] A combining module is used to combine the text elements and the image elements according to the chapter directory and the content directory to generate an ePub format file.
[0025] Preferably, the device further comprises:
[0026] The parsing module is used to parse the filtered file content to obtain the file encoding and file size corresponding to the filtered file content.
[0027] Preferably, the device further comprises:
[0028] The generating module is used to select images that meet preset rules from the image elements and generate the cover of the ePub format file.
[0029] Another aspect of the present invention provides an ePub file format conversion device, comprising:
[0030] memory for storing computer programs;
[0031] A processor is configured to implement the steps of any one of the above-described methods for converting ePub file format when executing the computer program.
[0032] Yet another aspect of the present invention provides a readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program implements the steps of any one of the above-mentioned methods for converting ePub file format.
[0033] The present invention has at least the following beneficial effects:
[0034] The present invention obtains the file content contained in the file to be converted, then filters the file content by keywords to obtain the filtered file content, then splits the text elements and image elements in the filtered file content, and generates a directory of chapters and a content directory corresponding to the directory of chapters. Finally, according to the directory of chapters and the content directory, the text elements and image elements are combined to generate an ePub format file. In this way, it is compatible with multi-format file uploads and can be automatically and uniformly converted into ePub format files that can be read by the front end through an algorithm, which reduces manual processing and improves conversion efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0036] Figure 1 A flowchart of a method for converting ePub file format provided by an embodiment of the present invention;
[0037] Figure 2 A schematic diagram of a process flow of an ePub file format conversion device provided by an embodiment of the present invention;
[0038] Figure 3 A schematic diagram of the structure of an ePub file format conversion device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0039] The core of the present invention is to provide an ePub file format conversion method, device, equipment and readable storage medium, which can automatically convert the file format through an algorithm, reduce manual processing, improve conversion efficiency, and at the same time do not require the use of other format conversion software for processing, and can be compatible with multi-format file conversion.
[0040] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0041] See also Figure 1 In one aspect, an embodiment of the present invention provides a method for converting an ePub file format, comprising:
[0042] S110: Obtain the file content contained in the file to be converted.
[0043] In the embodiment of the present invention, the file to be converted can be an electronic document in any format, such as txt, pdf, docx, html, etc. After the file to be converted is uploaded to the file processing server, the data in the file to be converted is read and parsed to obtain the file content contained in the file to be converted.
[0044] S120: Filter the file content by keywords to obtain filtered file content.
[0045] In the embodiment of the present invention, the file content contained in the file to be converted may contain sensitive content, etc., and it is necessary to perform keyword filtering on the file content through a filtering algorithm to obtain a clean version of the file content after filtering.
[0046] S130: Split the text elements and image elements in the filtered file content, and generate a directory of chapters and a directory of contents corresponding to the directory of chapters.
[0047] In this embodiment of the present invention, since electronic documents often contain not only text but also images, and text and images have different properties, a splitting algorithm is used to separate the text elements and image elements in the filtered file content, generating a text element set and an image element set, respectively, which are then stored on the file server. Furthermore, to ensure that the relative positions of the text and image elements remain the same before and after file conversion, a directory and chapter arrangement algorithm is used to generate a table of contents and a corresponding table of contents.
[0048] S140 , combining text elements and image elements according to the chapter directory and the content directory to generate an ePub format file.
[0049] In an embodiment of the present invention, based on the chapter directory and the content directory corresponding to the chapter directory, text elements and image elements can be combined through a file combination algorithm and written into an ePub file to generate an ePub format file for the front end to open and read.
[0050] As can be seen from the above, the embodiment of the present invention obtains the file content contained in the file to be converted, then performs keyword filtering on the file content to obtain the filtered file content, then splits the text elements and image elements in the filtered file content, and generates a chapter directory and a content directory corresponding to the chapter directory. Finally, according to the chapter directory and the content directory, the text elements and image elements are combined to generate an ePub format file. In this way, it is compatible with multi-format file uploads and can be automatically and uniformly converted into ePub format files that can be read by the front-end through an algorithm, reducing manual processing and improving conversion efficiency.
[0051] Optionally, in some embodiments of the present invention, step S120 specifically includes:
[0052] Compare the words in the document content with the keywords in the preset corpus one by one to obtain the similarity comparison results;
[0053] The words that meet the preset conditions in the similarity comparison results are replaced with random characters to obtain the filtered file content.
[0054] In an embodiment of the present invention, keywords such as sensitive content can be manually annotated based on a model method to form a preset corpus. Initialize the vocabulary set repList that needs to be filtered. Model the file content that needs to be filtered at the word level, convert each word in the file content into a vector, and perform a similarity comparison between each word and the keywords in the preset corpus to obtain a similarity comparison result. When the similarity comparison result meets the preset conditions, such as the similarity is greater than 90%, the word and the word position are taken out and stored in the repList. Traverse the repList and replace all the words in the repList with random characters, such as "*". Finally, replace the repList with the file content to obtain the filtered file content.
[0055] Optionally, in some embodiments of the present invention, after step S120, the method further includes:
[0056] Parse the filtered file content to obtain the file encoding and file size corresponding to the filtered file content.
[0057] In an embodiment of the present invention, the text encoding automatic detection technology cpdetector can be used to parse the filtered file content. Specifically, a detector proxy CodepageDetectorProxy is created, and ParsingDetector is loaded for encoding measurement of files such as html; ASCIIDetector is loaded for ASCII encoding measurement; UnicodeDetector is loaded for Unicode family encoding measurement; JChardetFacade is loaded for encoding measurement of files such as txt, pdf, and docx; the encoding measurement logic is executed through the detector proxy CodepageDetectorProxy to obtain the file encoding corresponding to the filtered file content. At the same time, a file object stream is created based on the filtered file content, and the readable data size in the stream is obtained based on the file object stream to obtain the file size corresponding to the filtered file content.
[0058] In specific implementation, for files of different formats to be converted, different splitting algorithms are used when splitting text elements and image elements, which are explained below with examples.
[0059] Taking docx files as an example, SWPF technology can be used to separate text and image elements from the filtered file content. Specifically, create a file parser XWPFParagraph; use it to parse the filtered file content to obtain an element list; initialize the image collection pics and the text collection texts; traverse the element list to determine whether the element node is a CTDrawing or CTPicture image node. If so, save the image node and its location information to the pics collection; if not, save the text node and its location information to the texts collection; traverse the image collection pics, upload the images in the pics collection to the file server, and update the image path information in the pics collection.
[0060] Taking a PDF file as an example, the Spire.PDF technology can be used to split the text elements and image elements in the filtered file content. Specifically, create a PDF document instance PdfDocument, initialize the image collection pics and the text collection texts; traverse all pages of the PDF file, query each page page; execute page to extract all images extractImages, and save the images and the image page position information to the collection pics; execute page to extract all text extractText, and save the text and the text page position information to the collection texts; traverse the image collection pics, upload the images in the collection pics to the file server, and update the path information of the images in the collection pics.
[0061] Specifically, when generating the chapter directory and the content directory corresponding to the chapter directory, first set the chapter regular expression, such as (^ / / s*第)(.{1,9})[章节卷集部篇回]( / / s*)(.*)( / n| / r| / r / n), initialize the chapter directory collection as dirs, and the content directory collection corresponding to the chapter directory as dirContents; according to the regular expression, obtain the content directory, chapter content and position from the text data in the texts collection; if the obtained directory and chapter information is empty, split the content into segments at a fixed number of words, such as 3000 words, starting from the initial position (0, 3000) of the text content. Determine whether the last character of the intercepted segment is a sentence end symbol (such as a period, a question mark, etc.). If so, the directory chapter is the first 15 characters of the intercepted segment. Otherwise, continue to traverse the content under the directory chapter until a sentence end symbol or a text end symbol is encountered. Define the end symbol position as len, and the next iterative split segment as (len, len + 3000). Store the chapter directory in the collection dirs; traverse the collection dirs, intercept the string according to the chapter directory position information of the text content, and the obtained string is the content corresponding to the directory chapter, and store the content in the collection dirContents.
[0062] Optionally, in some embodiments of the present invention, step S140 specifically includes:
[0063] Put the text elements and image elements into a preset HTML template according to the chapter directory and the content directory, and generate an HTML format file;
[0064] Generate an ePub format file according to the HTML format file.
[0065] In an embodiment of the present invention, an ePub HTML template model can be pre-set, wherein the template model includes Css and js, Css is used for page layout rendering, and js is used for page logic processing; the ePub html collection model is initialized; dirContents is traversed to define each chapter dir, the chapter content dirContent, and the picture pic at the corresponding position in the content; dir, dirContent, and pic are stored in the specified template model, an ePub html file is generated, and stored in htmls; using ePublib technology; an ePub book object book is created; dirs and htmls information is written into book; ePubWriter is used to write book into the ePub file to generate an ePub format file.
[0066] Optionally, in some embodiments of the present invention, after step S140, the method further includes:
[0067] Select images that meet the preset rules from the image elements and generate the cover of the ePub format file.
[0068] In an embodiment of the present invention, a file retrieval algorithm can be used to select the image with the largest weight among the image elements as the cover of the ePub format file. Specifically, the algorithm traverses pics, initializes the weight value of each image pic to w, sets the size of pics to k, and sets the weight of pics to ws. The number of times pic appears in the file is retrieved, n, and the weight of pic is updated to w = n / k. The current weight value w of pic is updated to the set ws. The weight set ws is sorted, and the image pic with the largest weight is selected as the cover of the current ePub format file. If the weight values in the weight set ws are consistent, the first image in the set pics is selected as the cover image and used as the cover of the ePub format file.
[0069] Another embodiment of the present invention provides an ePub file format conversion device, comprising:
[0070] An acquisition module 210 is used to acquire the file content contained in the file to be converted;
[0071] The filtering module 220 is used to filter the file content by keywords to obtain the filtered file content;
[0072] A splitting module 230 is used to split the text elements and image elements in the filtered file content and generate a directory of chapters and a directory of contents corresponding to the directory of chapters;
[0073] The combining module 240 is used to combine text elements and image elements according to the chapter directory and the content directory to generate an ePub format file.
[0074] Optionally, in some embodiments of the present invention, the filtering module 220 includes:
[0075] A comparison unit is used to compare the words in the document content with the keywords in the preset corpus one by one to obtain similarity comparison results;
[0076] The replacement unit is used to replace the words that meet the preset conditions in the similarity comparison results with random characters to obtain the filtered file content.
[0077] Optionally, in some embodiments of the present invention, the device further comprises:
[0078] The parsing module is used to parse the filtered file content to obtain the file encoding and file size corresponding to the filtered file content.
[0079] Optionally, in some embodiments of the present invention, the combining module 240 includes:
[0080] The first generating unit is used to place text elements and image elements into a preset HTML template according to the chapter directory and the content directory to generate an HTML format file;
[0081] The second generating unit is used to generate an ePub format file according to the HTML format file.
[0082] Optionally, in some embodiments of the present invention, the device further comprises:
[0083] The generation module is used to select images that meet preset rules from image elements and generate the cover of the ePub format file.
[0084] For the description of the relevant parts of the ePub file format conversion device provided by an embodiment of the present invention, please refer to the detailed description of the corresponding parts in the ePub file format conversion method provided by an embodiment of the present invention, and both have the corresponding effects of the ePub file format conversion method provided by an embodiment of the present invention, and will not be repeated here.
[0085] The ePub file format conversion device mentioned above is described from the perspective of functional modules. Furthermore, another aspect of the embodiment of the present invention provides an ePub file format conversion device, which is described from the perspective of hardware.
[0086] See also Figure 3 , the device includes:
[0087] Memory 310, for storing computer programs;
[0088] The processor 320 is configured to implement the steps of the ePub file format conversion method provided in any of the above embodiments when executing a computer program.
[0089] The processor 320 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 320 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), or PLA (Programmable Logic Array). The processor 320 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 320 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 320 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0090] The memory 310 may include one or more computer-readable storage media, which may be non-transitory. The memory 310 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 310 is at least used to store the following computer program, wherein, after the computer program is loaded and executed by the processor, it can implement the relevant steps of the ePub file format conversion method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 310 may also include an operating system and data, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system may include Windows, Unix, Linux, etc., and the data may include but is not limited to data corresponding to test results, etc.
[0091] It is understandable that if the ePub file format conversion method provided in any of the above embodiments is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium and executes all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk or optical disk, etc. Various media that can store program codes.
[0092] In view of this, another aspect of an embodiment of the present invention provides a readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the ePub file format conversion method provided in any of the above embodiments are implemented.
[0093] The functions of each functional module of the readable storage medium provided in the embodiment of the present invention can be specifically implemented according to the method in any of the above method embodiments. The specific implementation process can refer to the relevant description of any of the above method embodiments and will not be repeated here.
[0094] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can be referred to each other. It should also be noted that in this specification, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of further restrictions, the elements defined by the sentence "comprise a..." do not exclude the presence of other identical elements in the process, method, article or equipment including the element.
[0095] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for converting ePub file format, characterized in that: include: Obtain the file content contained in the file to be converted, where the file to be converted is a file in any format of txt file, pdf file, docx file, or html file; Perform keyword filtering on the file content to obtain filtered file content; Splitting the text elements and image elements in the filtered file content using a splitting algorithm to obtain a text element set and a picture element set, and generating a chapter directory and a content directory corresponding to the chapter directory using a directory chapter arrangement algorithm based on the text data in the text element set; Combining the text elements in the text element set and the image elements in the image element set according to the chapter directory and the content directory to generate an ePub format file; The keyword filtering of the file content to obtain the filtered file content includes: Comparing the words in the document content with the keywords in the preset corpus one by one to obtain similarity comparison results; The words that meet the preset conditions in the similarity comparison results are replaced with random characters to obtain the filtered file content; If the file to be converted is a docx file, the text elements and picture elements in the filtered file content are split by a splitting algorithm to obtain a text element set and a picture element set, including: Creating a file parser, parsing the filtered file content through the file parser to obtain an element list, initializing a picture element set and a text element set, traversing the element list, and determining whether an element node in the element list is a picture element or a text element; if it is a picture element, saving the picture element and its position information to the picture element set; if it is a text element, saving the text element and its position information to the text element set; If the file to be converted is a PDF file, the text elements and picture elements in the filtered file content are split by a splitting algorithm to obtain a text element set and a picture element set, including: Create a PDF document instance, initialize the picture element set and the text element set, traverse all pages of the filtered file content, query each page, extract all picture elements in the page, save all the picture elements and the page position information of the picture elements to the picture element set, extract all the text elements in the page, save all the text elements and the page position information of the text elements to the text element set.
2. The ePub file format conversion method according to claim 1, characterized in that: After performing keyword filtering on the file content to obtain filtered file content, the method further includes: The filtered file content is parsed to obtain the file encoding and file size corresponding to the filtered file content.
3. The ePub file format conversion method according to claim 1, characterized in that: The step of combining the text elements in the text element set and the picture elements in the picture element set according to the chapter directory and the content directory to generate an ePub format file includes: According to the chapter directory and the content directory, the text elements in the text element set and the picture elements in the picture element set are placed into a preset HTML template to generate an HTML format file; Generate an ePub format file based on the HTML format file.
4. The ePub file format conversion method according to claim 1, wherein: The method further comprises: Selecting picture elements that meet preset rules from the picture element set to generate a cover for the ePub format file.
5. An ePub file format conversion device, characterized in that: include: An acquisition module is used to acquire the file content contained in a file to be converted, wherein the file to be converted is a file in any format of a txt file, a pdf file, a docx file, or an html file; A filtering module, configured to filter the file content by keywords to obtain filtered file content; a splitting module for splitting the text elements and image elements in the filtered file content using a splitting algorithm to obtain a text element set and a picture element set, and generating a table of contents and a table of contents corresponding to the table of contents using a table of contents and a chapter arrangement algorithm based on the text data in the text element set; a combining module, configured to combine the text elements in the text element set and the image elements in the image element set according to the chapter directory and the content directory to generate an ePub format file; When the filtering module performs keyword filtering on the file content to obtain the filtered file content, it is specifically used to: Comparing the words in the document content with the keywords in the preset corpus one by one to obtain similarity comparison results; The words that meet the preset conditions in the similarity comparison results are replaced with random characters to obtain the filtered file content; If the file to be converted is a docx file, the splitting module is specifically used to: Creating a file parser, parsing the filtered file content through the file parser to obtain an element list, initializing a picture element set and a text element set, traversing the element list, and determining whether an element node in the element list is a picture element or a text element; if it is a picture element, saving the picture element and its position information to the picture element set; if it is a text element, saving the text element and its position information to the text element set; If the file to be converted is a PDF file, the splitting module is specifically used to: Create a PDF document instance, initialize the picture element set and the text element set, traverse all pages of the filtered file content, query each page, extract all picture elements in the page, save all the picture elements and the page position information of the picture elements to the picture element set, extract all the text elements in the page, save all the text elements and the page position information of the text elements to the text element set.
6. The ePub file format conversion device according to claim 5, characterized in that: The device further comprises: The parsing module is used to parse the filtered file content to obtain the file encoding and file size corresponding to the filtered file content.
7. The ePub file format conversion device according to claim 5, characterized in that: The device further comprises: The generating module is used to select the picture elements that meet the preset rules in the picture element set and generate the cover of the ePub format file.
8. An ePub file format conversion device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the ePub file format conversion method according to any one of claims 1 to 4 when executing the computer program.
9. A readable storage medium, characterized in that The readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the ePub file format conversion method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Method and system for converting Word file into EPUB file
CN110083805A
Speech recognition method and device
US20190043504A1