Method for realizing compatibility of PDF (Portable Document Format) file with terminal equipment, storage medium, equipment and computer program product

By converting PDF files into picture streams and displaying them on terminal devices, the problem of slow or abnormal loading of PDF files on different terminal devices is solved, and fast display and efficient rendering are achieved. It is suitable for various terminal devices and improves user experience and server processing capabilities.

CN119203927APending Publication Date: 2024-12-27SUNING CONSUMER FINANCE CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411240382.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-05
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

PDF files are loaded slowly or loaded abnormally on different terminal devices. This is mainly due to the different degree of support for PDF files by webview components of each device, resulting in incompatible fonts and inconsistent encodings, and cannot be compatible with each terminal device.

Method used

Convert PDF files into image streams and display them on terminal devices. The canvas size is calculated through PDDocument and BufferedImage processing, and the picture stream is written to the canvas of a certain size, and compressed when necessary to reduce device requests and improve loading speed. .

Benefits of technology

It realizes normal and rapid display of PDF files on various terminal devices, avoids font and encoding compatibility issues, improves loading and rendering speed, reduces server load, improves user experience, and reduces operating costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119203927A_ABST
    Figure CN119203927A_ABST
Patent Text Reader

Abstract

The invention discloses a method for realizing compatibility of a PDF (Portable Document Format) file with terminal equipment, a storage medium, equipment and a computer program product. The method comprises the following steps: generating a unique identification number of a user when the PDF file is stored; the terminal equipment initiates a request for viewing the PDF file, and obtains a corresponding PDF file stream according to the unique identification number of the user; according to the PDDocument, each page of PDF file stream is converted into a picture stream, and the picture streams are put into a set; traversing the picture stream in the set by using Buffer Image, calculating the size of the required canvas, and writing the picture stream in the set into the canvas with the determined size to obtain a new picture stream; and judging whether the byte size of the new picture stream is out of limit, if so, compressing the new picture stream, and displaying the compressed picture stream on the terminal equipment. According to the method and the device, the PDF file can be normally and quickly displayed on each terminal device and is not influenced by the type version of the terminal device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of PDF file processing, and in particular to a method, storage medium, device and computer program product for realizing PDF file compatibility with various terminal devices. Background Art

[0002] When PDF files are displayed on terminal devices with different containers, such as iOS and Android, they may load slowly or abnormally. This is because the webview components of different terminal devices are developed based on different browser kernels, which have different degrees of support for PDF files. Some terminal devices with webview components may not support PDF file rendering by default or have limited parsing capabilities for PDF format files. In addition, the fonts used in PDF files may not be in the font library of the terminal device, which may result in some characters not being displayed correctly. There may also be encoding inconsistencies in PDF files, which may cause garbled text displayed on some terminal devices. Therefore, existing PDF files are currently not compatible with various terminal devices. Summary of the invention

[0003] In view of the problems existing in the prior art, the present invention provides a method, storage medium, device and computer program product for achieving PDF file compatibility with various terminal devices, so that PDF files can be displayed normally and quickly on various terminal devices without being affected by the type and version of the terminal device.

[0004] To achieve the above technical objectives, the present invention adopts the following technical solution: a method for realizing PDF file compatibility with various terminal devices, specifically comprising the following steps:

[0005] Step S1, generating a unique user identification number when storing the PDF file;

[0006] Step S2: The terminal device initiates a request to view the PDF file and obtains the corresponding PDF file stream according to the user's unique identification number;

[0007] Step S3, convert each page of PDF file stream into a picture stream according to PDDocument, and put the picture stream into a collection;

[0008] Step S4, using BufferedImage to traverse the image streams in the collection, calculate the required canvas size, write the image streams in the collection into the canvas of the determined size, and obtain a new image stream;

[0009] Step S5, determine whether the byte size of the new picture stream exceeds the limit. If so, compress the new picture stream and display the compressed picture stream on the terminal device; otherwise, directly display the new picture stream on the terminal device.

[0010] Furthermore, step S3 includes the following sub-steps:

[0011] Step S3.1, use the PDDocument.load method to load the PDF file stream, and obtain the page index pageIndex of the PDF file stream;

[0012] Step S3.2, create a PDF renderer, pass the data of the loaded PDF file stream as a parameter to the constructor PDFRenderer(), and generate a handle object of the PDF renderer;

[0013] Step S3.3, according to the page index pageIndex of the PDF file stream, the image resolution dpi and the color mode ImageType of the image, and calling renderImageWithDPI(pageIndex, dpi, ImageType.) on the generated handle object, rendering each page in the PDF file stream as an image stream;

[0014] Step S3.4: Put the rendered image stream into the collection in the order of page index pageIndex.

[0015] Furthermore, step S4 includes the following sub-steps:

[0016] Step S4.1, traverse each image stream in the collection through BufferedImage, obtain the width of the canvas through buffer.getWidth, accumulate the height of each image stream through buffer.getHeight as the height of the canvas, and determine the canvas size by the width and height of the canvas;

