A Browser-based WASM Printing Plugin Method and System
Through the WASM printing plug-in method, the personalized self-service printing problem of browser printing function is solved, cross-platform, fast and convenient printing functions are realized, and pdf file self-recognition and refined control are supported, which is suitable for self-service devices.
Patent Information
- Application Number
- CN202410952944.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2044-07-16
AI Technical Summary
Traditional browser printing functions cannot meet the needs of personalized self-service printing, and ActiveX plug-ins are limited by operating system and browser support issues.
The WASM printing plug-in method is adopted, and the WASM binary files are obtained, deployed to the web server, and the WASM plug-in function interface is used to download and call the WASM plug-in function interface to realize the processing and printing of the document.
It realizes cross-platform, fast and convenient printing functions, supports self-recognition of PDF files, does not require installation of PDF readers, and has refined control capabilities to meet the needs of self-service printing.
Smart Images

Figure CN119065735B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of browser printing, and particularly relates to a WASM printing plugin method and system based on a browser. Background Art
[0002] Traditional browser-based printing mostly calls the printing window provided by the browser to select a printer, set printing attributes, and then complete the printing operation. This mode cannot meet the silent printing requirements of personalized self-service printing.
[0003] In response to the above problems, two solutions have been developed for printing on self-service devices:
[0004] One solution is to deploy an application program on the printing client. The application program encapsulates each function of printing. The browser front end needs to communicate with the application program and complete each functional service through corresponding interfaces. Another solution is based on the ActiveX plugin.
[0005] In addition to interface development work, the first solution also brings additional communication delays; in addition to being limited to the Windows operating system, the second solution is not supported by mainstream browsers such as Google. Summary of the Invention
[0006] Based on this, it is necessary to provide a WASM printing plugin method and system based on a browser to solve the above technical problems.
[0007] In a first aspect, this application provides a WASM printing plugin method based on a browser, including:
[0008] Obtain a wasm binary file to get a wasm plugin, where the wasm binary file can be recognized by the browser;
[0009] Deploy the wasm plugin to a web server to obtain a wasm plugin address, where the wasm plugin address represents the address of the wasm plugin in the web server;
[0010] At the front end of the browser, download the wasm plugin according to the wasm plugin address to obtain an instance of wasm;
[0011] Obtain an incoming document to be printed, and use the function parameters of the function interface of the wasm instance to parse and process and print the document to be printed.
[0012] In some implementable ways, the step of obtaining a wasm binary file to get a wasm plugin includes:
[0013] Use the emcc command of the Emscripten compiler to compile the source code file into a printer.wasm binary file. The exported functions of the printer.wasm binary file include a dynamic memory allocation function interface, a dynamic memory release function interface, and an execution printing command function interface. The execution printing command function interface includes at least a printing service type and printing service parameters.
[0014] In some implementable ways, the step of deploying the wasm plugin to a web server to obtain the wasm plugin address includes
[0015] Obtain the web server that supports static file hosting;
[0016] Store the wasm plugin in the web server directory to obtain the wasm plugin address.
[0017] In some implementable ways, the step of downloading at the front end of the browser according to the wasm plugin address to obtain an instance of wasm includes:
[0018] At the front end of the browser, use the JavaScript language to download the wasm plugin according to the wasm plugin address using the fetch method to obtain an instance of wasm. The instance of wasm represents instantiating binary data into a wasm instance.
[0019] In some implementable ways, the step of obtaining the incoming document to be printed and using the function parameters of the function interface of the wasm instance to process and print the document to be printed includes:
[0020] According to the incoming document to be printed, obtain the incoming service type and incoming service parameters passed from the front end. The incoming service type represents the type of the document to be printed, and the incoming service parameters represent the relevant parameters of the document to be printed;
[0021] Determine the printing service type according to the incoming service type;
[0022] According to the printing service type and the corresponding printing service parameters, parse the incoming service parameters to obtain the server address of the document to be printed;
[0023] According to the server address, download the document to be printed to the local to obtain the processing result returned by the service;
[0024] Determine whether the processing result is successful or failed according to the processing result returned by the service.
[0025] In some implementable ways, the step of downloading the document to be printed to the local according to the server address and obtaining the processing result returned by the service includes:
[0026] Using the printing service parameters to parse the incoming service parameters to obtain the server address fileurl of the document to be printed;
[0027] According to the server address fileurl of the document to be printed, call the get method of http to download the document to be printed to the local;
[0028] Then, using the printing service parameters to parse the incoming service parameters to obtain the required number of printing papers;
[0029] Compare the required number of printing papers with the remaining number of papers in the printing paper tray to obtain a comparison result;
[0030] If the comparison result is that the remaining number of papers is greater than or equal to the number of printing papers, form a printing instruction; otherwise, form a processing failure instruction.
[0031] In some implementable ways, the step of then using the printing service parameters to parse the incoming service parameters to obtain the required number of printing papers includes:
[0032] Determine the format of the document to be printed according to the binary byte identifier of the incoming document to be printed;
[0033] If the format of the document to be printed is a pdf file, parse the document to be printed to determine the number of pages of the document to be printed;
[0034] Send the printing document to the printer sequentially according to the number of printing pages of the pdf file;
[0035] If the format of the document to be printed is a picture, determine the number of pages of the document to be printed;
[0036] If the format of the document to be printed is not a picture, convert the document to be printed into a picture and determine the number of pages of the document to be printed;
[0037] Send the printing document to the printer sequentially according to the number of printing pages of the picture.
[0038] In some implementable ways, the steps of sending the printing document to the printer sequentially according to the number of printing pages of the pdf file and sending the printing document to the printer sequentially according to the number of printing pages of the picture both include:
[0039] Before the step of sending the printing document to the printer sequentially:
[0040] Parse the incoming service parameters using the printing service parameters to correspondingly obtain the printing attributes of each page of the PDF file or image, where the printing attributes at least include the paper orientation, paper size, and paper tray position;
[0041] Set the printing attributes using the interface of the operating system to correspondingly obtain a PDF file or image with printing attributes;
[0042] Send the PDF file or image with printing attributes to the printer.
[0043] The second aspect of the present invention provides a browser-based WASM printing plugin system, which is applied to the aforementioned browser-based WASM printing plugin method. The system includes:
[0044] An acquisition unit for acquiring a WASM binary file to obtain a WASM plugin, where the WASM binary file can be recognized by the browser;
[0045] A loading unit for deploying the WASM plugin to a web server to obtain a WASM plugin address, where the WASM plugin address represents the address of the WASM plugin in the web server;
[0046] A download unit for downloading the WASM plugin at the front end of the browser according to the WASM plugin address to obtain an instance of WASM;
[0047] A printing unit for acquiring an incoming document to be printed and processing and printing the document to be printed by parsing the function parameters of the function interface of the instance of WASM.
[0048] The third aspect of the present invention provides a computer program, and when the computer program is executed by a processor, the steps of the aforementioned browser-based WASM printing plugin method are implemented.
[0049] Beneficial effects:
[0050] The present application provides a WASM printing plugin method based on a browser. First, a wasm binary file is obtained to get a wasm plugin, where the wasm binary file can be recognized by the browser. Then, the wasm plugin is deployed to a web server to obtain a wasm plugin address, where the wasm plugin address represents the address of the wasm plugin in the web server. Next, at the front end of the browser, the wasm plugin is downloaded according to the wasm plugin address to obtain an instance of wasm. Finally, the incoming document to be printed is obtained, and the function parameters of the function interface of the instance of wasm are used for parsing to process and print the document to be printed. Using the above method, printing can be performed based on WASM of the browser, and the deficiencies of ActiveX plugins are solved in terms of adaptation. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the technical solutions in the embodiments of the present application or in the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0052] Figure 1 It is a flowchart of a WASM printing plugin method based on a browser in an embodiment;
[0053] Figure 2 It is a printing plugin architecture diagram of a WASM printing plugin method based on a browser in an embodiment;
[0054] Figure 3 It is a framework diagram of a WASM printing plugin method based on a browser in an embodiment;
[0055] Figure 4 It is a function diagram of a WASM printing plugin method based on a browser in an embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0056] To facilitate the understanding of the present application, the present application will be described more comprehensively below with reference to the relevant drawings. Embodiments of the present application are shown in the drawings. However, the present application can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, these embodiments are provided to make the disclosure of the present application more thorough and comprehensive.
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terms used in the specification of this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The term "and / or" used herein includes any and all combinations of one or more of the related listed items.
[0058] It can be understood that the terms "first", "second", etc. used in this application may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another.
[0059] Some nouns related to this application are explained below for the purpose of understanding this application:
[0060] WASM, WebAssembly is a binary instruction format that can be used as the compilation target of programming languages such as C, C++, Rust, etc. It is designed for efficient execution and can run in modern browsers. WASM has performance close to native code and is therefore suitable for applications that require high-performance computing, such as games, image processing, scientific computing, etc.
[0061] The Emscripten compiler is an open-source compiler toolchain mainly used to compile C and C++ code into WebAssembly (WASM) or asm.js so that this code can run in a web browser. The emcc command is the main compiler driver in the Emscripten toolchain and is similar to gcc or clang, used to compile C and C++ code into WebAssembly (WASM) or asm.js
[0062] The fetch method is a modern JavaScript API used to make asynchronous HTTP requests over the network. It is used to replace the old XMLHttpRequest, providing more powerful and flexible functions while having a more concise syntax.
[0063] The get method refers to a request method in the HTTP protocol used to request resources on a server.
[0064] The front end refers to the local computer that interacts with the user.
[0065] The back end is the server-side part of an application, responsible for processing data, business logic, and interacting with the database.
[0066] In the current technical scope, the browser printing function is limited by traditional means. Users need to rely on the built-in printing interface of the browser or the printing dialog provided by the operating system to perform operations. This process has certain limitations in terms of functionality, user experience design, and scalability.
[0067] In addition, the business function can only be completed through the browser's own printing dialog, with a single function. It cannot adapt to some special business scenarios, such as silent printing on self-service devices. Moreover, it is impossible to achieve refined management of printing. Due to security reasons, the browser does not allow JavaScript (js) to directly access peripheral hardware devices. This results in the inability to customize and develop the printing function individually and lack of scalability.
[0068] With the rise of WebAssembly (WASM) technology, it has become possible to directly interact with printers using high-performance languages such as C++ in the browser, achieving refined control and comprehensive monitoring of printers.
[0069] In view of this, the present application provides a WASM printing plugin method based on the browser, which proposes encapsulating the printing function into a WASM module plugin and then solving the printing of self-service devices by calling the function of the WASM module in the browser. The present invention can not only be cross-platform but also run in the browser, featuring high efficiency, convenience, and speed. Commonly used browsers can already support WebAssembly (WASM), addressing the deficiencies of ActiveX plugins in terms of compatibility.
[0070] In addition, the printing plugin has the characteristic of self-identification when printing PDF files, without the need to install any PDF readers. It has functions such as simple deployment and refined control of printing to meet specific self-service printing requirements.
[0071] The first aspect of the present invention provides a WASM printing plugin method based on the browser, and the method includes:
[0072] As Figures 1 to 4 shown, S100, obtain the wasm binary file to get the wasm plugin.
[0073] Among them, the wasm binary file can be recognized by the browser.
[0074] Specifically, the emcc command of the Emscripten compiler is used to compile the source code file into a printer.wasm binary file. The exported functions of the printer.wasm binary file include three function interfaces: malloc, free, and print_cmd. Further, malloc is a dynamic memory allocation function interface, free is a function interface for releasing dynamic memory, and print_cmd is a function interface for executing a print command. The execution print command function interface includes at least a print service type and print service parameters. When using the printer.wasm binary file, malloc is used as the dynamic memory allocation function interface for memory allocation. After using the printer.wasm binary file, free is used as the function interface for releasing dynamic memory to release the memory, thereby ensuring the reasonable utilization of memory.
[0075] Exemplarily, print_cmd can have two parameters. cmdtype is the print service type: 0 - print service, 1 - print control service. cmdparam is the print service parameter: in the format of a json string. It includes print attribute parameters and parameters such as the remote print document address.
[0076] S200, deploy the wasm plugin to the web server to obtain the wasm plugin address.
[0077] Wherein, the wasm plugin address represents the address of the wasm plugin in the web server.
[0078] Specifically, obtaining the wasm plugin address includes the following steps:
[0079] Obtain the web server that supports static file hosting.
[0080] Store the wasm plugin in the web server directory to obtain the wasm plugin address.
[0081] It should be noted that the web server can be selected as a server that supports static file hosting. The advantages are as follows: The static file hosting server is used to efficiently provide static resources (such as HTML, CSS, JavaScript, images, WASM files, etc.) without dealing with dynamic content generation. That is to say, files can be transmitted with the least overhead and latency, ensuring that users can quickly load the page. In addition, deploying a static file hosting web server is relatively simple. Just place the files in the specified directory, and the configuration requirements are relatively low. This convenience allows developers to quickly set up and go live with applications, which is suitable for scenarios that require quick deployment. It can also reduce the complexity of the server side and potential failure points, making the system more reliable and stable.
[0082] S300. At the front end of the browser, download the WASM plugin according to the WASM plugin address to obtain an instance of WASM.
[0083] Specifically, at the front end of the browser, use the JavaScript language to download the WASM plugin according to the WASM plugin address by using the fetch method to obtain an instance of WASM. Herein, the instance of WASM represents instantiating binary data into a WASM instance.
[0084] It should be noted that it is easy to introduce the WASM module into the existing Web browser application through JavaScript to achieve code interoperability. JavaScript can call the functions in the WASM module, and WASM can also call the functions of JavaScript, thus realizing seamless cooperation between the two.
[0085] At the front end of the browser, the purpose of obtaining a WebAssembly (WASM) instance through JavaScript is to be able to load, initialize, and call the functions in the WASM plugin. This step is a key part of the WebAssembly workflow because it converts the binary-format WASM file into an instance object that can be called by JavaScript, enabling interoperability between JavaScript and WASM. The WASM file is a compiled binary file that needs to be loaded and parsed by the browser. In JavaScript, the WASM file can be parsed into an executable WebAssembly plugin, thereby realizing the WASM function. After obtaining the WASM instance, it can be accessed through the instance object, and the functions exported in the WASM plugin can be called. These functions are specified during compilation, such as the dynamic memory allocation function interface, the dynamic memory release function interface, and the execution print command function interface. Through the instance object, JavaScript can directly call these functions and obtain the return values. After obtaining the WASM instance, the execution of the WASM plugin can be flexibly controlled in JavaScript. JavaScript can call the functions in WASM, pass parameters, and obtain results, and vice versa. This interoperability enables the combined use of high-performance WASM plugins and flexible JavaScript logic in web applications.
[0086] S400. Obtain the incoming document to be printed, and use the function parameters of the function interface of the instance of WASM to process and print the document to be printed.
[0087] Specifically, S400 includes the following steps:
[0088] Based on the to-be-printed document passed in, obtain the incoming service type and incoming service parameters passed in by the front end; wherein, the incoming service type represents the type of the to-be-printed document, and the incoming service parameters represent the relevant parameters of the to-be-printed document;
[0089] Determine the printing service type according to the incoming service type;
[0090] Parse the incoming service parameters according to the printing service type and the corresponding printing service parameters to obtain the server address of the to-be-printed document;
[0091] Download the to-be-printed document to the local according to the server address to obtain the processing result returned by the service;
[0092] Determine whether the processing result is successful or failed according to the processing result returned by the service;
[0093] It should be noted that according to the to-be-printed document passed in by the front end, the corresponding incoming service type and incoming service parameters can be obtained. That is to say, the incoming service type identifies the operations to be performed on the to-be-printed document, such as monitoring, tracking, controlling, and printing, etc. The service parameters are at the next level of the service type. That is, after determining the service type, the corresponding service parameters can be formed according to the service type. For example, after determining the incoming service type, according to the incoming service type, the printing service type cmdtype in the corresponding print_cmd function interface can be called. Next, use the printing service parameters cmdparam corresponding to the printing service type cmdtype to parse the incoming service parameters in order to obtain the specific parameters required. Another example is to use the printing service parameters cmdparam to perform function parameter parsing on the incoming service parameters, and parse the remote printing document address parameter, that is, the server address of the to-be-printed document. Next, according to the server address, the to-be-printed document can be downloaded to the local computer, so as to obtain the processing result returned by the service as successful, otherwise obtain the processing result returned by the service as failed. The returned processing result is successful or failed. The returned processing result can be returned to the front end and / or the back end. If it is returned to the back end, it is convenient for subsequent computer engineers to understand the reason for the failure; if it is returned to the front end, it is convenient for the operator to immediately understand the processing progress, so as to reprocess or change the processing method, etc.
[0094] It should also be noted that the step of downloading the to-be-printed document to the local according to the server address to obtain the processing result returned by the service includes:
[0095] Parse the incoming service parameters by using the printing service parameters to obtain the server address fileurl of the to-be-printed document;
[0096] Download the document to be printed locally by calling the GET method of HTTP according to the server address fileurl of the document to be printed.
[0097] Then, use the printing service parameters to parse the incoming service parameters to obtain the required number of printing papers.
[0098] Compare the required number of printing papers with the remaining number of papers in the printing paper tray to obtain a comparison result.
[0099] If the comparison result is that the remaining number of papers is greater than or equal to the number of printing papers, a printing instruction is formed; otherwise, a processing failure instruction is formed.
[0100] Specifically, when using the printing service parameters to parse the incoming service parameters, parsing means using a function to perform calculations to obtain the server address fileurl of the document to be printed, and then calling the GET method of HTTP to download the printing document locally. Further, in a browser environment, use JavaScript to call the GET method of HTTP to download the printing document, which can be implemented through the Fetch API (the Fetch API is a JavaScript API for making HTTP requests, mainly used to obtain resources from the network, making asynchronous operations more concise and readable). Next, obtain the status of the default printer through the Spool API (Print Spooler API, used to manage printing jobs and printers) according to the Windows operating system of the local computer; when the operating system of the local computer is Linux, obtain the status of the default printer through lpstat (lpstat is a command used to display printer status on Linux and other Unix-like systems) on Linux, and judge whether the printing status is normal. Then, use the printing service parameters again to parse the incoming service parameters to obtain the number of printing papers. That is to say, the incoming service parameters contain the number of pages, so that the required number of papers can be parsed. Compare the required number of papers with the papers in the current printing paper tray. If the remaining number of papers in the printing paper tray is greater than or equal to the required number of papers to be printed, a printing instruction is formed and sent to the printer; otherwise, a processing failure instruction is formed and returned to the front end or back end as needed.
[0101] It should also be noted that the step of using the printing service parameters to parse the incoming service parameters to obtain the required number of printing papers includes:
[0102] Determine the format of the document to be printed according to the binary byte identifier of the document to be printed passed in.
[0103] If the format of the document to be printed is a PDF file, parse the document to be printed to determine the number of pages of the document to be printed;
[0104] Send the printed document to the printer sequentially according to the number of pages to be printed of the PDF file;
[0105] If the format of the document to be printed is a picture, determine the number of pages of the document to be printed;
[0106] If the format of the document to be printed is not a picture, convert the document to be printed into a picture and determine the number of pages of the document to be printed;
[0107] Send the printed document to the printer sequentially according to the number of pages to be printed of the picture.
[0108] Specifically, when processing the document to be printed, especially when transmitting the document to be printed over the network, the document to be printed will be transmitted and processed in the form of binary data. Among them, the binary byte identifier is to represent the data of the document to be printed as a series of byte streams. In this way, according to the binary byte identifier of the incoming document to be printed, the bytes in the identifier format part are used to determine the format of the document to be printed. If the format represented by the binary bytes of the document to be printed is a PDF file, the document to be printed is parsed to obtain the number of pages of the document to be printed. Next, according to the number of pages, the PDF file is sent to the printer page by page in sequence for printing. If the format represented by the binary bytes of the document to be printed is a picture, it is directly sent to the printer for printing according to the sequence; if the format represented by the binary bytes of the document to be printed is not a picture, such as text, the text is converted into a picture, and then it is sent to the printer for printing according to the sequence.
[0109] In the steps of sending the printed document to the printer sequentially according to the number of pages to be printed of the PDF file and sending the printed document to the printer sequentially according to the number of pages to be printed of the picture, before the step of sending the printed document to the printer sequentially, the following steps are also included:
[0110] Use the printing service parameters to parse the incoming service parameters to correspondingly obtain the printing attributes of each page of the PDF file or picture; among them, the printing attributes at least include the paper orientation, paper size, and paper tray position;
[0111] Use the interface of the operating system to set the printing attributes to correspondingly obtain a PDF file or picture with printing attributes;
[0112] Send the PDF file or picture with printing attributes to the printer.
[0113] It should be noted that, in the foregoing steps, before sending the content to be printed to the printer, it is also necessary to perform attribute parsing on each page, that is, use the printing service parameters to parse the incoming service parameters. After parsing, the printing attributes of each page of the pdf file or picture can be obtained correspondingly. When sending each page of the pdf file or picture to the printer, the printing attributes of each page are sent to the printer at the same time, so that the printer can print the corresponding pdf file or picture according to the printing attributes.
[0114] Example of the printing plug-in call process
[0115] Step 1: Deploy the compiled printer.wasm plug-in to the web server.
[0116] Step 2: The browser front-end javascript downloads printer.wasm through the fetch method.
[0117] const resp = await fetch(printerwasmurl);
[0118] where printerwasmurl is the address of printer.wasm on the remote server.
[0119] Step 3: The browser front-end javascript obtains an instance of wasm.
[0120] const bytes = await resp.arrayBuffer();
[0121] const prntinst= await WebAssembly.instantiate(bytes, {
[0122] env: {},
[0123] });
[0124] Step 4: The browser front-end javascript obtains the function interface through the instance.
[0125] constret=prntinst.exports.print_cmd(cmdtype,wasmcmdstr);
[0126] where
[0127] cmdtype: The incoming service type passed in by the front end.
[0128] cmdparamstr : The incoming service parameter passed in by the front end in json format
[0129] wasmcmdstr: Conversion of the cmdparamstr string passed in by the front-end js.
[0130] The specific conversion is as follows:
[0131] const wasmcmdstr = prntinst.exports.malloc(cmdparamstr.length);
[0132] const HEAP8 = new Int8Array(prntinst.exports.memory.buffer);
[0133] cmdparamstr.split('').forEach((char, index) =>{
[0134] HEAP8[(wasmcmdstr + index)>>0] = char.charCodeAt(0);
[0135] });
[0136] ret: The processing result returned by the service. 0 indicates success, and other values indicate failure.
[0137] Step 5: Release the resources of the wasm module
[0138] prntinst.exports.free(wasmcmdstr);
[0139] Print business examples
[0140] Step 1: Parse the incoming business parameters to obtain the server address fileurl of the document to be printed. Call the http get method to download the document to be printed locally.
[0141] Step 2: On the windows operating system, obtain the status of the default printer through the spool api, and on linux, obtain the status of the default printer through lpstat to determine whether the printing status is normal.
[0142] Step 3: Parse the incoming business parameters again to obtain the capacity of the printing paper tray, and identify whether there is enough paper based on the number of printed papers saved locally.
[0143] Step 4: Parse the document to be printed and identify whether it is a pdf file based on the binary byte identifier of the document to be printed.
[0144] If it is a PDF file, parse the PDF file to identify the number of pages to be printed. Before sending the print content of each page to the printer in a loop, parse the print attributes of each page according to the incoming business parameters, specifically including the paper orientation (landscape or portrait), paper size (A3 or A4), paper tray position, etc. Set the print attributes through the interface of the operating system. After setting the print attributes, send the content of the current page to the printer. Thus, the function of fine printing is achieved.
[0145] Step 5: If the document to be printed is not a picture, such as text, call the corresponding conversion process to convert it into a JPEG picture.
[0146] Step 6: If the document to be printed is a picture, set the paper size, orientation, paper tray position, etc. according to the print attributes of the incoming business parameters, and then send the picture content to the printer.
[0147] Step 7: Loop through steps 4 to 6 above according to the number of copies to be printed passed in by the incoming business parameters.
[0148] Step 8: Feed back the print result to the front end.
[0149] Print control business embodiment
[0150] Control the pause and resume execution of the print queue.
[0151] Step 1: Parse the incoming business parameters to determine whether to pause or resume the task.
[0152] Step 2: If it is a pause, call the Windows spool API or lpstat to obtain the print queue of the default printer, detect the status of the print queue, and set the pause status of the print queue.
[0153] Step 3: If it is to resume execution, set the execution status of the print queue.
[0154] The second aspect of the present invention provides a browser-based WASM printing plugin system, which is applied to the aforementioned browser-based WASM printing plugin method. The system includes:
[0155] An acquisition unit for acquiring a WASM binary file to obtain a WASM plugin, wherein the WASM binary file can be recognized by the browser;
[0156] A loading unit for deploying the WASM plugin to a web server to obtain a WASM plugin address, where the WASM plugin address represents the address of the WASM plugin in the web server;
[0157] A download unit, used to download the wasm plug-in at the front end of the browser according to the wasm plug-in address to obtain a wasm instance;
[0158] The printing unit is used to obtain the incoming document to be printed, and use the function parameter parsing of the function interface of the wasm instance to process and print the document to be printed.
[0159] A third aspect of the present invention provides a computer program, which, when executed by a processor, implements the steps of the aforementioned browser-based WASM printing plug-in method.
[0160] In summary, this application provides a browser-based WASM printing plug-in method, and the printing plug-in mainly supports pictures and PDFs for printing content. Especially for PDF, the printing plug-in has the characteristics of self-identification when printing PDF files, and there is no need to install any PDF reader. Not only does it meet the basic printing functions, but it also realizes the personalized setting of printing properties for each page of PDF, realizing personalized printing in a true sense. It has the functions of simple deployment and refined control of printing, so as to meet specific self-service printing needs.
[0161] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0162] The various embodiments in the present disclosure are described in a progressive manner. For the same or similar parts among the various embodiments, reference can be made to each other, and the key point of each embodiment is to illustrate the differences from other embodiments.
[0163] The protection scope of the present disclosure is not limited to the above embodiments. Obviously, those skilled in the art can make various changes and deformations to the present disclosure without departing from the scope and spirit of the present disclosure. If these changes and deformations fall within the scope of the claims of the present disclosure and their equivalent technologies, the intention of the present disclosure also includes these changes and deformations.
Claims
1. A browser-based WASM printing plugin method, characterized in that, The method includes: Obtain a WASM binary file to get a WASM plugin, where the WASM binary file can be recognized by a browser; Deploy the WASM plugin to a web server to obtain a WASM plugin address, where the WASM plugin address represents the address of the WASM plugin in the web server; At the front end of the browser, download the WASM plugin according to the WASM plugin address to obtain an instance of WASM; Obtain an incoming document to be printed, and use the function parameter parsing of the function interface of the instance of WASM to process and print the document to be printed; where The step of obtaining a WASM binary file to get a WASM plugin includes: Use the emcc command of the Emscripten compiler to compile the source code file into a printer.wasm binary file, where the exported functions of the printer.wasm binary file include a dynamic memory allocation function interface, a dynamic memory release function interface, and an execution print command function interface, and the execution print command function interface includes at least a print service type and print service parameters; The step of obtaining an incoming document to be printed, and using the function parameter parsing of the function interface of the instance of WASM to process and print the document to be printed includes: According to the incoming document to be printed, obtain an incoming service type and incoming service parameters passed from the front end, where the incoming service type represents the type of the document to be printed, and the incoming service parameters represent the relevant parameters of the document to be printed; Determine the print service type according to the incoming service type; According to the print service type and the corresponding print service parameters, parse the incoming service parameters to obtain the server address of the document to be printed; According to the server address, download the document to be printed to the local to obtain a processing result returned by the service; Determine whether the processing result is successful or failed according to the processing result returned by the service.
2. The browser-based WASM printing plugin method according to claim 1, characterized in that The step of deploying the WASM plugin to a web server to obtain a WASM plugin address includes Obtain the web server that supports static file hosting; Store the WASM plugin in the web server directory to obtain a WASM plugin address.
3. The browser-based WASM printing plugin method according to claim 1, wherein The step of, at the front end of the browser, downloading according to the WASM plugin address to obtain an instance of WASM includes: At the front end of the browser, use the JavaScript language to download the WASM plugin according to the WASM plugin address by using the fetch method to obtain an instance of WASM, where the instance of WASM represents instantiating binary data into a WASM instance.
4. The browser-based WASM printing plugin method according to claim 1, wherein The step of, according to the server address, downloading the document to be printed to the local to obtain a processing result returned by the service includes: Use the print service parameters to parse the incoming service parameters to obtain the server address fileurl of the document to be printed; Download the document to be printed locally by calling the GET method of HTTP according to the server address fileurl of the document to be printed; Then, use the printing service parameters to parse the incoming service parameters to obtain the required number of printed sheets; Compare the required number of printed sheets with the remaining number of sheets in the printer tray to obtain a comparison result; If the comparison result is that the remaining number of sheets is greater than or equal to the number of printed sheets, a printing instruction is formed; otherwise, a processing failure instruction is formed.
5. The browser-based WASM printing plug-in method according to claim 4, characterized in that, The step of using the printing service parameters to parse the incoming service parameters to obtain the required number of printed sheets includes: Determine the format of the document to be printed according to the binary byte identifier of the document to be printed passed in; If the format of the document to be printed is a PDF file, parse the document to be printed to determine the number of pages of the document to be printed; Sequentially send the printed document to the printer according to the number of printed pages of the PDF file; If the format of the document to be printed is a picture, determine the number of pages of the document to be printed; If the format of the document to be printed is not a picture, convert the document to be printed into a picture and determine the number of pages of the document to be printed; Sequentially send the printed document to the printer according to the number of printed pages of the picture.
6. The browser-based WASM printing plug-in method according to claim 5, wherein The steps of sequentially sending the printed document to the printer according to the number of printed pages of the PDF file and sequentially sending the printed document to the printer according to the number of printed pages of the picture both include: Before the step of sequentially sending the printed document to the printer: Use the printing service parameters to parse the incoming service parameters to correspondingly obtain the printing attributes of each page of the PDF file or picture, where the printing attributes at least include the paper orientation, paper size, and paper tray position; Set the printing attributes using the interface of the operating system to correspondingly obtain a PDF file or picture with printing attributes; Send the PDF file or picture with printing attributes to the printer.
7. A browser-based WASM printing plugin system, characterized in that Applied to the browser-based WASM printing plugin method according to any one of claims 1-6, the system includes: An acquisition unit for acquiring a WASM binary file to obtain a WASM plugin, where the WASM binary file can be recognized by the browser; A loading unit for deploying the WASM plugin to a web server to obtain a WASM plugin address, where the WASM plugin address represents the address of the WASM plugin in the web server; A download unit for downloading the WASM plugin at the front end of the browser according to the WASM plugin address to obtain an instance of WASM; A printing unit for acquiring the incoming document to be printed and using the function parameter parsing of the function interface of the instance of WASM to process and print the document to be printed; where The step of acquiring the WASM binary file to obtain the WASM plugin includes: Compile the source code file into the printer.wasm binary file using the emcc command of the Emscripten compiler. The exported functions of the printer.wasm binary file include the dynamic memory allocation function interface, the dynamic memory release function interface, and the print command execution function interface. The print command execution function interface includes at least the print service type and the print service parameters; The steps of obtaining the incoming document to be printed and using the function parameters of the function interface of the wasm instance to process and print the document to be printed include: Based on the incoming document to be printed, obtain the incoming service type and incoming service parameters passed from the front end. The incoming service type represents the type of the document to be printed, and the incoming service parameters represent the relevant parameters of the document to be printed; Determine the print service type according to the incoming service type; Parse the incoming service parameters according to the print service type and the corresponding print service parameters to obtain the server address of the document to be printed; Download the document to be printed to the local according to the server address to obtain the processing result returned by the service; Determine whether the processing result is successful or failed according to the processing result returned by the service.
8. A computer-readable storage medium, characterized in that, A computer program is stored thereon, and when the computer program is executed by a processor, the steps of the browser-based WASM printing plugin method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Information processing apparatus and control method thereof, and non-transitory computer-readable storage medium
US20230161527A1