Online viewing method for large PDF (Portable Document Format) file

By splitting and converting PDF files on the server side and establishing search indexes, and rendering and loading data packets using the JS interface on the client side, efficient online viewing of large PDF files is achieved, blocking and pausing problems are solved, and user experience is improved and search and download functions.

CN118939611APending Publication Date: 2024-11-12CHONGQING TECH & BUSINESS INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410947962.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-16
Publication Date
2024-11-12

AI Technical Summary

Technical Problem

The prior art has blocking and pause problems when viewing large PDF files online, especially on mobile devices, and is unable to perform efficient text searches and text download copying.

Method used

Convert PDF files to hypertext and plain text packets on the server side, and establish a search index to provide full-text search services; use the JS interface to render specified page packets on the client side, adopting an unaware loading method, supporting text search and Download and save viewing status using browser COOKIE.

Benefits of technology

Solve blocking and pause problems when viewing large PDF files online, improve user experience, and support fast search and text download and copying, suitable for a variety of browsers and terminals.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939611A_ABST
    Figure CN118939611A_ABST
Patent Text Reader

Abstract

The invention discloses a large-scale PDF (Portable Document Format) file online viewing method. The method comprises the following steps: in a server side, storing in a file catalog established by a PDF file name abstract value; converting each page of text of the PDF file into a hypertext data packet and a plain text data packet by using a file conversion service, and storing the hypertext data packet and the plain text data packet in an abstract value file directory; establishing a PDF search index; responding to the browser; in the JS interface end, detecting a JS interface in a historical viewing state of the PDF file; requesting to load a JS interface of a specified page, and obtaining a hypertext data packet returned by the server; rendering a JS interface by using the hypertext data packet; loading JS interfaces of front and back pages of the specified page without perception; according to search result information returned by the service, establishing an outline catalogue with a page number corresponding to the keyword in the h5; copying the text and downloading the PDF file. According to the method and the device, the problems of blockage and pause when a large PDF file is checked online and the problem that text search and text downloading and copying cannot be performed are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of online viewing of files, and in particular relates to an online viewing method for a large PDF file. Background Art

[0002] In the current digital age, PDF files have become an indispensable part of our daily life and work. Whether in business, academia, design or personal fields, PDF files are very convenient and practical tools. Although there are many other file formats to choose from, PDF files are still the most popular choice because of its advantages such as cross-platform compatibility, editability, security and convenience. In various information systems, PDF files have become one of the main tools for viewing documents online.

[0003] Currently, there are several common methods for viewing PDF files online:

[0004] 1) Use HTML tags to view PDF files online (such as using IFRAME to view PDF files). Although this method is simple and easy, it lacks compatibility with some PC browsers and mobile browsers.

[0005] 2) Use third-party plug-in libraries (such as pdf.js, etc.) to view PDF files online. This method has good compatibility with PC browsers and mobile browsers, and supports segmented loading of large PDF files and saving browsing status (if supported by the server). However, when the PDF file is large, it will be blocked and paused until the entire PDF file is fully loaded before viewing the file content, resulting in a blank page and a poor experience. In addition, browsing large files on mobile devices is particularly wasteful of network traffic.

[0006] 3) Convert large PDF files into images and map the image addresses to URLs for online viewing. This method is well supported in various browsers and terminals and supports lazy loading mode, but it is difficult to search and copy the contents of the entire PDF file. Summary of the invention

[0007] In order to solve the above problems, the present invention proposes a method for online viewing of large PDF files, which solves the blocking and pausing problems that occur when viewing large PDF files online, as well as the problem that text search and text download and copying cannot be performed.

[0008] To achieve the above object, the technical solution adopted by the present invention is: a method for viewing a large PDF file online, comprising:

