File previewing method and device, equipment, storage medium and program product
By determining the file type and calling the corresponding preview component for conversion and display, the problem of multiple plug-in dependencies is solved, reducing device burden and improving user experience.
Patent Information
- Application Number
- CN202410802768.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-20
- Publication Date
- 2024-09-03
AI Technical Summary
When previewing multiple types of files, multiple plug-ins need to be installed, which increases the burden on the device and affects the user experience.
By determining the target file type corresponding to the file preview request, calling the corresponding preview display component for conversion and display, eliminating the dependence on multiple independent preview tools, and using a unified preview interface to display different types of files.
It reduces the burden on the device, provides a seamless operating experience and consistent visual effects, and improves the user's reading experience.
Smart Images

Figure CN118585281A
Abstract
Description
Technical Field
[0001] The present application relates to the field of file preview technology, and in particular to a file preview method, device, equipment, storage medium and program product. Background Art
[0002] Currently, users can preview image-type, PDF-type and other files online through web pages.
[0003] However, when previewing multiple types of files, files with different types of parameters need to use different plug-ins, so multiple plug-ins need to be installed to support the operation of viewing files with different types of parameters, which increases the burden on the device. Summary of the invention
[0004] The main purpose of the present application is to provide a file preview method, apparatus, device, storage medium and program product, aiming to solve the technical problem that when previewing files of different parameter types, multiple plug-ins need to be installed, thereby increasing the burden on the device.
[0005] To achieve the above purpose, the present application proposes a file preview method, comprising:
[0006] Determine the target file corresponding to the file preview request;
[0007] Based on the type parameter of the target file, calling the preview display component corresponding to the type parameter; the type parameter is any one of the PDF format, the image format, the hypertext markup language HTML format and the inline frame Iframe format;
[0008] Convert the target file into a preview file based on the preview display component;
[0009] The preview file is displayed in the preview interface.
[0010] In one embodiment, the step of converting the target file into a preview file based on the preview display component includes:
[0011] If the parameter type of the target file is a picture format, the uniform resource locator of the target file is imported into the picture tag, and the target picture corresponding to the target file is called using the file interface;
[0012] If the parameter type of the target file is in Iframe format, the uniform resource locator of the target file is imported into the Iframe tag to display the target webpage corresponding to the target file on the preview interface;
[0013] If the target file is in HTML format, the segmentation tag is called to segment the text content of the target file to obtain an HTML file corresponding to the target file;
[0014] If the target file is in PDF format, the target file is segmented to obtain multiple target sub-files, each target sub-file is parsed to obtain PDF text content corresponding to each target sub-file, and the canvas component is called to convert each PDF text content into image text.
[0015] In one embodiment, after the step of displaying the preview file on the preview interface, the method further includes:
[0016] If a user operation on the download control is received, the uniform resource locator of the target file is determined;
[0017] Calling an acquisition interface to acquire target data corresponding to the uniform resource locator of the target file;
[0018] Convert target data into unstructured data;
[0019] Call the Save As function to download unstructured data.
[0020] In one embodiment, after displaying the preview file on the preview interface, the method further includes:
[0021] If a user operation on the print control is received, the uniform resource locator of the target file is determined;
[0022] If the configuration parameter type of the uniform resource locator of the target file is a string, calling a new display interface to load the target file, and performing a printing operation after the loading is complete;
[0023] If the configuration parameter type of the uniform resource locator of the target file is an array, the target file is converted into unstructured data, the unstructured data is loaded in a new display interface based on the parameter type of the target file, and a printing operation is performed after the loading is completed.
[0024] In one embodiment, after the preview file is displayed on the preview interface, the following step is also included:
[0025] If a new file preview request is received, determining a uniform resource locator corresponding to the new file preview request;
[0026] Downloading a new target file corresponding to the new file preview request based on the uniform resource locator corresponding to the new file preview request;
[0027] Determine whether the new target file is consistent with the target file;
[0028] If the new target file is consistent with the target file, the preview file corresponding to the target file is called;
[0029] If the new target file is inconsistent with the target file, then determining the difference part and the same part between the new target file and the target file;
[0030] Calling the preview display component corresponding to the parameter type of the new target file to convert the difference part into the first sub-preview file;
[0031] Determine a second preview sub-file corresponding to the same portion from the target file;
[0032] The first sub-preview file and the second sub-preview file are concatenated to obtain a preview file corresponding to a new target file.
[0033] In one embodiment, after the step of determining the target file corresponding to the file preview request, the method further includes:
[0034] Determine the file number of the target file;
[0035] If the number of files is greater than the preset number of files, the preview file corresponding to the target file is displayed using the single file preview mode;
[0036] If the number of files is greater than the preset number of files, the preview files corresponding to the target files are displayed using the multi-file preview mode.
[0037] In addition, to achieve the above purpose, the present application also proposes a file preview device, which includes:
[0038] A determination module, used to determine a target file corresponding to a file preview request;
[0039] A calling module, used for calling a preview display component corresponding to a type parameter based on a type parameter of a target file; the type parameter is any one of a PDF format, a picture format, a hypertext markup language HTML format, and an inline frame Iframe format;
[0040] A conversion module, used for converting a target file into a preview file based on the preview display component;
[0041] The display module is used to display the preview file on the preview interface.
[0042] In addition, to achieve the above objectives, the present application also proposes a file preview device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the file preview method as described above.
[0043] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the file preview method as described above are implemented.
[0044] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the file preview method as described above are implemented.
[0045] One or more technical solutions proposed in this application have at least the following technical effects:
[0046] Compared with the method of installing multiple plug-ins to view files of different types of parameters in the related art, the file preview method proposed in this application directly calls the preview display component corresponding to the type parameter of the target file to convert the target file into a preview file when receiving the user's file preview request, that is, by calling the preview display component corresponding to the target file type to convert the target file into a preview file, there is no need to install multiple independent preview tools, eliminating the reliance on multiple independent preview tools for previewing files of different types of parameters, thereby reducing the burden on the device. At the same time, no matter what type of parameter the target file is, after converting it to a preview file, a unified preview interface is used to display the preview file corresponding to the target file, which can ensure a seamless transition and consistent visual experience for the user in operation, thereby bringing a better reading experience to the user. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0049] Figure 1 A flowchart of the first embodiment of the method for previewing application documents is provided;
[0050] Figure 2 A schematic diagram of file parameters for different types of parameters for this application;
[0051] Figure 3 A schematic diagram of a user inputting a file preview request and personalized parameters for this application;
[0052] Figure 4 A schematic diagram of converting a target file into a preview file using a preview display component corresponding to the target file in this application;
[0053] Figure 5A flowchart of calling the PDF js library to convert a target file of parameter type into PDF format for this application;
[0054] Figure 6 This is a schematic diagram of the preview interface of this application;
[0055] Figure 7 This is a schematic diagram of the preview interface of this application divided by function;
[0056] Figure 8 A schematic diagram of thumbnails of multiple target files of this application;
[0057] Fig. 9 This is a preview interface diagram of a file that cannot be previewed in this application;
[0058] Fig.10 This is a schematic diagram of the module structure of the file preview device in the embodiment of the present application;
[0059] Fig.11 Schematic diagram of the device structure of the hardware operating environment involved in the file preview method in the embodiment of the present application.
[0060] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0061] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0062] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0063] The main solution of the embodiment of the present application is: determine the target file corresponding to the file preview request; based on the type parameter of the target file, call the preview display component corresponding to the type parameter; the type parameter is any one of PDF format, picture format, hypertext markup language HTML format and inline frame Iframe format; based on the preview display component, convert the target file into a preview file; and display the preview file on the preview interface.
[0064] At present, with the development of technology, the web page preview function has been expanded to cover a variety of file type parameters, such as image format, PDF format, etc.
[0065] The current plug-ins are limited to a single file type parameter. When you need to preview files with multiple types of parameters, you need to install multiple plug-ins to support the preview of files with multiple types of parameters, which not only increases the burden on the device, but may also cause compatibility or stability issues. In addition, the switching and loading of components between different plug-ins may slow down the response speed of the web page and affect the overall user experience.
[0066] For developers, the challenges are equally severe. They must integrate multiple specific libraries and dependencies to support files of various parameter types, which not only complicates the development environment, but also easily causes conflicts in dependency management and consumes a lot of time. In addition, customizing the parsing and processing code for each parameter type of file greatly increases the development workload. The uniqueness of each parameter type requires developers to have an in-depth understanding and coding, which may cause code redundancy, increase maintenance difficulties, and easily breed errors. Cross-platform compatibility is also a tricky issue. The limitations of certain libraries may limit the universality of the application, and additional work is required to ensure stable operation on all target platforms.
[0067] The present application provides a solution. Compared with the related art of viewing files of different types of parameters by installing multiple plug-ins, the present application directly calls the preview display component corresponding to the type parameter of the target file to convert the target file into a preview file when receiving the user's file preview request, that is, by calling the preview display component corresponding to the target file type to convert the target file into a preview file, there is no need to install multiple independent preview tools, eliminating the reliance on multiple independent preview tools for previewing files of different types of parameters, thereby reducing the burden on the device. At the same time, no matter what type of parameter the target file is, after converting it to a preview file, a unified preview interface is used to display the preview file corresponding to the target file, which can ensure a seamless transition and consistent visual experience for the user in operation, thereby bringing a better reading experience to the user.
[0068] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a file preview device, etc. The following takes the file preview device as an example to illustrate this embodiment and the following embodiments.
[0069] Based on this, the present application embodiment provides a file preview method, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the document preview method of this application.
[0070] In this embodiment, the file preview method includes steps S10 to S40:
[0071] Step S10: determining the target file corresponding to the file preview request.
[0072] In this embodiment, the file preview request may be a request containing file data such as the file identifier, file path, and file parameters of the target file. The file parameters may be parameters such as type (type parameter), url (Uniform Resource Locator: Uniform Resource Locator) and httpHeader (header request information), as shown in FIG. Figure 2 As shown, Figure 2 A schematic diagram of file parameters for different types of parameters for this application.
[0073] Specifically, the user can input a file preview request by operating a virtual keyboard and / or controls of the file preview device. After receiving the file preview request, the file preview device can determine the file that the user needs to preview, that is, the target file, according to the file identifier or file path in the file preview request.
[0074] It is understandable that in order to make the preview interface for displaying preview files more in line with the user's personal preferences, further, the user can enter personalized parameters to adjust the preview interface through interaction with the file preview device. For example, the user can click on the pop-up control or the page embedded control to adjust the preview interface to a pop-up form or a page form. Alternatively, the user can decide whether to display the search bar by adjusting the setting parameters in the showSpreadBtn (show spread) control, that is, when the parameter of the showSpreadBtn control is set to false, the search bar will not be displayed. Alternatively, the user can use the defaultScale (default scale) control to determine whether to display the target file using the default scale. That is, when the user inputs a file preview request, he can also input personalized parameters to the file preview device at the same time, refer to Figure 3 As shown, Figure 3 A schematic diagram of the user inputting a file preview request and personalized parameters for this application, so that the user can adjust the preview interface according to personal needs.
[0075] Step S20: Based on the type parameter of the target file, a preview display component corresponding to the type parameter is called.
[0076] The type parameter is any one of PDF format, image format, hypertext markup language HTML format, and inline frame Iframe format.
[0077] Step S30: converting the target file into a preview file based on the preview display component.
[0078] After determining the target file, the preview file component corresponding to the target file can be called according to the type parameter of the target file, that is, the preview display component corresponding to the type parameter is called to convert the target file into a preview file. Different preview display components have different specific operation methods when converting the target file into a preview file. Therefore, in order to quickly and accurately convert the target file into a preview file, further, as an optional implementation, step S30 specifically includes:
[0079] Step S301: if the parameter type of the target file is a picture format, the uniform resource locator of the target file is imported into the picture tag, and the target picture corresponding to the target file is called using the file interface.
[0080] Step S302: if the parameter type of the target file is an Iframe format, the uniform resource locator of the target file is imported into the Iframe tag to display the target web page corresponding to the target file on the preview interface.
[0081] Step S303: If the target file is in HTML format, the segmentation tag is called to segment the text content of the target file to obtain an HTML file corresponding to the target file.
[0082] Step S304, if the target file is in PDF format, the target file is segmented to obtain multiple target sub-files, each target sub-file is parsed to obtain the PDF text content corresponding to each target sub-file, and the canvas component is called to convert each PDF text content into image text.
[0083] In this embodiment, in order to facilitate the management of multiple preview display components, multiple preview display components can be encapsulated into the internal file of Content using Content.tsx. When calling the preview display component, switching judgment can be made according to the type of the target file.
[0084] Specifically, after determining the target file, you can choose different ways to convert the target file into a preview file according to the type parameters of the target file, such as referring to Figure 4 As shown, Figure 4 This is a schematic diagram of converting a target file into a preview file using a preview display component corresponding to the target file. Figure 4In the example, when the type parameter of the target file is a picture format, the target file can be displayed through the img tag of HTML5 and the file API (file interface). The img tag obtains the actual picture content through the network request through the passed-in url, that is, the parameter type of the target file is a picture format, the uniform resource locator of the target file is imported into the picture tag, and the target picture corresponding to the target file is called using the file interface. When the type parameter of the target file is an Iframe format, the corresponding url can be passed in using the Iframe tag of HTML, and the corresponding web page can be obtained using the url, that is, the parameter type of the target file is an Iframe format, and the uniform resource locator of the target file is imported into the Iframe tag to display the target web page corresponding to the target file in the preview interface. When the format of the target file is an HTML format, the div (divider) tag of HTML can be used to include the text content of HTML to realize the display of the HTML format file, that is, the format of the target file is an HTML format, and the segmentation tag is called to segment the text content of the target file to obtain the HTML file corresponding to the target file.
[0085] Correspondingly, when the file parameter type of the target file is PDF format, refer to Figure 5 As shown, Figure 5 The flowchart of calling the PDF js library to convert the parameter type of the target file in PDF format for this application. The PDF js (JavaScript) library can be called to split the PDF file into multiple sub-files. Among them, the PDF js library is an open source library developed by Mozilla, which can be used for free, and the library has the advantages of good rendering performance, support for offline use, high customizability, strong cross-platform capabilities, and high security. After the target file is divided into multiple target sub-files, in order to reduce the initial loading time and memory consumption, the target sub-files can be loaded on demand, and the binary data of the sub-files can be read using the parser, that is, the byte stream, PDF syntax, page, text, image font and other text content in the sub-file are parsed to parse it into a PDF document structure. After obtaining the text content, the canvas component of HTML5 can be used to convert the text content into image text, draw a display page, that is, the format of the target file is PDF format, the target file is divided, and multiple target sub-files are obtained. Each target sub-file is parsed to obtain the PDF text content corresponding to each target sub-file, and the canvas component is called to convert each PDF text content into image text.
[0086] Among them, when converting the target file in PDF format into a preview file, after using the PDF js library to split the target file into multiple sub-target files, it can be loaded on demand in blocks, cached parsing results, use Web Workers for background parsing and conversion, and dynamically adjust the quality according to the screen size and resolution to optimize PDF conversion, thereby improving the performance of PDF preview.
[0087] Step S40: display the preview file on the preview interface.
[0088] In this embodiment, the React framework can be used to build the framework of the preview interface, and Less can be used to write the style of the preview interface to achieve the purpose of improving interface design efficiency and enriching the style, and TypeScript can be combined to enhance type safety and ensure code quality and stability.
[0089] Specifically, after obtaining the preview file, the preview file can be displayed on the preview interface for the user to read. Figure 6 As shown in the figure, in the preview interface, the preview interface consists of the top area, the side sliding bar area, the file content display area and the tail area. The top area contains text information, zoom controls, full screen zoom controls and fuzzy search controls, etc. The side sliding bar is used to display thumbnails of preview files; the file content display area is used to display the contents of preview files; and the tail contains download controls and print controls.
[0090] Alternatively, you can also divide the preview interface according to function, such as referring to Figure 7 As shown, in Figure 7 In the preview interface, the preview interface is divided into a multi-file preview display area and an additional function display area. After receiving a file preview request from a user, the target file is converted into a preview file based on the aforementioned steps, and then the preview file can be displayed in the multi-file preview display area, wherein the multi-file display area includes a sidebar thumbnail list and a file content display area. The single file list in the sidebar thumbnail list is used to display a thumbnail of a single target file, and the multi-file list is used to display thumbnails of multiple target files. The file content display area is used to display target files in image format, PDF format, HTML format, or Iframe format. In the additional function display area, there are a top area and a tail area.
[0091] In the multi-file preview display area, you can use the single file preview mode to display the preview file, or you can use the multi-file preview mode to display the preview file. When using the single file preview mode to display the preview file, you can use the side slide bar to display the thumbnail of the target file. The component that displays the thumbnail of a single target file is encapsulated by Thumbnail.tsx; when using the multi-file preview mode to display the preview file, you can also use the side slide bar to display the thumbnails of multiple target files. The component that displays the thumbnails of multiple target files is encapsulated by FileList.tsx. In the content display area, you can use Content.tsx to encapsulate the content component that displays the target file in image format, HTML format, Iframe format or PDF format. Among them, for the preview file in PDF format, you can use BasePdfViewer.tsx to encapsulate the PDF preview component. For the top area, you can use Header.tsx to encapsulate the top display component, including functions such as zoom in and out, zoom full screen and fuzzy search. For the tail area, you can use Footer.tsx to encapsulate the tail display component, including download function, print function, etc.
[0092] It should be noted that when the user is reading the preview file, if he wants to save the preview file, he can click the download control in the tail area to download the preview file. Therefore, further, as an optional implementation, after step S40, it also includes:
[0093] Step S41: If a user operation for downloading a control is received, the uniform resource locator of the target file is determined.
[0094] Step S42: calling an acquisition interface to acquire target data corresponding to the uniform resource locator of the target file.
[0095] Step S43: convert the target data into unstructured data.
[0096] Step S44, calling the Save As function to download the unstructured data.
[0097] Specifically, after receiving the user's operation on the download control, the file preview device can determine the target file that the user is currently reading and determine the URL of the target file. After determining the URL of the target file, the fetchAPI (get interface) can be used to communicate with the specified URL to obtain the target data of the target file from the server. After obtaining the target data of the target file, the target data can be converted into a Blod object, that is, the target data is converted into unstructured data stored in the memory of the file preview device. After converting the target data into unstructured data, the saveAs function can be called to download the unstructured data, and the unstructured data can be saved locally on the user's device.
[0098] Accordingly, when the user prefers to read paper documents rather than online reading, the user can click the print control in the tail area to print the target document. Therefore, further, as an optional implementation, after step S40, it also includes:
[0099] Step S45: if a user operation on the print control is received, the uniform resource locator of the target file is determined.
[0100] Step S46: If the configuration parameter type of the uniform resource locator of the target file is a string, a new display interface is called to load the target file, and a printing operation is performed after the loading is completed.
[0101] Step S47, if the configuration parameter type of the uniform resource locator of the target file is an array, the target file is converted into unstructured data, and based on the parameter type of the target file, the unstructured data is loaded in a new display interface, and a printing operation is performed after loading is completed.
[0102] Specifically, after receiving the user's operation on the print control, the file preview device can determine the target file currently displayed to the user and determine the uniform resource locator of the target file. After determining the uniform resource locator of the target file, the corresponding printing operation can be performed according to the configuration parameter type of the uniform resource locator. When the configuration parameter type of the uniform resource locator is a string, a new display interface can be called to load the target file, and a printing operation can be performed after the loading is complete. When the configuration parameter type of the uniform resource locator is an array, the target file is converted into unstructured data, and according to the specified MIME type, that is, the parameter type of the target file, the unstructured data is loaded in the new display interface, and a printing operation is performed after the loading is complete.
[0103] In this embodiment, print controls and download controls are provided on the preview interface, which not only enriches the functions of the preview interface, but also facilitates users to automatically download or print target files according to personal preferences and needs, thereby improving user experience.
[0104] It should be noted that, in actual application, the user may read the same target file multiple times, or read files similar to the target file. When the user reads the same file multiple times or reads files similar to the target file, in order to improve the efficiency of responding to the user's file preview request, further, as an optional implementation, after step S40, it also includes:
[0105] Step S50: If a new file preview request is received, a uniform resource locator corresponding to the new file preview request is determined.
[0106] Step S51: downloading a new target file corresponding to the new file preview request based on the uniform resource locator corresponding to the new file preview request.
[0107] Step S52, determining whether the new target file is consistent with the target file.
[0108] Step S53: If the new target file is consistent with the target file, the preview file corresponding to the target file is called.
[0109] Step S54: if the new target file is inconsistent with the target file, then determining the difference part and the same part between the new target file and the target file.
[0110] Step S55: calling the preview display component corresponding to the parameter type of the new target file to convert the difference part into the first sub-preview file.
[0111] Step S56: determining a second sub-preview file corresponding to the same portion from the target file.
[0112] Step S57: concatenate the first sub-preview file and the second sub-preview file to obtain a preview file corresponding to the new target file.
[0113] Specifically, after receiving a new file preview request input by the user, the URL corresponding to the new file preview request can be determined according to the file path in the new file preview request, and the new target file corresponding to the new file preview request can be downloaded according to the URL corresponding to the new file preview request.
[0114] After obtaining the new target file, it can be determined whether the new target file is consistent with the target file by comparing the identifier of the new target file with the identifier of the target file, or by comparing the content hash of the new target file with the content hash of the target file. When the new target file is consistent with the target file, the preview file corresponding to the target file can be directly called, and the preview file corresponding to the target file can be displayed. When the new target file is inconsistent with the target file, the file comparison algorithm can be used to determine the difference and the same part between the new target file and the target file. After determining the same part and the difference part, for the difference part, the preview display component corresponding to the type parameter of the new target file can be called to convert the difference part into the first preview sub-file; for the same part, the second sub-preview file corresponding to the same part can be determined from the target file, and finally the first sub-preview file and the second sub-preview file are spliced to obtain the preview file corresponding to the new target file.
[0115] In this embodiment, when the new target file is consistent with the target file, the preview file corresponding to the target file is directly called. When the new target file is inconsistent with the target file, the difference between the new target file and the target file is converted. This can reduce the number of unnecessary conversions and avoid slow response problems caused by frequent page switching, thereby improving the response efficiency to users' file preview requests.
[0116] Or, further, as another optional implementation, it is also possible to reduce unnecessary conversions and improve code performance by using methods such as useCreaction of the ahooks library and use Memo of react hook in the project code, thereby improving the efficiency of responding to user file preview requests.
[0117] It is understandable that when a user uploads a file preview request, the file preview request may include file identifiers and file URLs of multiple files, or may include a file identifier and file URL of only one file. When the file preview request includes multiple target files, in order to meet the reading needs of different users, further, as an optional implementation, after step S40, it also includes:
[0118] Step S60, determining the number of target files.
[0119] Step S61: If the number of files is greater than the preset number of files, a preview file corresponding to the target file is displayed using a single file preview mode.
[0120] Step S62: If the number of files is greater than the preset number of files, a preview file corresponding to the target file is displayed using a multi-file preview mode.
[0121] Specifically, after receiving the file preview request input by the user, the number of target files can be determined according to the file identifier or file path in the file preview request. When the number of files is 1, the thumbnail component can be used to display the thumbnail of a single file in the sidebar, that is, the AutoSizer component provided by the react-virtualized-auto-sizer library and the FixedSizeList component provided by the react-window library are encapsulated in the Thumbnail component, and the AutoSizer component and the FixedSizeList component can be used to build a high-performance, responsive and adaptive long list as a sidebar. After obtaining the long list, the img tag can be used as the tag of the long list, and the URL of the target file can be imported into the img tag, so as to obtain the actual image through the URL request of the target file, thereby achieving the purpose of displaying the thumbnail of a single target file in the sidebar, that is, when the number of files is greater than the preset number of files, the preview file corresponding to the target file is displayed using the single file preview mode. Among them, the single file preview mode only supports the display of target files in image format and PDF format.
[0122] Correspondingly, when the number of target files is greater than 1, the FileList component can be used to display thumbnails of multiple files in the sidebar, that is, the AutoSizer component provided by the react-virtualized-auto-sizer library and the FixedSizeList component provided by the react-window library are encapsulated in the FileList component, and the AutoSizer component and the FixedSizeList component can be used to build a high-performance, responsive and adaptive long list as a sidebar. After obtaining the long list, different target files can be mounted in the div tag using ref (reference) mounting and div tags to display thumbnails corresponding to each target file, that is, when the number of files is greater than the preset number of files, the preview files corresponding to the target files are displayed using the multi-file preview mode. It should be noted that when the number of files is greater than the preset number of files, there are multiple thumbnails displayed in the sidebar. In order to facilitate the user to quickly view any target file, further, as an optional implementation, the onClickFile (click file) method can be called to display the corresponding target file and the file information of the corresponding target file when clicking on different thumbnails. Figure 8 shown.
[0123] During the user's reading process, in order to ensure that the user can fully understand the file information of the displayed target file, such as when signing a contract or reading an agreement, to ensure that important information is fully read, further, as an optional implementation method, after displaying the preview file, the file interface of the currently displayed preview file can be timed. When the accumulated time reaches the preset time, if a user's sliding operation is received, the next file interface will be displayed to the user.
[0124] In this embodiment, different file preview modes are used to display preview files corresponding to the target files according to the number of target files, and different services can be provided for different files. For example, when there are multiple target files, the preview files corresponding to the target files are displayed using the multi-file preview mode, which can facilitate users to switch the files to be read at any time, reduce the delay when switching between different file types, improve the response speed of the web page, and ensure a smooth browsing experience. When there is one target file, the preview file corresponding to the target file is displayed using the single file preview mode, which can facilitate users to concentrate on reading, thereby improving the user experience. At the same time, when using the side slide bar to display the thumbnails of the target files, using the FixedSizeList and AutoSizer components to create a long list of virtual scrolling can greatly reduce memory usage and conversion time, and reduce the loss of thumbnail display to overall performance.
[0125] It should be noted that, in actual applications, when the target file corresponding to the file preview request is empty, or one of the multiple target files uploaded by the user cannot be previewed, the target file can be displayed in the content display area as damaged and cannot be previewed, such as Fig. 9 shown.
[0126] Furthermore, in order to improve the reusability of the preview display component and the preview interface code, the preview display component and the preview interface can be packaged into an NPM (Node Package Manager) module so that more developers can seamlessly integrate it into their projects, thereby improving the reusability of the code.
[0127] In this embodiment, compared with the related art of viewing files of different types of parameters by installing multiple plug-ins, this application directly calls the preview display component corresponding to the type parameter of the target file to convert the target file into a preview file when receiving the user's file preview request, that is, by calling the preview display component corresponding to the target file type to convert the target file into a preview file, there is no need to install multiple independent preview tools, eliminating the reliance on multiple independent preview tools for previewing files of different types of parameters, thereby reducing the burden on the device. At the same time, no matter what type of parameter the target file is, after converting it to a preview file, a unified preview interface is used to display the preview file corresponding to the target file, which can ensure a seamless transition and consistent visual experience for the user in operation, thereby bringing a better reading experience to the user.
[0128] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the document preview method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0129] This application also provides a file preview device, please refer to Fig.10 , the file preview device comprises:
[0130] A determination module, used to determine a target file corresponding to a file preview request;
[0131] A calling module, used for calling a preview display component corresponding to a type parameter based on a type parameter of a target file; the type parameter is any one of a PDF format, a picture format, a hypertext markup language HTML format, and an inline frame Iframe format;
[0132] A conversion module, used for converting a target file into a preview file based on the preview display component;
[0133] The display module is used to display the preview file on the preview interface.
[0134] The file preview device provided by the present application adopts the file preview method in the above embodiment, which can solve the technical problem that when previewing files of different parameter types, multiple plug-ins need to be installed, thereby increasing the burden on the device. Compared with the related art, the beneficial effects of the file preview device provided by the present application are the same as the beneficial effects of the file preview method provided by the above embodiment, and other technical features in the file preview device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0135] The present application provides a file preview device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the file preview method in the above-mentioned embodiment 1.
[0136] Reference below Fig.11 , which shows a schematic diagram of the structure of a file preview device suitable for implementing an embodiment of the present application. The file preview device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.11 The file preview device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0137] like Fig.11 As shown, the file preview device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the file preview device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the file preview device to communicate with other devices wirelessly or by wire to exchange data. Although the file preview device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided alternatively.
[0138] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0139] The file preview device provided by the present application adopts the file preview method in the above embodiment, which can solve the technical problem that when previewing files of different parameter types, multiple plug-ins need to be installed, thereby increasing the burden on the device. Compared with the related art, the beneficial effects of the file preview device provided by the present application are the same as the beneficial effects of the file preview method provided by the above embodiment, and other technical features in the file preview device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0140] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0141] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0142] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the file preview method in the above-mentioned embodiment.
[0143] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0144] The computer-readable storage medium may be included in the file preview device; or may exist independently without being assembled into the file preview device.
[0145] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by a file preview device, the file preview device: determines a target file corresponding to a file preview request; based on a type parameter of the target file, calls a preview display component corresponding to the type parameter; the type parameter is any one of a PDF format, a picture format, a hypertext markup language HTML format, and an inline frame Iframe format; based on the preview display component, converts the target file into a preview file; and displays the preview file on a preview interface.
[0146] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0147] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0148] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0149] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned file preview method, and can solve the technical problem that when previewing files of different parameter types, multiple plug-ins need to be installed, thereby increasing the burden on the device. Compared with the related art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the file preview method provided by the above-mentioned embodiment, and will not be repeated here.
[0150] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned file preview method when executed by a processor.
[0151] The computer program product provided by the present application can solve the technical problem that when previewing files of different parameter types, multiple plug-ins need to be installed, thereby increasing the burden on the device. Compared with the related art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the file preview method provided by the above embodiment, and will not be repeated here.
[0152] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A file preview method, characterized in that: The method comprises: Determine the target file corresponding to the file preview request; Based on the type parameter of the target file, calling a preview display component corresponding to the type parameter; the type parameter is any one of a PDF format, a picture format, a hypertext markup language HTML format, and an inline frame Iframe format; Converting the target file into a preview file based on the preview display component; The preview file is displayed on the preview interface.
2. The method according to claim 1, characterized in that The step of converting the target file into a preview file based on the preview display component comprises: If the parameter type of the target file is a picture format, importing the uniform resource locator of the target file into the picture tag, and using the file interface to call the target picture corresponding to the target file; If the parameter type of the target file is in Iframe format, importing the uniform resource locator of the target file into the Iframe tag to display the target webpage corresponding to the target file in the preview interface; If the target file is in HTML format, calling the segmentation tag to segment the text content of the target file to obtain an HTML file corresponding to the target file; If the target file is in PDF format, the target file is segmented to obtain multiple target sub-files, each target sub-file is parsed to obtain PDF text content corresponding to each target sub-file, and a canvas component is called to convert each PDF text content into image text.
3. The method according to claim 1, characterized in that After the step of displaying the preview file on the preview interface, the method further includes: If a user operation on the download control is received, the uniform resource locator of the target file is determined; Calling an acquisition interface to acquire target data corresponding to the uniform resource locator of the target file; converting the target data into unstructured data; The Save As function is called to download the unstructured data.
4. The method according to claim 1, characterized in that After displaying the preview file on the preview interface, the method further includes: If a user operation on the print control is received, the uniform resource locator of the target file is determined; If the configuration parameter type of the uniform resource locator of the target file is a string, calling a new display interface to load the target file, and performing a printing operation after the loading is complete; If the configuration parameter type of the uniform resource locator of the target file is an array, the target file is converted into unstructured data, the unstructured data is loaded in a new display interface based on the parameter type of the target file, and a printing operation is performed after loading is complete.
5. The method according to claim 1, characterized in that After displaying the preview file on the preview interface, the method further includes: If a new file preview request is received, determining a uniform resource locator corresponding to the new file preview request; Downloading a new target file corresponding to the new file preview request based on the uniform resource locator corresponding to the new file preview request; Determine whether the new target file is consistent with the target file; If the new target file is consistent with the target file, calling the preview file corresponding to the target file; If the new target file is inconsistent with the target file, determining the difference part and the same part between the new target file and the target file; Calling a preview display component corresponding to the parameter type of the new target file to convert the difference portion into a first sub-preview file; Determining a second sub-preview file corresponding to the same portion from the target file; The first sub-preview file and the second sub-preview file are concatenated to obtain a preview file corresponding to the new target file.
6. The method according to claim 1, characterized in that After the step of determining the target file corresponding to the file preview request, the method further includes: Determine the file quantity of the target file; If the number of files is greater than the preset number of files, a preview file corresponding to the target file is displayed using a single file preview mode; If the number of files is greater than the preset number of files, a preview file corresponding to the target file is displayed using a multi-file preview mode.
7. A file preview device, characterized in that: The device comprises: A determination module, used to determine a target file corresponding to a file preview request; A calling module, used for calling a preview display component corresponding to a type parameter of the target file based on the type parameter of the target file; the type parameter is any one of a PDF format, a picture format, a hypertext markup language HTML format, and an inline frame Iframe format; A conversion module, used for converting the target file into a preview file based on the preview display component; The display module is used to display the preview file on the preview interface.
8. A file preview device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the file preview method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the file preview method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the file preview method according to any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Previewing method and device for multi-type files, equipment and medium
CN118860985A
A preview method, device, equipment and medium for multiple types of files
CN118860985B
Task execution method and device, storage medium and electronic equipment
CN119576885A
Method and device for previewing open format document, electronic equipment and storage medium
CN121092804A
Method, device, electronic equipment and storage medium for open format document preview
CN121092804B
