Print file size optimization method and computer readable storage medium

By font cropping and merging of cloud-printed PDF files, the problem of slow downloading and error-prone printing files caused by tight bandwidth during cloud printing is solved, and the effect of improving printing efficiency and maintaining consistent printing effect is achieved.

CN119720943APending Publication Date: 2025-03-28FUJIAN CENTM INFORMATION
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411515588.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

During the cloud printing process, when the network bandwidth resources are tight, the printing file download speed will be slow and error-prone, affecting the overall printing efficiency.

Method used

By parsing and counting the PDF files to be printed, the text collection of each font is obtained, and unused font data is cropped and removed, the font file to be printed is replaced, and the font file to be printed is uploaded to the cloud print server.

Benefits of technology

It effectively reduces the size of files to be printed, reduces the requirements for network bandwidth, improves the response speed and file loading speed, ensures smooth printing in environments with limited bandwidth resources, and maintains consistent printing results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119720943A_ABST
    Figure CN119720943A_ABST
Patent Text Reader

Abstract

The invention discloses a printing file size optimization method and a computer readable storage medium, and the method comprises the steps: obtaining a to-be-printed file which is in a PDF format; analyzing and counting the to-be-printed file to obtain character statistical data of the to-be-printed file, the character statistical data comprising a character set corresponding to each font; the font file of each font is cut, related data of other characters except the character set corresponding to each font is removed, and the related data comprises font data; and according to the cut font file, replacing the font file of the to-be-printed file, and uploading the replaced to-be-printed file to a cloud printing server. The transmission speed and the printing efficiency of the to-be-printed file can be improved, and the uniformity of the printing effect can be ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of printing technology, and in particular to a method for optimizing the size of a printing file and a computer-readable storage medium. Background Art

[0002] In modern enterprise printer management, cloud printing technology is usually used to manage printers and printing permissions. For example, by using one terminal to control more than 10 printers, the remaining terminals only need to install virtual printer drivers, and then the universal virtual printer driver collects print files, centralizes them to the server for forwarding and identification, and pushes them to the designated printer for printing according to the printer selected by the user.

[0003] The above process is the solution that almost all existing cloud printing will adopt. The advantage of this solution is that the printers are centrally managed. The printer driver only needs to be installed on one computer, and the user's computer only needs to install a unified virtual print driver. If you want to print later, you only need to open the file and select the virtual print driver to print. This avoids the problem that each user needs to install a bunch of printer drivers and it is difficult to choose when printing. This solution has no disadvantages when bandwidth resources are sufficient, but as the number of users increases and bandwidth resources become tight, its disadvantages will gradually be exposed. In short, when more devices use network resources, the network speed will also slow down, causing the printer to download and print files more and more slowly, and the user's waiting time for printing will also increase. In the worst case, the print file download fails and cannot be printed, causing the user to be unable to print files.

[0004] In the prior art, in order to solve the problem of the size of the collected print files, PDF (Portable Document Format) clipping technology is used. PDF clipping technology is to remove some embedded resource files in the PDF file to achieve the goal of PDF file size compression (PDF is a cross-platform file format, widely used in the exchange and dissemination of electronic documents. Due to the high compatibility of PDF files, the print file information collected by the virtual printer driver is generally stored in PDF format). For example, the font resources in the PDF file can be deleted to reduce the size of the PDF print file. Generally speaking, the font size in the PDF file is generally around 5MB~9MB, and the size of the print file saved in PDF format is usually around 10MB. By removing the font files embedded in the PDF file, the size of the print file can be compressed to less than 100KB, so that the size can be compressed to about 1 / 100 of the original size, reducing the occupation of network broadband resources, and solving the problem of slow print file speed and error-prone print file download caused by tight bandwidth resources.