[0009] On the server side: receive the PDF file uploaded by the browser and save it in the file directory established by the summary value of the PDF file name; use the file conversion service to convert each page of the PDF file into a hypertext data packet and a plain text data packet, and save them in the corresponding summary value file directory; establish a PDF search index in the search engine and provide full-text search keyword service; respond to the browser request to return the specified page data packet, respond to the browser full-text search keyword service, respond to the browser to download the PDF original file, and respond to text download;

[0010] In the JS interface end: JS interface for detecting the historical viewing status of PDF files; JS interface for requesting to load the specified page and obtaining the hypertext data packet returned by the server; rendering the JS interface using the hypertext data packet; JS interface for unconsciously loading the previous and next pages of the specified page; sending full-text search keywords to the service, and establishing an outline directory corresponding to the page number and keyword in h5 according to the search result information returned by the service; copying text and downloading PDF files.

[0011] Furthermore, the file receiving service at the server side: when receiving a PDF file uploaded by a browser, a new directory called a file directory is created on the server with the MD5 digest value of the PDF file name, and the file is saved in the file directory, and then the file conversion service is notified.

[0012] Furthermore, the file conversion service on the server side: when splitting and converting the PDF file, each page of the PDF file is converted into two data packets: one is a hypertext data packet named in the page number .html format and saved in the file directory; the other is a plain text data packet named in the page number .txt format and saved in the same file directory;

[0013] The plain text file is used to establish the index search relationship between the file name summary value, page number and text data package in the full-text search keyword service, as well as the text download of the specified page;

[0014] At the same time, the text of all pages is merged into one file, named PDF file name summary value.txt, and saved in the file directory.

[0015] Furthermore, the full-text search keyword service at the server side: establishes a full-text index search relationship of the file name summary value, page number and text data packet for the document converted into plain text data in the search engine.

[0016] Furthermore, in response to the browser request, the specified page data packet is returned: when the service program receives the file information request that the browser needs to view, it locates the corresponding file directory, reads the contents of all files corresponding to the page number array in the file directory, and returns the contents of each file in the form of a JSON array;

[0017] Respond to the browser's full-text search keywords: When the service program receives the keyword information that the browser needs to search for in the full text, it searches the PDF file name summary value, page number and keyword through the search engine, and returns the corresponding relationship in the form of a JSON array;

[0018] Respond to the browser downloading the original PDF file: When the service program receives the information that the browser needs to download a PDF file, it locates the corresponding file directory, reads the PDF file in the file directory and returns it;

[0019] Response text download: When the service program receives information that the browser needs to download a PDF file, it locates the file directory. If there is page number information, it reads the page number .txt file content and returns it. If there is no page number information, it reads the PDF file name summary value .txt file content in the file directory and returns it.

[0020] Furthermore, the JS interface for detecting the historical viewing status of a PDF file checks whether the viewing page number corresponding to the file name summary value is saved in the cookie before the PDF file is loaded. If so, the page number is used as the starting page number for loading the file. If not, 1 is used as the starting page number for loading the file.

[0021] Furthermore, a JS interface for loading a specified page is requested: a summary value of the PDF file name to be viewed is generated in the JS service interface, and a WEB service request is sent to d with the PDF file name, the summary value of the PDF file name, and the starting page number. The server responds to the browser request and returns a specified page data packet, thereby obtaining a hypertext data packet returned by the server;

[0022] Hypertext data packet rendering JS interface: After the browser receives the returned hypertext data packet, it creates p tag elements in the H5 page in the order of page numbers, sets the id of the p tag element to the page number, sets the CSS style of the p tag rendering according to the A4 standard, and renders the hypertext data packet;

[0023] JS interface for imperceptibly loading the pages before and after the specified page: Use the JS window object method window.setTimeout to start the background thread to load the pages before and after the specified page; in this method, determine whether the pages before and after the specified page are loaded, that is, determine whether there is a p tag element with an ID value of the loaded page number in the H5 page. If not, send a request message to the server to load the hypertext data packet.