[0017] Step S4.2: Write each image stream content in the collection into a canvas of a determined canvas size according to the page index pageIndex to obtain a new image stream.

[0018] Furthermore, the specific process of compressing the new image stream in step S5 is: reducing the width and height of the new image stream in equal proportion to obtain a reduced image stream, generating a three-primary color canvas through BufferImage according to the size of the reduced image stream, and drawing the reduced image stream on the generated three-primary color canvas through drawImage.

[0019] Furthermore, the present invention also provides a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute the method for achieving PDF file compatibility with various terminal devices.

[0020] Furthermore, the present invention also provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for achieving PDF file compatibility with various terminal devices is implemented.

[0021] Furthermore, the present invention also provides a computer program product, including a computer program, and when the computer program is executed by a processor, the method for achieving PDF file compatibility with various terminal devices is implemented.

[0022] Compared with the prior art, the present invention has the following beneficial effects: the method for realizing PDF file compatibility with various terminal devices of the present invention converts the PDF file into a picture for display on the terminal device, and the file in picture format does not need to rely on specific encoding and fonts, and is directly displayed in the form of pixels, thereby avoiding the situation that the PDF encoding and fonts are not supported on the terminal device due to the direct display of PDF, and is applicable to various terminal devices; in addition, the present invention converts the PDF file stream into a picture stream through PDDocument, which can solve the problem of PDF file compatibility of different terminal devices, and the specific fonts in the PDF file can be better presented after the layout is converted into a picture, thereby avoiding the difference in display on different device terminals, and can improve the speed of loading and rendering, and improve work efficiency; and, the size of the canvas is calculated through BufferedImage, and all picture streams are written into one canvas, so as to reduce the number of times the device terminal requests the server, reduce the load of the server, and thus process more user requests more efficiently, while enabling users to see the content in the PDF file faster, improving user experience, and the merged pictures are more easily cached by the device terminal webview, and when the user visits again, there is no need to reload the required pictures. In summary, the method for achieving PDF file compatibility with various terminal devices through the present invention can enable PDF files to be displayed normally and quickly on various terminal devices without being affected by the type and version of the terminal device. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 The present invention is a flow chart of a method for implementing PDF file compatibility with various terminal devices. DETAILED DESCRIPTION

[0024] The technical solution of the present invention is further explained below in conjunction with the accompanying drawings.

[0025] like Figure 1 The present invention is a flowchart of a method for implementing PDF file compatibility with various terminal devices, and the method specifically includes the following steps:

[0026] Step S1: Generate a unique user identification number when storing a PDF file.

[0027] Step S2: The terminal device initiates a request to view the PDF file and obtains the corresponding PDF file stream according to the user's unique identification number.

[0028] Step S3: Since the image format is more compatible than the PDF format on various terminal devices, especially in some environments that do not support direct viewing of PDF, the image format can ensure the normal display of the content. Therefore, according to PDDocument, each page of the PDF file stream is converted into an image stream, and the image stream is placed in a collection. This can solve the problem of PDF file compatibility on different terminal devices, and the specific fonts in the PDF file can be better presented after the typesetting is converted into an image, avoiding display differences on different device terminals, and can increase the speed of loading and rendering, thereby improving work efficiency. It specifically includes the following sub-steps:

[0029] Step S3.1, use the PDDocument.load method to load the PDF file stream, and obtain the page index pageIndex of the PDF file stream;

[0030] Step S3.2, create a PDF renderer, pass the data of the loaded PDF file stream as a parameter to the constructor PDFRenderer(), and generate a handle object of the PDF renderer;

[0031] Step S3.3, according to the page index pageIndex of the PDF file stream, the image resolution dpi and the color mode ImageType of the image, and calling renderImageWithDPI(pageIndex, dpi, ImageType.) on the generated handle object, rendering each page in the PDF file stream as an image stream;

[0032] Step S3.4: Put the rendered image stream into the collection in the order of page index pageIndex.

[0033] Step S4, use BufferedImage to traverse the image stream in the collection, calculate the size of the required canvas, write the image stream in the collection into the canvas of the determined size, and obtain a new image stream to reduce the number of times the device terminal requests the server, reduce the server load, and process more user requests more efficiently, while enabling users to see the content in the PDF file faster, improving user experience, and the merged image is easier to be cached by the device terminal webview, so when the user visits again, there is no need to reload the required image. Specifically including the following sub-steps:

[0034] Step S4.1, traverse each image stream in the collection through BufferedImage, obtain the width of the canvas through buffer.getWidth, accumulate the height of each image stream through buffer.getHeight as the height of the canvas, and determine the canvas size by the width and height of the canvas;

[0035] Step S4.2: Write each image stream content in the collection into a canvas of a determined canvas size according to the page index pageIndex to obtain a new image stream.