[0005] Although removing embedded font files can reduce the print file size to about 1 / 100 of the original size, the font resources in the PDF file actually play an important role in maintaining the consistency of the printing effect. Generally speaking, the font files in the PDF file have the following functions: Cross-platform consistency: PDF was originally designed to enable cross-platform document sharing, ensuring that the appearance of the document remains consistent when viewed on different devices and operating systems. Embedding font information allows the document to display the expected font style correctly even if the specific font used when the original file was created is not installed on the target system.

[0006] Self-contained: PDF files can embed font descriptors or complete font files, which means that the document does not need to rely on external font resources during transmission, improving the independence and integrity of the document.

[0007] Visual fidelity: By directly including all font data used in the document, PDF can accurately reproduce the formatting and layout design of the text, including special font styles and weights, which is especially important for fields such as design, publishing and legal documents that require high font accuracy.

[0008] Compatibility and retroactivity: Even if the original fonts are no longer commonly used or updated over time, embedded fonts can still ensure that the document will be displayed correctly in the future, enhancing the long-term compatibility of the document.

[0009] Therefore, once the embedded font files are removed from a PDF file, although the size of the printed file can be greatly reduced, it may cause garbled characters to be printed in the PDF file or the printed font effect may be inconsistent with the original one. Summary of the invention

[0010] The technical problem to be solved by the present invention is to provide a print file size optimization method and a computer-readable storage medium, which can solve the problems of slow printing of files and prone to printing errors in the cloud printing process when network bandwidth resources are tight, so as to improve the overall printing efficiency.

[0011] In order to solve the above technical problems, the technical solution adopted by the present invention is: a method for optimizing the size of a printed file, comprising: Obtain a file to be printed, where the file to be printed is in PDF format; Parsing and counting the file to be printed to obtain text statistics of the file to be printed, wherein the text statistics include a text set corresponding to each font; Cutting the font files of each font respectively, removing the relevant data of other characters outside the character set corresponding to each font, wherein the relevant data includes the glyph data; The font file of the file to be printed is replaced according to the cropped font file, and the replaced file to be printed is uploaded to the cloud printing server.

[0012] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method described above is implemented.

[0013] The beneficial effect of the present invention is that by parsing and counting the files to be printed, the fonts and characters used in the files to be printed are obtained, and the relevant data of the unused characters are removed, so that the files to be printed can be greatly compressed, and because the original font information is retained, the printing effect is consistent with the font originally used by the user and there will be no problem of garbled Chinese characters.

[0014] The present invention can effectively reduce the size of files to be printed, reduce the bandwidth requirements for the network, improve the response speed, speed up the loading speed of files, and can smoothly push the print files to the printer for printing in an environment with limited bandwidth resources, and the printing time will not differ too much from the original; and by cutting the font file, the used PDF text font information is retained and the printing effect can be guaranteed not to be inconsistent due to the missing font file, which can well ensure the uniformity of the printing effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 A flow chart of the print file size optimization method of the present invention; Figure 2 This is a flow chart of a method according to Embodiment 1 of the present invention. DETAILED DESCRIPTION

[0016] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is a detailed description in conjunction with the implementation methods and the accompanying drawings.

[0017] See also Figure 1 , a printing file size optimization method, comprising: Obtain a file to be printed, where the file to be printed is in PDF format; Parsing and counting the file to be printed to obtain text statistics of the file to be printed, wherein the text statistics include a text set corresponding to each font; Cutting the font files of each font respectively, removing the relevant data of other characters outside the character set corresponding to each font, wherein the relevant data includes the glyph data; The font file of the file to be printed is replaced according to the cropped font file, and the replaced file to be printed is uploaded to the cloud printing server.

[0018] It can be seen from the above description that the beneficial effects of the present invention are: it can improve the transmission speed and printing efficiency of the file to be printed, and can ensure the uniformity of the printing effect.

[0019] Furthermore, before replacing the font file of the to-be-printed file according to the cut font file, the method further comprises: Calculate the character overlap rate according to the character set corresponding to each font; If the text overlap rate is less than or equal to a preset threshold, the font files of the cropped fonts are merged.