[0024] Furthermore, the Y-axis scrolling is used in the H5 page to load the JS interface without perception: when viewing the page rendered by the loaded p element, the vertical axis scroll offset value of the scroll bar is obtained through the scroll event of the scroll bar, and the p element currently being viewed is calculated according to the relationship between the position of the p element of each page in the page and the scroll bar offset value, and the ID value of the p element is obtained, that is, the page number currently being viewed is obtained;

[0025] The correspondence between the PDF file name summary value and the page number is saved in a cookie as the historical viewing status information of the file; the page number is used as the designated page number, and then the JS interface method of loading the pages before and after the designated page is performed imperceptibly to realize the loading of the hypertext data packet of the page.

[0026] Furthermore, a full-text search is performed in the JS interface: a web request service information is sent to the server in the interface, and the correspondence between the keyword and the page number returned by the server is obtained, and the correspondence directory between the keyword and the page number is displayed in the H5 in the form of an outline directory. When the user operates the correspondence directory, the page number corresponding to the keyword is obtained, and the page number is used as the designated page number to request to load the page, and the keyword in the p element of the page is replaced with keyword / span to realize the reverse display of the keyword.

[0027] Furthermore, text download in the JS interface: sending web request service information to the server in the interface, obtaining the text information returned by the server, and saving it as a local file;

[0028] Download the original PDF in the JS interface: Send web request service information to the server in the interface, obtain the data returned by the server and save it as a local file.

[0029] The beneficial effects of adopting this technical solution are:

[0030] The present invention designs a service program to perform functions such as split conversion, text indexing, full-text search, and file download on PDF files; and designs a JS interface for rendering PDF file pages, text search positioning, and text download. This solves the blocking and pausing problems that occur when using plug-ins such as PDF.js to view large PDF files online, and also solves the problem that text search and text download and copying cannot be performed when converting large PDF files into single-page image files for online viewing.

[0031] The method for viewing large PDF files online through a dedicated service and a JS interface has the following characteristics: 1) converting large PDF files into hypertext data packets page by page, using h5 The element displays the specified page data package in the client browser. You can set 1) The CSS rendering format of the element is used to achieve page preview and printing effects, and supports various browsers and terminals; 2) The method of imperceptibly loading the specified page and the data packets of the pages before and after the specified page is adopted to avoid loading the entire PDF file at one time, improve the user experience of viewing large PDF files, and may save traffic; 3) Pre-establish a search index for the PDF body text and page number in the full-text search engine, so that the service can quickly respond to JS requests for full-text search of keywords; 4) In addition to saving the full-text text of the PDF file, text data packets are established by page and saved separately, supporting the download of single-page text data and full-text text data; 5) Using the browser COOKIE technology, the current viewing status of the PDF file (the relationship between the file name summary value and the current page) is saved on the client. The next time you view the same file, you do not need to reload the entire PDF file, and you can directly load the specified page corresponding to the file name summary value. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 This is a timing diagram of the uploading, splitting and conversion of a PDF file in a server in an embodiment of the present invention;

[0033] Figure 2 This is a timing diagram of loading a specified page by a JS interface in an embodiment of the present invention;

[0034] Figure 3 This is a full-text search timing diagram in an embodiment of the present invention;

[0035] Figure 4 This is a timing diagram of the pages before and after the specified page is loaded imperceptibly in an embodiment of the present invention. DETAILED DESCRIPTION

[0036] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is further described below with reference to the accompanying drawings.

[0037] In this embodiment, see Figure 1 and Figure 2 As shown, the present invention proposes a method for viewing a large PDF file online, comprising:

[0038] On the server side: receive the PDF file uploaded by the browser and save it in the file directory established by the summary value of the PDF file name; use the file conversion service to convert each page of the PDF file into a hypertext data packet and a plain text data packet, and save them in the corresponding summary value file directory; establish a PDF search index in the search engine and provide full-text search keyword service; respond to the browser request to return the specified page data packet, respond to the browser full-text search keyword service, respond to the browser to download the PDF original file, and respond to text download;

