Watermark printing implementation method and device and electronic equipment
By injecting a custom dynamic library into the printing process and changing the printing behavior using hooking technology, automatic watermark addition of GDI and XPS printing types is achieved, solving the problems of high system complexity, large conversion overhead and lack of universality in the existing technology, and improving printing effect and universality.
Patent Information
- Application Number
- CN202510062370.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-05-13
AI Technical Summary
The existing method for printing watermarks of data to be printed has problems such as high system complexity, large conversion overhead of original documents, poor printing effect and lack of universality.
By injecting custom dynamic libraries into the printing process and using hooking technology to change the GDI and XPS printing behavior, watermarks are automatically added during the printing process, reducing system complexity and conversion overhead and improving versatility.
Automatic watermark addition to GDI and XPS printing types is realized, reducing system complexity and conversion overhead, and improving printing effect and versatility.
Smart Images

Figure CN119989307A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of printing data to be printed, and in particular to a method, device and electronic equipment for implementing printing watermarks. Background Art
[0002] When printing data to be printed, adding a watermark to the document is an important way to protect data. Once the document is leaked, the watermark information can be effectively used to trace the source. There are two different types of printing in the Windows operating system, namely GDI printing and XPS printing. GDI is the traditional graphics interface of Windows, which can convert the drawing instructions of the program into a format that the device can understand. It has been widely used since the early versions of Windows. XPS is a document format based on vector graphics. It uses XML language to describe the layout, content and printing information of the document. It was introduced by Microsoft in Windows Vista and later.
[0003] At present, the existing methods for implementing watermarking of data to be printed generally implement watermarking through kernel interception and print redirection. Specifically, all user printing operations are intercepted through kernel threads, and all user printing tasks are virtually redirected by hooking SSDT (System Services Descriptor Table), converting the redirected documents into images and adding watermarks, and redirecting the watermarked images to the original printer. This technology has the current status of high system complexity, high conversion overhead of original documents, and poor printing effect. In addition, the document needs to be converted into an image format, which is only applicable to GDI printing and cannot implement XPS printing, so it also lacks versatility.
[0004] In general, existing printing watermark implementation methods have the problems of high system complexity, high conversion overhead of original documents, poor printing effects and lack of versatility. Summary of the invention
[0005] The purpose of the present invention is to provide a method, device and electronic device for implementing printing watermarks, so as to alleviate the technical problems of the prior art, namely, high system complexity, large conversion overhead of original documents, poor printing effect and lack of versatility, thereby reducing system complexity, conversion overhead of original documents, improving printing effect and increasing versatility.
[0006] In the first aspect, an embodiment of the present invention provides a method for implementing a printing watermark, comprising: determining data to be printed and a custom dynamic library injected into a printing process of the data to be printed, wherein the printing process includes GDI printing behaviors and XPS printing behaviors changed based on hooking technology; identifying the printing type of the data to be printed executed by the printing process; based on the custom dynamic library, using the printing behavior corresponding to the printing type in the printing process to add a watermark during the printing process of the data to be printed.
[0007] In a preferred embodiment of the present invention, the method further comprises: when the printing of the data to be printed is completed, uninstalling the custom dynamic library from the printing process of the data to be printed.
[0008] In a preferred embodiment of the present invention, the above method also includes: based on the inline hook technology, the above custom dynamic library is respectively hooked with the GDI printing function and the XPS printing function in the above printing process to change the GDI printing behavior and the XPS printing behavior in the above printing process.
[0009] In a preferred embodiment of the present invention, the step of identifying the print type of the print process executed to print the data to be printed includes: identifying the print type in the print process according to the print start function called by the print process; wherein the print start function is a GDI document print start function or an XPS job print start function.
[0010] In a preferred embodiment of the present invention, based on the above-mentioned custom dynamic library, a watermark is added in the printing process of the above-mentioned data to be printed by adopting the printing behavior corresponding to the above-mentioned printing type in the above-mentioned printing process, including: when the above-mentioned printing type is a GDI printing type, the context of the above-mentioned data to be printed is obtained according to the input parameters of the GDI page end function called by the above-mentioned printing process; and the custom dynamic library is called to draw a watermark in the context of the above-mentioned data to be printed according to the graphics device interface drawing command provided by the operating system.
[0011] In a preferred embodiment of the present invention, based on the above-mentioned custom dynamic library, the printing behavior corresponding to the above-mentioned printing type in the above-mentioned printing process is adopted to add a watermark in the printing process of the above-mentioned data to be printed, including: when the above-mentioned printing type is the XPS printing type, redirecting the printed output file to a preset folder, and extracting the XPS document corresponding to the above-mentioned data to be printed from the above-mentioned preset folder; calling the custom dynamic library according to the XPS image drawing command provided by the operating system to add a watermark to each page in the above-mentioned XPS document.
[0012] In a preferred embodiment of the present invention, when the above-mentioned printing type is the XPS printing type, the printed output file is redirected to a preset folder, including: obtaining the output path of the above-mentioned output file according to the input parameters of the XPS document printing start function called by the above-mentioned printing process; and modifying the output path of the above-mentioned output file to the preset output path of the above-mentioned preset folder.
[0013] In a preferred embodiment of the present invention, the XPS document corresponding to the above-mentioned data to be printed is extracted from the above-mentioned preset folder, including: obtaining the print data stream in the above-mentioned data to be printed and the length of the above-mentioned print data stream according to the input parameters of the XPS data stream writing function called by the above-mentioned printing process; determining the XPS document corresponding to the data to be printed from the above-mentioned preset folder according to the above-mentioned print data stream and the length of the above-mentioned print data stream.
[0014] In a preferred embodiment of the present invention, the step of calling the custom dynamic library to add the XPS print watermark to each page in the XPS document according to the XPS image drawing command provided by the operating system includes:
[0015] Generate a watermark image according to the preset parameters in the custom dynamic library through the XPS image drawing command; call the XPS file open function through the printing process to load the XPS document; call the XPS content bounding box acquisition function through the printing process to obtain the parameter information of each page of the XPS document; call the XPS image resource creation function through the printing process to load the watermark image into the printing process; call the XPS image brush creation function through the printing process to generate a picture brush of the watermark image; add a watermark to each page based on the picture brush and the drawing area parameters corresponding to the parameter information of each page.
[0016] In the second aspect, an embodiment of the present invention provides a printing watermark implementation device, including: a determination module, used to determine the data to be printed and a custom dynamic library injected into the printing process of the above-mentioned data to be printed, wherein the above-mentioned printing process includes GDI printing behavior and XPS printing behavior changed based on hooking technology; an identification module, used to identify the printing type of the above-mentioned printing process executing the printing of the above-mentioned data to be printed; a printing module, used to add a watermark in the printing process of the above-mentioned data to be printed based on the above-mentioned custom dynamic library and adopt the printing behavior corresponding to the above-mentioned printing type in the above-mentioned printing process.
[0017] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the method.
[0018] The embodiments of the present invention have the following beneficial technical effects:
[0019] The embodiment of the present invention provides a method, device and electronic device for implementing a print watermark, including: determining the data to be printed and a custom dynamic library injected into the printing process of the data to be printed, wherein the printing process includes GDI printing behavior and XPS printing behavior changed based on hook technology; identifying the printing type of the data to be printed executed by the printing process; based on the custom dynamic library, using the printing behavior corresponding to the printing type in the above printing process, adding a watermark in the printing process of the data to be printed. The method realizes automatic watermarking of GDI and XPS printing types without the user having to add additional printing operation steps by dynamically injecting a custom library into the printing process and using hook technology to change the printing behavior. Since it is not necessary to convert the file to be printed into a picture, the conversion cost is reduced and the versatility is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 A schematic diagram of a process for implementing a printing watermark provided by an embodiment of the present invention;
[0022] Figure 2 A schematic diagram of a flow chart of another method for implementing a printing watermark provided by an embodiment of the present invention;
[0023] Figure 3 A schematic diagram of the structure of a device for implementing a printing watermark provided by an embodiment of the present invention;
[0024] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.
[0025] Icons: 31 - determination module; 32 - identification module; 33 - printing module; 41 - memory; 42 - processor; 43 - bus; 44 - communication interface. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] It should also be noted that the information and data processed by this application in the process of printing watermarks are authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with the relevant laws, regulations and standards of the relevant regions, take necessary confidentiality measures, do not violate public order and good customs, and provide corresponding operation entrances for users to choose to authorize or refuse. For example, an interface is set between this system and relevant users or institutions. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or institution through the interface, and obtain relevant information after receiving the consent information fed back by the aforementioned user or institution.
[0029] The existing method for implementing watermarking of data to be printed is generally to implement watermarking through kernel interception and print redirection. Specifically, all user printing operations are intercepted through kernel threads, all user printing tasks are virtually redirected by hooking SSDT, the redirected documents are converted into images and watermarks are added, and the watermarked images are redirected to the original printer. This technology increases the complexity of the system because it intercepts and redirects printing in the kernel. When interception or redirection errors occur, the entire system crashes with a blue screen, so there is a problem of high system complexity; in addition, the watermarking process of this solution requires the original document to be converted into an image, resulting in a large conversion process overhead; in addition, this solution requires the original document to be converted into an image and printed together with the watermark, and the conversion process may cause distortion and affect the printing quality, and it is only applicable to GDI printing and cannot achieve XPS printing, so it also lacks versatility.
[0030] Based on this, the embodiment of the present invention provides a method, device and electronic device for implementing a print watermark. The method reduces system complexity by linking the application programming interface of the GDI print program with the application programming interface of the XPS print program. Since it is not necessary to convert the file to be printed into an image, the conversion cost is reduced and the versatility is improved. In order to facilitate the understanding of the present invention, a method for implementing a print watermark is first introduced in detail.
[0031] Example 1
[0032] In an embodiment of the present invention, Figure 1 A schematic flow chart of a method for implementing a printing watermark provided by an embodiment of the present invention.
[0033] Depend on Figure 1 As can be seen, the method includes:
[0034] Step S101: determining data to be printed and a custom dynamic library injected into a printing process of the data to be printed, wherein the printing process includes GDI printing behavior and XPS printing behavior changed based on hooking technology.
[0035] In some examples, when a custom dynamic library is injected into a printing process, a loading mechanism of the custom dynamic library is triggered, and after the custom dynamic library is loaded, a DllMain function in the custom dynamic library can be executed.
[0036] Hooking is a programming technique that allows developers to insert custom code when a specific event or operation occurs. In the printing process, hooks can be used to intercept, modify or extend printing behavior.
[0037] For GDI printing, hooking might involve intercepting GDI function calls and then adding custom processing logic before or after those function calls.
[0038] For XPS printing, hooking may involve intercepting the creation, processing, or submission of a print job and inserting custom XPS generation or modification logic into these processes.
[0039] Here, custom dynamic libraries are dynamic link libraries developed by developers themselves. Dynamic Link Library (DLL) is a programming technology widely used in Windows operating systems. It allows developers to package commonly used codes, functions and resources into a single file, which can be shared by multiple applications or processes at runtime. By creating custom dynamic libraries, developers can reuse and modularize codes and improve program performance.
[0040] In the above step S101, changing the GDI printing behavior and the XPS printing behavior based on the hooking technology may include: inserting a jump instruction into the starting address of the API related to printing in the memory in the printing process based on the inline hooking technology, and the jump instruction is used to jump to the code position defined by the custom dynamic library, so that the printing process executes the code at the code position. Step S102: Identifying the printing type of the above printing process executing the printing of the above data to be printed.
[0041] Here, both GDI printing and XPS printing call a specific start application programming interface to mark the start of a print. Before GDI prints a document, it calls the GDI document print start function; before XPS prints a document, it generally calls the XPS job print start function, so that the print type in the above printing process can be identified based on the calling of the GDI document print start function and the XPS job print start function.
[0042] Step S103: Based on the above-mentioned custom dynamic library, a watermark is added in the printing process of the above-mentioned data to be printed by adopting the printing behavior corresponding to the above-mentioned printing type in the above-mentioned printing process.
[0043] For the GDI print type, based on a custom dynamic library, a print behavior corresponding to the GDI print type in the printing process of the data to be printed is adopted to add a watermark in the printing process of the data to be printed.
[0044] For the XPS print type, based on the custom dynamic library, the printing behavior corresponding to the XPS print type in the printing process of the data to be printed is adopted, and a watermark is added in the printing process of the data to be printed.
[0045] Exemplarily, in step S103, each time the printing process executes an API hooked to a custom dynamic library, it can jump to the code location defined by the custom dynamic library based on the jump instruction inserted into the starting address of the API in the memory, and execute the code at the code location. After execution, it can jump to execute the original API of the API pre-saved in the custom dynamic library, wherein the original API is the API before being hooked to the custom dynamic library.
[0046] The embodiment of the present invention provides a method for implementing a printing watermark, including: determining data to be printed and a custom dynamic library injected into the printing process of the data to be printed, wherein the printing process includes GDI printing behavior and XPS printing behavior changed based on hook technology; identifying the printing type of the data to be printed executed by the printing process; based on the custom dynamic library, using the printing behavior corresponding to the printing type in the printing process, adding a watermark in the printing process of the data to be printed. The method dynamically injects a custom library into the printing process and uses the hook technology to change the printing behavior, without the user having to add additional printing operation steps, to achieve automatic watermark addition for GDI and XPS printing types, and because it does not need to convert the file to be printed into a picture, it reduces the conversion overhead and improves versatility.
[0047] Example 2
[0048] Based on the above embodiment 1, Figure 2 A schematic flow chart of another method for implementing watermark printing provided by an embodiment of the present invention.
[0049] Step S201: determining the data to be printed and the custom dynamic library injected into the printing process of the data to be printed, wherein the printing process includes the GDI printing behavior and the XPS printing behavior changed based on the hooking technology.
[0050] In this embodiment, the method further includes: based on the inline hooking technology, hooking the custom dynamic library with the GDI printing function and the XPS printing function in the printing process respectively, so as to change the GDI printing behavior and the XPS printing behavior in the printing process.
[0051] Exemplarily, in the process of injecting the above-mentioned custom dynamic library into the printing process, the inline hooking technology can be used to insert a jump instruction to the starting address in memory of each API related to GDI printing or XPS printing in the printing process. The jump instruction is used to jump to the code location defined by the custom dynamic library, so that the printing process executes the code at the code location. In this way, the custom dynamic library is hooked with the application programming interface (Application Programming Interface, API) related to printing, and the original behavior of these application programming interfaces is changed, so as to add a watermark during the printing process.
[0052] Exemplarily, the printing process will call a specific start API for GDI printing or XPS printing to mark the start of a print. For example, before GDI prints a document, it will call the StartDoc function or the StartPage function; before XPS prints a document, it will generally call the StartXpsPrintJob function. In this embodiment, the start APIs of different printing types can be hooked in the custom dynamic library. When the printing process calls the start API of a certain printing type, it will jump to the code position in the custom dynamic library that is hooked to the start API to execute the code.
[0053] As another example, in a custom dynamic library, a GDI page print end function (e.g., EndPage function) and other APIs related to GDI printing are hooked. For example, a GDI page print end function (e.g., EndPage function) is hooked in a custom dynamic library. When the printing process executes the hooked GDI page print end function, based on the GDI page print end function, it jumps to the code position defined by the dynamic library to obtain the current device context parameters, and based on the device context parameters, calls the GdiPlus drawing command to draw a watermark in the device context. After the watermark drawing is completed, the original GDI page print end function defined in the dynamic library ends the printing of the page. It can be understood that the original GDI page print end function is the GDI page print end function in the printing process before being hooked with the dynamic library. Executing the original GDI page print end function defined in the dynamic library is the printing process executing the original API behavior.
[0054] As another example, an XPS document printing start function (eg, StartDocPrinter function) and other APIs related to XPS printing are hooked in a custom dynamic library.
[0055] Step S202: Identify the printing type of the printing process to print the data to be printed.
[0056] In this embodiment, the step of identifying the printing type of the above-mentioned printing process to print the above-mentioned data to be printed includes: identifying the printing type in the above-mentioned printing process according to the printing start function called by the above-mentioned printing process; wherein the above-mentioned printing start function is a GDI document printing start function or an XPS job printing start function.
[0057] Here, the step of identifying the printing type of the printing process executed to print the data to be printed can accurately determine the printing type by identifying whether the printing start function called by the printing process is a GDI document printing start function or an XPS job printing start function, thereby ensuring the correctness and pertinence of subsequent operations such as adding watermarks.
[0058] Step S203: Based on the above-mentioned custom dynamic library, a watermark is added in the printing process of the above-mentioned data to be printed by adopting the printing behavior corresponding to the above-mentioned printing type in the above-mentioned printing process.
[0059] In this embodiment, based on the above-mentioned custom dynamic library, the printing behavior corresponding to the above-mentioned printing type in the above-mentioned printing process is adopted to add a watermark in the printing process of the above-mentioned data to be printed, which may include: when the above-mentioned printing type is a GDI printing type, obtaining the context of the above-mentioned data to be printed according to the input parameters of the GDI page end function called by the above-mentioned printing process; calling the above-mentioned custom dynamic library to draw a watermark in the context of the above-mentioned data to be printed according to the graphics device interface drawing command provided by the operating system.
[0060] Here, based on the above-mentioned custom dynamic library, the printing behavior corresponding to the above-mentioned printing type in the above-mentioned printing process is adopted, and the step of adding a watermark in the printing process of the above-mentioned data to be printed is achieved by accurately drawing the watermark in the context of the data to be printed during the printing process of the GDI printing type, using the custom dynamic library and the graphics device interface drawing commands provided by the operating system, thereby ensuring the accuracy and compatibility of the watermark adding.
[0061] Furthermore, based on the above-mentioned custom dynamic library, the printing behavior corresponding to the above-mentioned printing type in the above-mentioned printing process is adopted to add a watermark in the printing process of the above-mentioned data to be printed, which may include: when the above-mentioned printing type is the XPS printing type, redirecting the printed output file to a preset folder, and extracting the XPS document corresponding to the above-mentioned data to be printed from the above-mentioned preset folder; calling the above-mentioned custom dynamic library according to the XPS image drawing command provided by the operating system, and adding a watermark to each page in the above-mentioned XPS document.
[0062] Here, based on the above-mentioned custom dynamic library, the printing behavior corresponding to the above-mentioned printing type in the above-mentioned printing process is adopted. The step of adding a watermark in the printing process of the above-mentioned data to be printed redirects the output file of the XPS print type to a preset folder and extracts the corresponding XPS document. The XPS image drawing command and custom dynamic library provided by the operating system are used to add a watermark to each page, thereby ensuring the efficiency and accuracy of watermark adding.
[0063] Among them, when the printing type is the XPS printing type, the printed output file is redirected to a preset folder, including: obtaining the output path of the output file according to the input parameters of the XPS document printing start function called by the above printing process; and modifying the output path of the output file to the preset output path of the above preset folder.
[0064] Here, in the above-mentioned case where the printing type is the XPS printing type, the step of redirecting the printed output file to the preset folder redirects the output file to the preset folder by modifying the input parameters of the XPS document printing start function, thereby ensuring that the data to be printed can be accurately stored in the specified location, providing a guarantee for subsequent watermark adding and other processing.
[0065] Exemplarily, extracting the XPS document corresponding to the data to be printed from the preset folder includes: obtaining the print data stream in the data to be printed and the length of the print data stream according to the input parameters of the XPS data stream writing function called by the printing process; determining the XPS document corresponding to the data to be printed from the preset folder according to the print data stream and the length of the print data stream.
[0066] Here, by parsing the XPS data stream and its length in the printing process, the corresponding XPS document is accurately located and extracted from the preset folder, ensuring the accurate acquisition and processing of the printing data, and improving the efficiency and accuracy of the printing task.
[0067] Specifically, when the XPS data stream writing function is called, the print data stream is obtained according to the first input parameter of the XPS data stream writing function, and the length of the data stream is obtained according to the second input parameter of the XPS data stream writing function. It is known that the XPS data stream writing function will add several bytes of prefix information before the XPS data stream, and the XPS data always starts with a string of fixed magic numbers (0x50, 0x4B, 0x03, 0x04), so the KMP algorithm (an improved string matching algorithm) is used to search for the starting position of the XPS document in the data stream; WriteFile is used to write the data stream starting from the specified position to the disk; after completing the modification of the output path, the original data stream writing function is called to start printing.
[0068] Exemplarily, the step of calling the above-mentioned custom dynamic library to add the above-mentioned XPS print watermark to each page in the above-mentioned XPS document according to the XPS image drawing command provided by the operating system includes: generating a watermark image according to the preset parameters in the above-mentioned custom dynamic library through the above-mentioned XPS image drawing command; calling the XPS file open function through the above-mentioned printing process to load the above-mentioned XPS document; calling the XPS content bounding box acquisition function through the above-mentioned printing process to obtain the parameter information of each of the above-mentioned pages of the above-mentioned XPS document; calling the XPS image resource creation function through the above-mentioned printing process to load the above-mentioned watermark image into the above-mentioned printing process; calling the XPS image brush creation function through the above-mentioned printing process to generate the picture brush of the above-mentioned watermark image; adding a watermark to each page based on the above-mentioned picture brush and the drawing area parameters corresponding to the parameter information of each of the above-mentioned pages.
[0069] Step S204: when the printing of the data to be printed is completed, the custom dynamic library is uninstalled from the printing process of the data to be printed.
[0070] Here, after the printing of the data to be printed is completed, the hook to the relevant printing API can be unhooked in the custom dynamic library, and the custom dynamic library can be uninstalled.
[0071] The embodiment of the present invention provides a method for implementing a printing watermark, including: determining data to be printed and a custom dynamic library injected into the printing process of the data to be printed, wherein the printing process includes GDI printing behavior and XPS printing behavior changed based on hook technology; identifying the printing type of the data to be printed executed by the printing process; based on the custom dynamic library, using the printing behavior corresponding to the printing type in the printing process, adding a watermark in the printing process of the data to be printed; when the printing of the data to be printed is completed, uninstalling the custom dynamic library from the printing process of the data to be printed. The method dynamically injects a custom library into the printing process and changes the printing behavior using the hook technology, without the user having to add additional printing operation steps, realizes the automatic watermark addition of GDI and XPS printing types, and automatically uninstalls the custom library after printing is completed, thereby ensuring the stability and security of the system.
[0072] Example 3
[0073] For ease of understanding, this embodiment further details the steps of the method for implementing printing watermarks in specific operations based on Embodiment 2.
[0074] The present invention first hooks the relevant application programming interfaces of GDI printing behavior and XPS printing behavior in a custom dynamic library, and then injects the dynamic library into the printing process. Then, the printing type is identified according to the different application programming interfaces called by the printing process, and different watermark adding logics are executed based on the identified printing type. Finally, when the watermark adding is completed, the custom dynamic library is uninstalled.
[0075] Here, the watermark adding logic may specifically refer to step S203 of the above-mentioned embodiment 2.
[0076] In the process of identifying the print type, both the GDI print behavior and the XPS print behavior will call the start application programming interface of the above-mentioned custom dynamic library to mark the start of a print.
[0077] Exemplarily, before GDI prints a document, it will call the StartDoc function; before XPS prints a document, it will generally call the StartXpsPrintJob function. Here, the StartDoc function is the GDI document printing start function in Example 2; the StartXpsPrintJob function is the XPS job printing start function in Example 2.
[0078] In the actual operation process, the custom dynamic library is hooked up with the start application programming interface of different printing types, and sets the variable indicating the start of printing in the printing process and the variable indicating the current printing type. When the start application programming interface is called, the print start variable is set to true.
[0079] Exemplarily, when a GDI document print start function or a GDI page print start function is called, the print type variable is set to GDI print, and when an XPS job print start function is called, the print type is set to XPS print.
[0080] In one embodiment, when the print type is the GDI print type, the context of the data to be printed in the current printing device is obtained according to the input parameter of the EndPage function called by the print process. Then, the EndPage function of the custom dynamic library is called to draw the watermark in the context of the data to be printed through the drawing command provided by the GdiPlus provided by the operating system. Here, the EndPage function is the GDI page end function in Example 2, and the GdiPlus interface is the graphics device interface in Example 2.
[0081] In another embodiment, when the print type is the XPS print type, the output file is redirected to a preset folder. Since the redirected output file may have been converted into the printer language, it may not contain an XPS document. Therefore, it is necessary to extract the XPS document corresponding to the data to be printed from the preset folder. Finally, the custom dynamic library is called to add a watermark to each page in the XPS document according to the XPS image drawing command provided by the operating system.
[0082] Specifically, the process of redirecting the output file to be printed to the preset folder may include: obtaining the DOC_INFO_1 structure according to the input parameter of the XPS document printing start function called by the printing process, that is, the input parameter pDocInfo, wherein the DOC_INFO_1 structure contains information such as the output path of the document, thereby obtaining the output path of the output file. Finally, modifying the pointer pOutputFile in the DOC_INFO_1 structure to modify the output path of the output file to the preset output path of the preset folder.
[0083] Exemplarily, calling the above-mentioned custom dynamic library according to the XPS image drawing command provided by the operating system, the step of adding a watermark to each page in the above-mentioned XPS document may include: first, using the Gdiplus interface to generate an on-demand watermark image and save it in PNG format on the disk. Then, load the XPS document through the XPS file open function, parse the XPS document through the member function of IXpsOMPackage, and obtain all XPS pages. Then, obtain the width, height and other information of the page content area through the IXpsOMPage::GetContentBox function. Load the watermark image as an XPS resource through the IXpsOMObjectFactory::CreateImageResource function. Generate a picture brush through IXpsOMObjectFactory::CreateImageBrush, and draw the watermark according to the properties such as the width and height of the drawing area. Finally, after drawing all pages, use IXpsOMPackage::WriteToFile to save the XPS document.
[0084] Here, the above IXpsOMPackage is an interface in the Windows XPS object model, which represents a complete XPS document package. It encapsulates all the contents and structures of the XPS document, allowing applications to read, modify and operate various parts of the document; IXpsOMPage::GetContentBox is a method in the Windows XPS object model, which is used to obtain the actual bounding box of the XPS page content. This bounding box defines the visible area of the page content, excluding margins or other non-content areas; IXpsOMObjectFactory::CreateImageBrush function is a method in the Windows XPS object model, which is used to create an image-based brush (IXpsOMImageBrush), which can be used to fill graphics, text or other elements, using images as fill content; IXpsOMPackage::WriteToFile is a method in the Windows XPS object model, which is used to save an XPS document package to a specified path in the file system. This method allows users to persist all modifications made to the XPS document as an actual xps file; IXpsOMObjectFactory::CreateImageResource function is an XPS image resource creation function.
[0085] The printing watermark implementation method provided by the embodiment of the present invention can be applied to the printing scenarios of various documents with security printing requirements, such as financial statements, business plans, patent applications, etc. It is necessary to ensure that these contents will not be disseminated without authorization, and once information leakage occurs, it must be effectively traceable. For example, when an employee prints a document, the solution provided by the embodiment of the present invention can automatically add an appropriate watermark to the printed document to ensure that no matter what printing technology the application is based on (for example: Word is generally based on GDI printing, XPSViewer is generally based on XPS printing), the printed paper will display traceable information such as user name, time, terminal IP, etc.
[0086] Example 4
[0087] Based on the above embodiments, Figure 3 A schematic diagram of the structure of a device for implementing a printing watermark provided in an embodiment of the present invention.
[0088] Depend on Figure 3 As can be seen, the device includes:
[0089] The determination module 31 is used to determine the data to be printed and the custom dynamic library injected into the printing process of the data to be printed, wherein the printing process includes the GDI printing behavior and the XPS printing behavior changed based on the hooking technology.
[0090] The identification module 32 is used to identify the printing type of the to-be-printed data executed by the printing process.
[0091] The printing module 33 is used to add a watermark in the printing process of the data to be printed by adopting the printing behavior corresponding to the printing type in the printing process based on the custom dynamic library.
[0092] In one embodiment, the device further comprises an unloading module connected to the printing module 33; the unloading module is used to unload the custom dynamic library from the printing process of the data to be printed when the printing of the data to be printed is completed.
[0093] In one embodiment, the determination module 31 is further used to hook the custom dynamic library with the GDI print function and the XPS print function in the print process respectively based on the inline hook technology to change the GDI print behavior and the XPS print behavior in the print process.
[0094] In one embodiment, the identification module 32 is further used to identify the printing type in the printing process according to the printing start function called by the printing process; wherein the printing start function is a GDI document printing start function or an XPS job printing start function.
[0095] In one embodiment, the printing module 33 is also used to obtain the context of the above-mentioned data to be printed according to the input parameters of the GDI page end function called by the above-mentioned printing process when the above-mentioned printing type is the GDI printing type; and call the above-mentioned custom dynamic library to draw a watermark in the context of the above-mentioned data to be printed according to the graphics device interface drawing command provided by the operating system.
[0096] In one embodiment, the printing module 33 is also used to redirect the printed output file to a preset folder when the above-mentioned printing type is the XPS printing type, and extract the XPS document corresponding to the above-mentioned data to be printed from the above-mentioned preset folder; call the above-mentioned custom dynamic library according to the XPS image drawing command provided by the operating system to add a watermark to each page in the above-mentioned XPS document.
[0097] In one embodiment, the printing module 33 is further used to obtain the output path of the output file according to the input parameters of the XPS document printing start function called by the printing process; and modify the output path of the output file to the preset output path of the preset folder.
[0098] In one embodiment, the printing module 33 is also used to obtain the print data stream in the data to be printed and the length of the print data stream according to the input parameters of the XPS data stream writing function called by the printing process; and determine the XPS document corresponding to the data to be printed from the preset folder according to the print data stream and the length of the print data stream.
[0099] The printing watermark implementation device provided in the embodiment of the present invention has the same technical features as the printing watermark implementation method provided in the above embodiment, so it can also solve the same technical problems and achieve the same technical effects. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the device described above can refer to the corresponding process in the above method embodiment, and will not be repeated here.
[0100] Example 5
[0101] This embodiment provides an electronic device, including a processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the steps of the printing watermark implementation method.
[0102] This embodiment provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of the method for implementing a printing watermark are implemented.
[0103] See also Figure 4 The structure diagram of an electronic device shown in the figure includes: a memory 41 and a processor 42. The memory 41 stores a computer program that can be run on the processor 42. When the processor executes the computer program, the steps provided by the above-mentioned printing watermark implementation method are implemented.
[0104] like Figure 4 As shown, the device further includes: a bus 43 and a communication interface 44, a processor 42, a communication interface 44 and a memory 41 are connected via the bus 43; the processor 42 is used to execute executable modules stored in the memory 41, such as computer programs.
[0105] The memory 41 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 44 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0106] The bus 43 may be an ISA bus, a PCI bus, or an EISA bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0107] The memory 41 is used to store programs, and the processor 42 executes the programs after receiving the execution instructions. The method executed by the printing watermark implementation device disclosed in any embodiment of the present invention can be applied to the processor 42, or implemented by the processor 42. The processor 42 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 42 or the instructions in the form of software. The above processor 42 can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. It can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present invention. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 41, and the processor 42 reads the information in the memory 41 and completes the steps of the above method in combination with its hardware.
[0108] Furthermore, an embodiment of the present invention also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by the processor 42, the machine-executable instructions prompt the processor 42 to implement the above-mentioned printing watermark implementation method.
[0109] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0110] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0111] The embodiments or examples of the present disclosure are not exhaustive, but are only illustrative of some embodiments or examples, and are not intended to be specific limitations on the scope of protection of the present disclosure. In the absence of contradiction, each step in a certain embodiment or example can be implemented as an independent example, and the steps can be combined arbitrarily. For example, the scheme after removing some steps in a certain embodiment or example can also be implemented as an independent example, and the order of the steps in a certain embodiment or example can be arbitrarily exchanged. In addition, the optional methods or optional examples in a certain embodiment or example can be combined arbitrarily; in addition, the various embodiments or examples can be combined arbitrarily, for example, some or all steps of different embodiments or examples can be combined arbitrarily, and a certain embodiment or example can be combined arbitrarily with the optional methods or optional examples of other embodiments or examples.
[0112] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0113] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0114] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0115] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0116] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for implementing a printing watermark, characterized in that: include: Determine the data to be printed and the custom dynamic library injected into the printing process of the data to be printed, wherein the printing process includes the GDI printing behavior and the XPS printing behavior changed based on the hooking technology; Identify the printing type of the printing process executing printing of the to-be-printed data; Based on the custom dynamic library, a printing behavior corresponding to the printing type in the printing process is adopted to add a watermark during the printing process of the data to be printed.
2. The method for implementing watermark printing according to claim 1, characterized in that: The method further comprises: When the printing of the data to be printed is completed, the custom dynamic library is uninstalled from the printing process of the data to be printed.
3. The method for implementing watermark printing according to claim 1, characterized in that: The method further comprises: Based on the inline hooking technology, the custom dynamic library is hooked to the GDI printing function and the XPS printing function in the printing process respectively, so as to change the GDI printing behavior and the XPS printing behavior in the printing process.
4. The method for implementing watermark printing according to claim 1, characterized in that: The step of identifying the printing type of the printing process for printing the data to be printed comprises: According to the print start function called by the print process, the print type in the print process is identified; wherein the print start function is a GDI document print start function or an XPS job print start function.
5. The method for implementing watermark printing according to any one of claims 1 to 4, characterized in that: Based on the custom dynamic library, a printing behavior corresponding to the printing type in the printing process is adopted to add a watermark during the printing process of the data to be printed, including: In the case where the printing type is a GDI printing type, obtaining the context of the data to be printed according to the input parameters of the GDI page end function called by the printing process; The custom dynamic library is called to draw a watermark in the context of the data to be printed according to a graphics device interface drawing command provided by the operating system.
6. The method for implementing watermark printing according to any one of claims 1 to 4, characterized in that: Based on the custom dynamic library, a printing behavior corresponding to the printing type in the printing process is adopted to add a watermark during the printing process of the data to be printed, including: In the case where the printing type is the XPS printing type, redirecting the printed output file to a preset folder, and extracting the XPS document corresponding to the to-be-printed data from the preset folder; The custom dynamic library is called to add a watermark to each page in the XPS document according to the XPS image drawing command provided by the operating system.
7. The method for implementing watermark printing according to claim 6, characterized in that: When the printing type is the XPS printing type, redirecting the printed output file to a preset folder includes: According to the input parameters of the XPS document print start function called by the print process, the output path of the output file is obtained; The output path of the output file is modified to be the preset output path of the preset folder.
8. The method for implementing watermark printing according to claim 6, characterized in that: Extracting the XPS document corresponding to the to-be-printed data from the preset folder includes: According to the input parameters of the XPS data stream writing function called by the printing process, the print data stream in the data to be printed and the length of the print data stream are obtained; According to the print data stream and the length of the print data stream, an XPS document corresponding to the to-be-printed data is determined from the preset folder.
9. A device for implementing a printing watermark, characterized in that: include: A determination module, used for determining data to be printed and a custom dynamic library injected into a printing process of the data to be printed, wherein the printing process includes a GDI printing behavior and an XPS printing behavior changed based on a hooking technology; An identification module, used for identifying the printing type of the data to be printed executed by the printing process; The printing module is used to add a watermark in the printing process of the data to be printed based on the custom dynamic library and adopt the printing behavior corresponding to the printing type in the printing process.
10. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the method according to any one of claims 1 to 8.