[0020] From the above description, it can be seen that if the text overlap rate is lower than the threshold, it means that the text overlap rates involved in different fonts are low, and different fonts can be considered to be merged together, so as to further optimize the size of the file to be printed.

[0021] Furthermore, the character overlap rate is calculated according to the character set corresponding to each font, specifically: Calculating the intersection of the character sets corresponding to each font, and counting the number of characters in the intersection to obtain a first number; Calculating a union of character sets corresponding to each font, and counting the number of characters in the union to obtain a second number; The first number is divided by the second number to obtain a text overlap ratio.

[0022] Furthermore, the merging of the clipped font files of each font includes: Add the fonts used in the file to be printed to the list of fonts to be merged; Selecting the font corresponding to the character set with the largest number of characters in the list of fonts to be merged as the current reference font; Traverse other fonts in the list of fonts to be merged, and sequentially obtain other fonts as the current traversal font; Compare the character sets corresponding to the current reference font and the current traversal font, if a character exists in the character set corresponding to the current traversal font but does not exist in the character set corresponding to the current reference font, copy the relevant data of the character to the font file of the current reference font, and delete the relevant data of the character in the font file of the current traversal font, the relevant data including the mapping relationship between the character code and the glyph index, the glyph data and the horizontal metric information; After traversing other fonts, the current reference font is removed from the list of fonts to be merged, and the step of selecting the font corresponding to the character set with the largest number of characters in the list of fonts to be merged as the current reference font is continued.

[0023] From the above description, it can be seen that using the font with the largest number of characters in the text set as the base font can reduce the amount of data migration; merging the relevant data of the characters in other fonts that are not repeated with the base font into the base font, and when the characters of some fonts in other fonts are not repeated with the characters of the base font, the number of fonts can be reduced.

[0024] Furthermore, the merging of the clipped font files of each font includes: Add the fonts used in the file to be printed to the list of fonts to be merged; Selecting the font corresponding to the character set with the largest number of characters in the list of fonts to be merged as the base font; Traverse other fonts in the list of fonts to be merged, and sequentially obtain other fonts as the current traversal font; Compare the character sets corresponding to the current reference font and the current traversal font. If a character exists in both the character sets corresponding to the current traversal font and the reference font, add the character to the reference font as a variant of the same character, and update the glyph replacement table of the reference font. If a character exists in the character set corresponding to the current traversal font but does not exist in the character set corresponding to the reference font, the glyph data of the character is copied to the glyph data table of the reference font, and the character mapping table of the reference font is updated.

[0025] It can be seen from the above description that merging the font files of all fonts into one font can greatly reduce the number of fonts and further optimize the size of the file to be printed.

[0026] Furthermore, the character mapping table of the updated reference font is specifically: A new glyph index is allocated to the glyph data of the font, and a mapping relationship between the character code of the font and the new glyph index is added to a character mapping table of the reference font.

[0027] From the above description, it can be seen that it is ensured that the relevant mapping relationship of the merged text will not overwrite the mapping relationship of the original text.

[0028] Further, the obtaining of the file to be printed includes: The data to be printed is received, and the data to be printed is converted into a PDF format to obtain a file to be printed.

[0029] Furthermore, the parsing and counting of the file to be printed to obtain text statistics of the file to be printed includes: Parsing the file to be printed to obtain a mapping relationship between text and fonts; According to the mapping relationship between the characters and fonts, a character set corresponding to each font is obtained by statistics, wherein the character set is a deduplicated character set.