[0039] In the JS interface end: JS interface for detecting the historical viewing status of PDF files; JS interface for requesting to load the specified page and obtaining the hypertext data packet returned by the server; rendering the JS interface using the hypertext data packet; JS interface for unconsciously loading the previous and next pages of the specified page; sending full-text search keywords to the service, and establishing an outline directory corresponding to the page number and keyword in h5 according to the search result information returned by the service; copying text and downloading PDF files.

[0040] As an optimization solution of the above embodiment:

[0041] On the server side:

[0042] a. File receiving service: When receiving a PDF file uploaded by a browser, a new directory called the file directory is created on the server with the MD5 digest value of the PDF file name, and the file is saved in the file directory, and then the file conversion service b is notified.

[0043] b. File conversion service: When splitting and converting a PDF file, each page of the PDF file is converted into two data packets: one is a hypertext data packet, named in the format of "page number".html" and saved in the file directory; the other is a plain text data packet, named in the format of "page number".txt" and saved in the same file directory;

[0044] The plain text file is used to establish the index search relationship between the file name summary value, page number and text data packet in the c full-text search keyword service, as well as the text download of the specified page;

[0045] At the same time, the text of all pages is merged into one file, named PDF file name summary value.txt, and saved in the file directory.

[0046] c. Figure 3 As shown, the full-text search keyword service: establishes a full-text index search relationship of the file name summary value, page number, and text data packet for the document converted into plain text data in the search engine. This service can be implemented using tools such as the Solr search engine and the full-text index database engine.

[0047] d. Respond to the browser request and return the specified page data packet: When the service program receives the file information request that the browser needs to view (including the PDF file name, the MD5 digest value of the file name, and the page number array), it locates the corresponding file directory, reads the contents of all files corresponding to the page number array in the file directory (named "page number.html"), and returns the content of each file in the form of a JSON array;

[0048] e. Respond to the browser's full-text search keywords: When the service program receives the keyword information that the browser needs to search for in the full text (including PDF file name, PDF file name summary value, and search keywords), it searches the PDF file name summary value, page number, and keyword through the search engine, and returns the corresponding relationship in the form of a JSON array.

[0049] f. Respond to the browser to download the original PDF file: When the service program receives the information that the browser needs to download the PDF file (including the PDF file name and the PDF file name summary value), it locates the corresponding file directory, reads the PDF file in the file directory and returns.

[0050] g. Response text download: When the service program receives information that the browser needs to download a PDF file (including PDF file name, PDF file name summary value, and page number), it locates the file directory. If there is page number information, it reads the "page number.txt" file content and returns it. If there is no page number information, it reads the "PDF file name summary value.txt" file content in the file directory and returns it.

[0051] As an optimization solution of the above embodiment:

[0052] In the JS interface:

[0053] h. JS interface for detecting the historical viewing status of PDF files: Before loading the PDF file, check whether the viewing page number corresponding to the file name summary value is saved in the cookie. If so, use the page number as the starting page number for loading the file. If not, use 1 as the starting page number for loading the file, and call i to complete the page loading.

[0054] i. Request to load the JS interface of the specified page: Generate the summary value of the PDF file name to be viewed in the JS service interface, and send the PDF file name, PDF file name summary value, and starting page number (which can be a page number array) to d. The server responds to the browser request and returns the specified page data packet, thereby obtaining the hypertext data packet returned by the server.

[0055] j. Hypertext data packet rendering JS interface: After the browser receives the hypertext data packet returned in i, it creates p tag elements in the H5 page in the order of page numbers and sets the id of the p tag element to the page number (that is, the format is: <p id=”页号”>), the CSS style of the p tag rendering can be set according to the A4 standard, the hypertext data packet can be rendered, and k can be notified to load the previous and next pages of the current page without perception.