[0036] Step S5, determine whether the byte size of the new picture stream exceeds the limit. If so, compress the new picture stream and display the compressed picture stream on the terminal device; otherwise, directly display the new picture stream on the terminal device.

[0037] The specific process of compressing the new image stream in the present invention is: the width and height of the new image stream are reduced in proportion to obtain a reduced image stream, a three-primary color canvas is generated through BufferImage according to the size of the reduced image stream, and the reduced image stream is drawn on the generated three-primary color canvas through drawImage. The compressed image file becomes smaller and can be loaded and displayed faster, thereby improving the user experience. At the same time, the compressed image can reduce the storage space occupied by the server, save storage costs, and achieve cost reduction and efficiency improvement. In addition, the compressed image consumes less bandwidth during transmission, thereby reducing operating costs.

[0038] The method of the present invention realizes PDF file compatibility with various terminal devices by converting PDF files into pictures for display on terminal devices. Files in picture format do not need to rely on specific encoding and fonts, and are directly displayed in the form of pixels, thereby avoiding the situation where PDF encoding and fonts are not supported on terminal devices due to direct PDF display. The method is suitable for various terminal devices.

[0039] In a technical solution of the present invention, a computer-readable storage medium is further provided, storing a computer program, wherein the computer program enables a computer to execute the method for achieving PDF file compatibility with various terminal devices.

[0040] In a technical solution of the present invention, an electronic device is also provided, including: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for achieving PDF file compatibility with various terminal devices is implemented.

[0041] In a technical solution of the present invention, a computer program product is also provided, including a computer program, and when the computer program is executed by a processor, the method for achieving PDF file compatibility with various terminal devices is implemented.

[0042] In the embodiments disclosed in the present application, the computer storage medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. The computer storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the above. More specific examples of computer storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above.

[0043] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in this application can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0044] The above are only preferred embodiments of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should be regarded as the protection scope of the present invention.

Claims

1. A method for achieving PDF file compatibility with various terminal devices, characterized in that: The specific steps include: Step S1, generating a unique user identification number when storing the PDF file; Step S2: The terminal device initiates a request to view the PDF file and obtains the corresponding PDF file stream according to the user's unique identification number; Step S3, convert each page of PDF file stream into a picture stream according to PDDocument, and put the picture stream into a collection; Step S4, using BufferedImage to traverse the image streams in the collection, calculate the required canvas size, write the image streams in the collection into the canvas of the determined size, and obtain a new image stream; Step S5, determine whether the byte size of the new picture stream exceeds the limit. If so, compress the new picture stream and display the compressed picture stream on the terminal device; otherwise, directly display the new picture stream on the terminal device.

2. A method for achieving PDF file compatibility with various terminal devices according to claim 1, characterized in that: Step S3 includes the following sub-steps: Step S3.1, use the PDDocument.load method to load the PDF file stream, and obtain the page index pageIndex of the PDF file stream; Step S3.2, create a PDF renderer, pass the data of the loaded PDF file stream as a parameter to the constructor PDFRenderer(), and generate a handle object of the PDF renderer; Step S3.3, according to the page index pageIndex of the PDF file stream, the image resolution dpi and the color mode ImageType of the image, and calling renderImageWithDPI(pageIndex, dpi, ImageType.) on the generated handle object, rendering each page in the PDF file stream as an image stream; Step S3.4: Put the rendered image stream into the collection in the order of page index pageIndex.

3. The method for achieving PDF file compatibility with various terminal devices according to claim 1, characterized in that: Step S4 includes the following sub-steps: Step S4.1, traverse each image stream in the collection through BufferedImage, obtain the width of the canvas through buffer.getWidth, accumulate the height of each image stream through buffer.getHeight as the height of the canvas, and determine the canvas size by the width and height of the canvas; Step S4.2: Write each image stream content in the collection into a canvas of a determined canvas size according to the page index pageIndex to obtain a new image stream.

4. The method for achieving PDF file compatibility with various terminal devices according to claim 1, characterized in that: The specific process of compressing the new image stream in step S5 is: reducing the width and height of the new image stream in equal proportion to obtain a reduced image stream, generating a three-primary color canvas through BufferImage according to the size of the reduced image stream, and drawing the reduced image stream on the generated three-primary color canvas through drawImage.

5. A computer-readable storage medium storing a computer program, characterized in that: The computer program enables a computer to execute the method for achieving PDF file compatibility with various terminal devices as described in any one of claims 1 to 4.

6. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for achieving PDF file compatibility with various terminal devices as described in any one of claims 1 to 4 is implemented.

7. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for achieving PDF file compatibility with various terminal devices as described in any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Method of converting PDF file into pictures, electronic device and computer-readable storage medium

    CN108509396A

  • Large PDF (Portable Document Format) annotation method and device

    CN116911264A

  • Printing electronic documents from large HTML screens

    US20230106345A1