[0030] Furthermore, the step of tailoring the font files of each font to remove the data related to other characters outside the character set corresponding to each font includes: According to the character code of each character in the character set corresponding to a font, a corresponding glyph index is obtained through a character mapping table, wherein the character mapping table is used to store a mapping relationship between the character code and the glyph index; According to the obtained glyph index, the corresponding glyph data is obtained through a glyph index table and a glyph data table, wherein the glyph index table is used to store a mapping relationship between the glyph index and the offset of the corresponding glyph data in the glyph data table, and the glyph data table is used to store the glyph data; A cropped font corresponding to the font is created, and a font file of the cropped font corresponding to the font is reconstructed according to the character code, glyph index and glyph data of each character in the character set corresponding to the font.

[0031] From the above description, it can be seen that the font file is repackaged, the font table is reconstructed and saved as a new font.

[0032] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method described above is implemented.

[0033] Embodiment 1 Please refer to Figure 2 , Embodiment 1 of the present invention is: a method for optimizing the size of a printed file, which can be applied to cloud printing. Figure 2 As shown, the following steps are included: S1: Get the file to be printed.

[0034] Specifically, when a user uses document editing software (such as WPS) on a computer to print a file, he or she selects the virtual printer driver provided by Cloud Print to print. At this time, the printer driver receives the print data instruction sent by the document editing software (the instruction usually contains print data, such as EMF or RAW, etc.), parses the print instruction, constructs a PDF file format, converts the received print data into PDF format, and saves it locally.

[0035] S2: Analyze and count the file to be printed to obtain text statistical data of the file to be printed, where the text statistical data includes a mapping relationship between text and fonts and a text set corresponding to each font.

[0036] Specifically, the file to be printed is parsed to obtain a mapping relationship between text and fonts; based on the mapping relationship between text and fonts, a text set corresponding to each font is statistically obtained, wherein the text set is a deduplicated text set.

[0037] In actual application scenarios, PDF open source frameworks (such as muPDF, PoDoFo, etc.) can be used to parse the files to be printed. Usually, the text information in PDF files is stored in the content stream. By parsing the text type information in the content stream of the PDF file, the text and font information corresponding to each content stream is counted, and the mapping relationship between text and font is obtained.

[0038] Then count the words contained in each font in the file to be printed. For example, the sentence "Study hard and make progress every day" has a total of 8 words, but 6 words are used, namely: "good", "learn", "learn", "day", "towards", "up". And so on, count all the non-repeated words corresponding to each font.

[0039] In actual application scenarios, since the content stream of a PDF document is parsed in sequence, the content can be parsed in the order of the PDF document pages. First, get the Document object from the PDF file (the file to be printed) (Document is the root object of the PDF document, which contains all the basic information in the document), and construct it through the code: PdfMemDocumentdocument(filename); get the Page object from the Document (the Page object contains the content of the page and related resources, including text resources and font resources), and get the Page object of each page through the code PdfPage* page = document.GetPage(i). In the Page object, first get the font resources used in this page, using the key code: PdfObject* fontsObject = page->GetFromResources(PdfName("Font")); get the Font resource node of this page and store it in the Map object (with the font name as the key and the font resource as the value).

[0040] After getting the Page object of each page, construct a PdfContentsTokenizer tokenizer object to search for the Tj or TJ object in the Page (Tj and TJ are two operators used to draw text in the PDF content stream. They are part of the PDF syntax and are used to describe how to draw text on a page). After getting the Tj and TJ objects, extract the text content and store it in a Map object (with the font name as the key and the Tj object i value as the storage).

[0041] Traverse the extracted text and fonts, and count the text sets corresponding to each font in turn. For example, suppose that a part of the text in the file to be printed uses the Song font, then count the text sets (non-repeated characters) used in all paragraphs that use Song text, such as the sentence "Study hard and make progress every day", its text set is: (good, study, learn, day, to, up). You can use the Set collection for statistics, because the Set collection naturally has the ability to remove duplicates. Then store the counted text set in a Map with the font name as the key and the font set as the value (for example, Map <String, Set <string>>) S3: Crop the font files of each font respectively, and remove the relevant data of other characters outside the character set corresponding to each font, wherein the relevant data of the characters include the glyph data of the characters, and may also include the mapping relationship between the character encoding of the characters and the glyph index and horizontal measurement information.