[0056] k. Figure 4 As shown, the JS interface for imperceptibly loading the pages before and after the specified page: use the JS window object method window.setTimeout to start the background thread to load the pages before and after the specified page; in this method, it is determined whether the pages before and after the specified page are loaded, that is, whether there is a p tag element with an ID value of the loaded page number in the H5 page. If not, a request message (including: PDF file name, MD5 digest value of the PDF file name, and array of page numbers) is sent to the server, and i is called to load the hypertext data packet of the page.

[0057] l. Use Y-axis scrolling in H5 pages to load the JS interface without perception: When viewing a page that has been loaded with p element rendering, obtain the vertical axis scroll offset value of the scroll bar through the scroll bar's scroll event, calculate the p element currently being viewed based on the relationship between the position of the p element of each page in the page and the scroll bar offset value, and obtain the ID value of the p element, that is,

[0058] Get the page number currently being viewed;

[0059] The correspondence between the PDF file name summary value and the page number is saved in a cookie as the historical viewing status information of the file; the page number is used as the designated page number, and then the JS interface method of loading the pages before and after the designated page is performed imperceptibly to realize the loading of the hypertext data packet of the page.

[0060] m. Perform full-text search in the JS interface: send web request service information (including search keywords, pdf file name, and pdf file name summary value) to the server in the interface, and obtain the corresponding relationship between keywords and page numbers returned by the server. Display the corresponding relationship directory between keywords and page numbers in the form of an outline directory in H5. When the user operates the corresponding relationship directory, the page number corresponding to the keyword is obtained, and the page number is used as the specified page number to request to load the page, and the keyword in the p element of the page is replaced with <span style="color:white;background:blue”>Keyword / span, to realize reverse display of keywords.

[0061] n. Text download in JS interface: Send web request service information (including PDF file name, PDF file name summary value, page number) to the server in the interface, obtain the text information returned by the server, and save it as a local file;

[0062] o. Download the original PDF in the JS interface: Send web request service information (including PDF file name, PDF file name summary value) to the server in the interface, obtain the data returned by the server and save it as a local file.

[0063] The above shows and describes the basic principles and main features of the present invention and the advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.

Claims

1. A method for viewing a large PDF file online, characterized in that: include: On the server side: receive the PDF file uploaded by the browser and save it in the file directory created by the PDF file name summary value; Use the file conversion service to convert the body of each page of the PDF file into a hypertext packet and a plain text packet, and save them in the corresponding summary value file directory; Establish PDF search index in search engine, provide full-text search keyword service; respond to browser request to return specified page data packet, respond to browser full-text search keyword service, respond to browser download PDF original file, respond to text download; In the JS interface end: JS interface for detecting the historical viewing status of PDF files; JS interface for requesting to load the specified page and obtaining the hypertext data packet returned by the server; rendering the JS interface using the hypertext data packet; JS interface for unconsciously loading the previous and next pages of the specified page; sending full-text search keywords to the service, and establishing an outline directory corresponding to the page number and keyword in h5 according to the search result information returned by the service; copying text and downloading PDF files.

2. A method for viewing a large PDF file online according to claim 1, characterized in that: The file receiving service on the server side: when receiving a PDF file uploaded by a browser, a new directory is created on the server with the MD5 digest value of the PDF file name, called the file directory, and the file is saved in the file directory, and then the file conversion service is notified.

3. A method for viewing a large PDF file online according to claim 2, characterized in that: The file conversion service on the server side: when splitting and converting a PDF file, each page of the PDF file is converted into two data packets: one is a hypertext data packet named in the page number .html format and saved in the file directory; the other is a plain text data packet named in the page number .txt format and saved in the same file directory; The plain text file is used to establish the index search relationship between the file name summary value, page number and text data package in the full-text search keyword service, as well as the text download of the specified page; At the same time, the text of all pages is merged into one file, named PDF file name summary value.txt, and saved in the file directory.

4. A method for viewing a large PDF file online according to claim 3, characterized in that: The full-text search keyword service on the server side: establishes a full-text index search relationship of the file name summary value, page number and text data packet for the document converted into plain text data in the search engine.

5. A method for viewing a large PDF file online according to claim 4, characterized in that: Respond to browser requests and return the specified page data packet: When the service program receives a request for file information that the browser needs to view, it locates the corresponding file directory, reads the contents of all files corresponding to the page number array in the file directory, and returns the contents of each file in the form of a JSON array; Respond to the browser's full-text search keywords: When the service program receives the keyword information that the browser needs to search for in the full text, it searches the PDF file name summary value, page number and keyword through the search engine, and returns the corresponding relationship in the form of a JSON array; Respond to the browser downloading the original PDF file: When the service program receives the information that the browser needs to download a PDF file, it locates the corresponding file directory, reads the PDF file in the file directory and returns it; Response text download: When the service program receives information that the browser needs to download a PDF file, it locates the file directory. If there is page number information, it reads the page number .txt file content and returns it. If there is no page number information, it reads the PDF file name summary value .txt file content in the file directory and returns it.

6. A method for viewing a large PDF file online according to claim 1, characterized in that: JS interface for detecting the historical viewing status of PDF files. Before loading a PDF file, check whether the viewing page number corresponding to the file name summary value is saved in the cookie. If so, use the page number as the starting page number for loading the file. If not, use 1 as the starting page number for loading the file.

7. A method for viewing a large PDF file online according to claim 1, characterized in that: Request to load the JS interface of the specified page: Generate the summary value of the PDF file name to be viewed in the JS service interface, and send the PDF file name, PDF file name summary value, and starting page number to d for a WEB service request. The server responds to the browser request and returns the specified page data packet, thereby obtaining the hypertext data packet returned by the server; Hypertext data packet rendering JS interface: After the browser receives the returned hypertext data packet, it creates p tag elements in the H5 page in the order of page numbers, sets the id of the p tag element to the page number, sets the CSS style of the p tag rendering according to the A4 standard, and renders the hypertext data packet; JS interface for loading the pages before and after the specified page without perception: Use the JS window object method to start the background thread to load the pages before and after the specified page; In this method, it is determined whether the previous and next pages of the specified page are loaded, that is, whether there is a p tag element with an ID value of the loaded page number in the H5 page. If not, a request message is sent to the server to realize the loading of the hypertext data packet.

8. A method for viewing a large PDF file online according to claim 9, characterized in that: In the H5 page, the Y-axis scrolling is used to load the JS interface without perception: when viewing the page rendered by the loaded p element, the vertical axis scroll offset value of the scroll bar is obtained through the scroll event of the scroll bar. According to the relationship between the position of the p element of each page in the page and the scroll bar offset value, the p element currently being viewed is calculated, and the ID value of the p element is obtained, that is, the page number currently being viewed is obtained; The correspondence between the PDF file name summary value and the page number is saved in a cookie as the historical viewing status information of the file; the page number is used as the designated page number, and then the JS interface method of loading the pages before and after the designated page is performed imperceptibly to realize the loading of the hypertext data packet of the page.

9. A method for viewing a large PDF file online according to claim 1, characterized in that: Full-text search is performed in the JS interface: web request service information is sent to the server in the interface, and the correspondence between keywords and page numbers returned by the server is obtained. The correspondence directory between keywords and page numbers is displayed in the form of an outline directory in H5. When the user operates the correspondence directory, the page number corresponding to the keyword is obtained, and the page number is used as the specified page number to request to load the page, and the keyword in the p element of the page is replaced with keyword / span to realize the reverse display of the keyword.

10. A method for viewing a large PDF file online according to claim 1, characterized in that: Text download in JS interface: send web request service information to the server in the interface, obtain the text information returned by the server, and save it as a local file; Download the original PDF in the JS interface: Send web request service information to the server in the interface, obtain the data returned by the server and save it as a local file.