[0042] Specifically, the font files of each font used in the file to be printed are read, the cmap table (character mapping table) therein is parsed, and the glyph index (glyph ID) corresponding to each character is obtained according to the character encoding of each character in the character set corresponding to each font; then, according to the glyph index corresponding to each character, the offset of the glyph data of each character in the glyf table (glyph data table) is obtained through the loca table (glyph index table), and then the glyph data of each character is obtained through the glyf table (glyph data table). In this embodiment, a cropped font corresponding to each font is created respectively, and the font file of the cropped font is reconstructed according to the relevant data of each character in the character set corresponding to each font, that is, the font file is repackaged, and the font table is reconstructed and saved as a new font.

[0043] Among them, the cmap table (character mapping table) is used to save the mapping relationship between character encoding and glyph index; the loca table (glyph index table) is used to save the mapping relationship between glyph index and its corresponding glyph data offset in the glyph data table to help locate specific glyph data; the glyf table (glyph data table) is used to save glyph outline data. The font file also includes the hmtx table (horizontal measurement table) to save the horizontal measurement information of the glyph index to the glyph, which is used for text layout and typesetting.

[0044] In actual application scenarios, the font TTF file is parsed. According to the TTF file standard, the TTF file is mainly divided into: Offset Table, Table Directory, Tables, where the table contains various character encoding information and glyph information. In this embodiment, the cmap table (character mapping table) and glyf table (glyph data table) in the TTF file are mainly cropped, and the remaining structures are adjusted according to the cropped content.

[0045] Since the controller program is clearly running on the Windows system and uses the UTF-8 data set, the redundant character mapping table in the cmap table can be cut off in this embodiment (for example, Macintosh Roman encoding, a character set encoding used on the Apple platform), and the glyph data not used in the glyf table can be deleted according to the statistical text set. For example, there are more than 7,000 Chinese characters in Song font, but the text using Song font in the to-be-printed file is only "Study hard, make progress every day", that is, the text set corresponding to Song font contains 6 characters, namely (good, study, learn, day, go, up), then the glyph data of these 6 characters are retained, and the glyph data of other characters in the font data of Song font are deleted. After the glyph data is cut in this way, the size of the font file will be greatly reduced. It can be seen from experiments that the size of a font file can be reduced from 9MB to about 180KB in this embodiment, and the compression rate reaches about 98%. After cutting, the structural information of the TTF file is adjusted and then updated to the font. Iterate through all font files in the entire PDF file.

[0046] By removing the unused glyph information in the file to be printed, it not only does not affect the final printing effect, but also greatly reduces the size of the font file.

[0047] S4: Calculate the character overlap rate according to the character set corresponding to each font.

[0048] Specifically, the intersection and union of the character sets corresponding to each font are calculated respectively, and then the number of characters in the intersection and union are counted respectively. The number of characters in the intersection is divided by the number of characters in the union to calculate the character overlap rate.

[0049] S5: Determine whether the text overlap rate is less than or equal to a preset threshold, if so, execute step S6, if not, execute step S7.

[0050] In this embodiment, the preset threshold is 50%. If the text overlap rate exceeds 50%, it means that the probability of having the same text between different fonts is high, and the meaning of merging fonts is low, so font merging is not performed. If the text overlap rate is less than 50%, it means that the text overlap rate involved in different fonts is low, and different fonts can be considered to be merged together. In actual application scenarios, the threshold can be adjusted according to actual conditions.

[0051] S6: merging the cut font files of each font.

[0052] In this embodiment, this step includes the following steps: S601: Add the fonts used in the file to be printed to the list of fonts to be merged.

[0053] S602: Select the font corresponding to the text set with the largest number of characters in the to-be-merged font list as the current reference font.

[0054] S603: Traverse the other fonts in the to-be-merged font list, and sequentially obtain an other font as the current traversed font.

[0055] S604: Compare the text sets corresponding to the current reference font and the current traversed font, and determine whether there are texts that meet the merging conditions. The merging conditions are that they exist in the text set corresponding to the current traversed font but do not exist in the text set corresponding to the current reference font, that is, determine whether there are texts that exist in the text set corresponding to the current traversed font but do not exist in the text set corresponding to the current reference font. If so, execute step S605; if not, execute step S606.

[0056] S605: Copy the relevant data of the texts that meet the merging conditions to the font file of the current reference font, and delete the relevant data of the texts that meet the merging conditions in the font file of the current traversed font. Among them, the relevant data of the text includes the mapping relationship between the character encoding and the glyph index of the text, the glyph data, and the horizontal metric information.

[0057] For example, assume that the current reference font is Font 1, and the text set corresponding to Font 1 is {你, 好, 世, 界...}; the current traversed font is Font 2, and the text set corresponding to Font 2 is {你, 好, 开, 发, 者...}. For the text set corresponding to Font 2, since "你" and "好" also exist in the text set corresponding to Font 1, they are retained; since the three characters "开", "发", and "者" do not exist in the text set corresponding to Font 1, the relevant data of these three characters are copied to the font file of Font 1. For example, the glyph data of these three characters are copied to the glyf table (glyph data table) of Font 1, the mapping relationship between the character encoding and the glyph index of these three characters is copied to the cmap table (character mapping table) of Font 1, and the horizontal metric information of these three characters is copied to the hmtx table (horizontal metric table) of Font 1. Further, after the glyph data of these three characters are copied to the glyf table of Font 1, according to the offsets of the glyph data of these three characters in the glyf table of Font 1, the mapping relationship between the glyph index of these three characters and the offset of their glyph data in the glyf table of Font 1 is added to the loca table (glyph index table) of Font 1. Finally, the glyph data, glyph mapping relationship and other information of these three characters are trimmed and deleted in the font file of Font 2. At this time, the text set corresponding to Font 1 is {你, 好, 世, 界, 开, 发, 者...}, and the text set corresponding to Font 2 is {你, 好...}. And so on, traverse other fonts.

[0058] S606: Determine whether the other fonts in the list of fonts to be merged have been traversed. If so, execute step S607. If not, continue to traverse other fonts and obtain the next other font as the current traversed font, that is, return to execute step S603.

[0059] S607: Remove the current reference font from the list of fonts to be merged, and then continue to execute S602 until the list of fonts to be merged is empty or only one font remains.

[0060] In another embodiment, this step can also be implemented as follows: First, a font corresponding to a character set with the largest number of characters is selected from among the fonts used in the file to be printed as a reference font.

[0061] Then, other fonts are traversed, and other fonts are sequentially obtained as the current traversal font.

[0062] Next, compare the text sets corresponding to the current base font and the current traversal font. If a certain text exists in the text sets corresponding to both the current traversal font and the base font, add the text to the base font as a variant of the same character, and update the GSUB table (glyph substitution table, used for glyph substitution when rendering text, such as processing different glyph variants of the same character) of the base font.

[0063] If a certain character exists in the character set corresponding to the currently traversed font but does not exist in the character set corresponding to the base font, the glyph data of the character is copied to the glyf table (glyph data table) of the base font, and the cmap table (character mapping table) of the base font is updated. In order to ensure that the mapping of the base font is not overwritten, in this embodiment, a new glyph index is assigned to the glyph data of the font, and the mapping relationship between the character code of the font and the new glyph index is added to the cmap table of the base font.

[0064] And so on, after traversing other fonts, the font files of other fonts will be merged into the base font.

[0065] For example, assume that Font 1 is the reference font, and the set of characters corresponding to Font 1 is {你, 好, 世, 界...}; the currently traversed font is Font 2, and the set of characters corresponding to Font 2 is {你, 好, 开, 发, 者...}. Since the characters "你" and "好" already have glyphs in Font 1, these two characters are added to Font 1 as variants of the same character, and tables such as the GSUB table are updated. Since the three characters "开", "发", and "者" do not exist in the set of characters corresponding to Font 1, the glyph data of these three characters is copied to the glyf table of Font 1, and a new glyph index is assigned to each of these three characters. Assume that the next available glyph index in Font 1 is 100, then the new glyph indices of these three characters in Font 1 can be 100, 101, and 102 respectively. Then, in the cmap table of Font 1, three new mapping entries are added, namely the mapping relationship between the character code (Unicode code point) of "开" and its new glyph index 100, the mapping relationship between the character code of "发" and its new glyph index 101, and the mapping relationship between the character code of "者" and its new glyph index 102. The relevant information of Font 1 at this time can be shown in the following table:

[0066] S7: According to the cropped or merged font file, replace the font file of the file to be printed, and upload the replaced file to be printed to the cloud printing server.

[0067] Specifically, according to the relationship between paragraphs and fonts obtained in step S2, the PDF open-source framework can be used to gradually replace the font files of each text content stream. Finally, the PDF file after replacing the font file is uploaded to the cloud printing server again, and the relevant printing parameters are uploaded to the cloud printing server. Further, in order to prevent information leakage during the transmission process, the SM4 algorithm in the national cryptographic algorithm is used to encrypt the data.

[0068] After the user authenticates and prints on the cloud printing controller, the cloud printing controller will pull the printing job information corresponding to the user (including the printed PDF file and printing parameters). After the download is completed, the encrypted printing file will be decrypted using the same encryption algorithm to obtain the PDF source file. After the decryption is completed, the PDF file is pushed to the printer driver for file printing. Although the font file is cropped, since all the characters used in the PDF file are included in the TTF file, it can still be printed normally without garbled characters.

[0069] This embodiment can not only reduce the occupation of network resources during the printing process and improve printing efficiency; it also avoids the problem of inconsistent printing effects or garbled printing due to the lack of embedded fonts; at the same time, merging the cropped fonts can further reduce the size of the font file and the number of font files, thereby speeding up the loading speed of the PDF file.

[0070] Embodiment 2 This embodiment is a computer-readable storage medium corresponding to the above embodiment, on which a computer program is stored. When the program is executed by the processor, the various steps of the print file size optimization method in the above embodiment are implemented, and the same technical effect can be achieved, which will not be repeated here.

[0071] In summary, the present invention provides a method for optimizing the size of printed files and a computer-readable storage medium, which can achieve compressed printing of PDF file size by cutting, merging, and replacing fonts of cloud printing files, thereby improving the printing speed of the entire cloud printing process. The present invention can effectively reduce the size of the file to be printed, reduce the bandwidth requirements for the network, improve the response speed, and speed up the loading speed of the file. In an environment where bandwidth resources are limited, the printed file can be smoothly pushed to the printer for printing, and the printing time will not be much different from the original; and by cutting the font file, the used PDF text font information is retained and the printing effect can be guaranteed not to be inconsistent due to the lack of the font file, which can well ensure the uniformity of the printing effect.

[0072] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.< / string>

Claims

1. A method for optimizing the size of a printed file, characterized in that: include: Obtain a file to be printed, where the file to be printed is in PDF format; Parsing and counting the file to be printed to obtain text statistics of the file to be printed, wherein the text statistics include a text set corresponding to each font; Cutting the font files of each font respectively, removing the relevant data of other characters outside the character set corresponding to each font, wherein the relevant data includes the glyph data; The font file of the file to be printed is replaced according to the cropped font file, and the replaced file to be printed is uploaded to the cloud printing server.

2. The print file size optimization method according to claim 1, characterized in that: Before replacing the font file of the to-be-printed file according to the cut font file, the method further comprises: Calculate the character overlap rate according to the character set corresponding to each font; If the text overlap rate is less than or equal to a preset threshold, the font files of the cropped fonts are merged.

3. The print file size optimization method according to claim 2, characterized in that: The character overlap rate is calculated according to the character set corresponding to each font, specifically: Calculating the intersection of the character sets corresponding to each font, and counting the number of characters in the intersection to obtain a first number; Calculating a union of character sets corresponding to each font, and counting the number of characters in the union to obtain a second number; The first number is divided by the second number to obtain a text overlap ratio.

4. The print file size optimization method according to claim 2, characterized in that: The step of merging the clipped font files of each font includes: Add the fonts used in the file to be printed to the list of fonts to be merged; Selecting the font corresponding to the character set with the largest number of characters in the list of fonts to be merged as the current reference font; Traverse other fonts in the list of fonts to be merged, and sequentially obtain other fonts as the current traversal font; Compare the character sets corresponding to the current reference font and the current traversal font, if a character exists in the character set corresponding to the current traversal font but does not exist in the character set corresponding to the current reference font, copy the relevant data of the character to the font file of the current reference font, and delete the relevant data of the character in the font file of the current traversal font, the relevant data including the mapping relationship between the character code and the glyph index, the glyph data and the horizontal metric information; After traversing other fonts, the current reference font is removed from the list of fonts to be merged, and the step of selecting the font corresponding to the character set with the largest number of characters in the list of fonts to be merged as the current reference font is continued.

5. The print file size optimization method according to claim 2, characterized in that: The step of merging the clipped font files of each font includes: Add the fonts used in the file to be printed to the list of fonts to be merged; Selecting the font corresponding to the character set with the largest number of characters in the list of fonts to be merged as the base font; Traverse other fonts in the list of fonts to be merged, and sequentially obtain other fonts as the current traversal font; Compare the character sets corresponding to the current reference font and the current traversal font. If a character exists in both the character sets corresponding to the current traversal font and the reference font, add the character to the reference font as a variant of the same character, and update the glyph replacement table of the reference font. If a character exists in the character set corresponding to the current traversal font but does not exist in the character set corresponding to the reference font, the glyph data of the character is copied to the glyph data table of the reference font, and the character mapping table of the reference font is updated.

6. The print file size optimization method according to claim 5, characterized in that: The character mapping table of the updated reference font is specifically: A new glyph index is allocated to the glyph data of the font, and a mapping relationship between the character code of the font and the new glyph index is added to a character mapping table of the reference font.

7. The print file size optimization method according to claim 1, characterized in that: The step of obtaining the file to be printed includes: The data to be printed is received, and the data to be printed is converted into a PDF format to obtain a file to be printed.

8. The print file size optimization method according to claim 1, characterized in that: The parsing and counting of the file to be printed to obtain text statistical data of the file to be printed includes: Parsing the file to be printed to obtain a mapping relationship between text and fonts; According to the mapping relationship between the characters and fonts, a character set corresponding to each font is obtained by statistics, wherein the character set is a deduplicated character set.

9. The print file size optimization method according to claim 1, characterized in that: The step of tailoring the font files of each font to remove the data related to other characters outside the character set corresponding to each font includes: According to the character code of each character in the character set corresponding to a font, a corresponding glyph index is obtained through a character mapping table, wherein the character mapping table is used to store a mapping relationship between the character code and the glyph index; According to the obtained glyph index, the corresponding glyph data is obtained through a glyph index table and a glyph data table, wherein the glyph index table is used to store a mapping relationship between the glyph index and the offset of the corresponding glyph data in the glyph data table, and the glyph data table is used to store the glyph data; A cropped font corresponding to the font is created, and a font file of the cropped font corresponding to the font is reconstructed according to the character code, glyph index and glyph data of each character in the character set corresponding to the font.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.