Method, system and equipment for automatically removing watermarks from PDF (Portable Document Format) document and medium
By analyzing PDF documents and using format conversion and dewatering task pool to process non-standard watermarks, the problem that the existing technology cannot automatically remove non-standard watermarks is solved, and the smoothness of efficient dewatering and document processes are achieved.
Patent Information
- Application Number
- CN202510210107.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-25
- Publication Date
- 2025-06-13
AI Technical Summary
The existing PDF watermark removal scheme cannot automatically remove watermarks from PDF documents with non-standard watermarks, resulting in restrictions on reading, printing, sharing and other processes.
By analyzing the PDF document, it detects whether it contains watermark elements of non-standard watermark type. If it exists, the PDF page is assigned to the format conversion task pool and the dewatermark task pool, format conversion and dewatermark processing are performed, and the watermarkless PDF document is finally generated.
It realizes efficient and high-quality removal of standard watermarks and non-standard watermarks in PDF documents, improving the smoothness of the reading, printing, sharing and other processes of documents.
Smart Images

Figure CN120145344A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of PDF, and in particular, to a method, system, device and medium for automatically removing watermarks from PDF documents. Background Art
[0002] Currently, in daily writing, reading, office and other scenarios, PDF (Portable Document Format) format documents (hereinafter referred to as PDF documents) are widely used for reading and sharing. However, due to the large number of PDF document processing software on the market, the produced PDF documents will carry various watermark marks in many cases, such as Logo pictures or text watermarks, which cause a lot of trouble to the subsequent processes such as reading, printing and sharing of PDF documents. The current PDF watermark removal solutions on the market can only remove the documents with PDF standard watermarks added, and cannot automatically remove the documents with non-standard watermarks added. There is an urgent need for a new solution to solve the problems in this scenario. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide a method, system, device and medium for automatically removing watermarks from PDF documents, which can efficiently and high-quality remove standard watermarks and non-standard watermarks in PDF documents, and make the processes of reading, printing, sharing, etc. of PDF documents smoother.
[0004] In a first aspect, the present invention provides a method for automatically removing watermarks from PDF documents. The method is applied to a system, and the system is deployed with a format conversion task pool and a watermark removal task pool. The method includes:
[0005] Analyze the PDF document to be processed to detect whether the PDF pages in the analyzed PDF document to be processed contain watermark elements of non-standard watermark types;
[0006] If so, allocate the PDF page to the first task node in the format conversion task pool, and execute the format conversion task on the allocated PDF page through the first task node to obtain the picture file corresponding to the PDF page;
[0007] Allocate the picture file to the second task node in the watermark removal task pool, and execute the watermark removal task on the allocated picture file through the second task node to remove the watermark elements from the picture file to obtain a new picture file;
[0008] Generate a watermark-free PDF document based on the new picture file.
[0009] In an implementation manner, executing the format conversion task on the allocated PDF page through the first task node to obtain the picture file corresponding to the PDF page includes:
[0010] Extract the page content included in the PDF page and render the page content onto a Bitmap object;
[0011] Loop to extract the annotation content included in the PDF page and superimpose and render all the annotation content onto the same Bitmap object;
[0012] Save the Bitmap object in image format to obtain the image file corresponding to the PDF page.
[0013] In one implementation, perform a watermark removal task on the assigned image file through a second task node to remove the watermark element from the image file to obtain a new image file, including:
[0014] Call the watermark removal model to remove the watermark element from the image file through the watermark removal model to obtain a new image file; wherein, the watermark removal model is used to locate the area where the watermark element is located in the image file and perform color elimination processing on the area where the watermark element is located.
[0015] In one implementation, remove the watermark element from the image file through the watermark removal model to obtain a new image file, including:
[0016] Capture the area where the watermark element is located in the image file, establish an annular sampling band at the outer edge of the area where the watermark element is located, and perform color elimination processing on the color of the area where the watermark element is located based on the color information of the pixel points included in the annular sampling band.
[0017] In one implementation, generate a watermark-free PDF document based on the new image file, including:
[0018] Obtain a newly created PDF document;
[0019] Create a blank PDF page in the newly created PDF document, and write the new image file into the blank PDF page according to the page number of the new image file to obtain a watermark-free PDF page;
[0020] Continue to create new blank PDF pages in the newly created PDF document until the number of watermark-free PDF pages included in the newly created PDF document is the same as the number of PDF pages included in the PDF document to be processed, to obtain a watermark-free PDF document.
[0021] In one implementation, the number of first task nodes is multiple; allocating the PDF pages to the first task nodes in the format conversion task pool includes:
[0022] Pre-scan the PDF pages to obtain the metadata complexity included in the PDF pages;
[0023] Based on the metadata complexity and the volume of the PDF page, use a task time prediction model to predict the predicted duration required for the format conversion task of the PDF page;
[0024] Determine the priority corresponding to the PDF page based on the duration prediction value;
[0025] Add the PDF page to the priority queue according to the priority;
[0026] According to the priority queue, allocate the PDF page to the first task node in the format conversion task pool.
[0027] In one implementation, the number of second task nodes is multiple; allocating the picture file to the second task node in the watermark removal task pool includes:
[0028] Pre-allocate the picture file to the second task node in the watermark removal task pool and update the watermark removal task queue of the second task node;
[0029] Based on the number of picture files contained in the watermark removal task queue, perceive the stress index corresponding to the second task node;
[0030] When the stress index is higher than the stress threshold, pre-allocate the picture file to the next second task node in the watermark removal task pool until the stress index corresponding to the watermark removal queue of the second task node is lower than the stress threshold, and then allocate the picture file to the second task node.
[0031] In a second aspect, the present invention also provides a PDF document automatic watermark removal system. The system is deployed with a format conversion task pool and a watermark removal task pool. The system includes:
[0032] A PDF parsing module for parsing the PDF document to be processed to detect whether the PDF page in the parsed PDF document to be processed contains watermark elements of non-standard watermark types;
[0033] A format conversion module for, when the detection result of the PDF parsing module is yes, allocating the PDF page to the first task node in the format conversion task pool, and the first task node performs a format conversion task on the allocated PDF page to obtain a picture file corresponding to the PDF page;
[0034] A watermark removal module for allocating the picture file to the second task node in the watermark removal task pool, and the second task node performs a watermark removal task on the allocated picture file to remove the watermark elements from the picture file to obtain a new picture file;
[0035] A PDF generation module for generating a watermark-free PDF document based on the new picture file.
[0036] In a third aspect, the present invention further provides an electronic device, including a processor and a memory. 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 the first aspect.
[0037] In a fourth aspect, the present invention further provides a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to implement the method according to any one of the first aspect.
[0038] A method, system, device, and medium for automatically removing watermarks from PDF documents provided by the present invention first parses a PDF document to be processed. When it is detected that the PDF pages in the parsed PDF document to be processed contain watermark elements of a non-standard watermark type, the PDF pages are assigned to the first task node in the format conversion task pool. The first task node performs a format conversion task on the assigned PDF pages to obtain a picture file corresponding to the PDF pages. Then, the picture file is assigned to the second task node in the watermark removal task pool, and the second task node performs a watermark removal task on the assigned picture file to remove the watermark elements from the picture file to obtain a new picture file. Finally, a watermark-free PDF document is generated based on the new picture file. The above method parses the PDF document to be processed to detect watermark elements of a standard watermark type or a non-standard watermark type in the PDF pages. For PDF pages containing watermark elements of a non-standard watermark type, the PDF pages are converted into picture files through the format conversion task pool and the watermark removal task pool, and the watermark elements in the picture files are removed. Then, a watermark-free PDF document is generated based on the new picture file. The present invention can efficiently and high-quality remove standard watermarks and non-standard watermarks in PDF documents, making the processes of reading, printing, sharing, etc. of PDF documents smoother.
[0039] Other features and advantages of the present invention will be described in the following specification, and in part, will be obvious from the specification, or will be understood by implementing the present invention. The objectives and other advantages of the present invention are achieved and obtained by the structures specifically pointed out in the specification, claims, and drawings.
[0040] To make the above objectives, features, and advantages of the present invention more obvious and understandable, the following specific preferred embodiments are given, and in conjunction with the accompanying drawings, the detailed description is as follows. Description of the Drawings
[0041] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for the description of the specific embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0042] Figure 1 It is a schematic flowchart of a method for automatically removing watermarks from PDF documents provided by an embodiment of the present invention;
[0043] Figure 2 It is a technical framework diagram of a method for automatically removing watermarks from PDF documents provided by an embodiment of the present invention;
[0044] Figure 3 It is an architecture diagram of a format conversion task pool provided by an embodiment of the present invention;
[0045] Figure 4 It is an architecture diagram of a watermark removal task pool provided by an embodiment of the present invention;
[0046] Figure 5 It is a schematic structural diagram of a system for automatically removing watermarks from PDF documents provided by an embodiment of the present invention;
[0047] Figure 6 It is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. Specific Embodiments
[0048] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions of the present invention in conjunction with the embodiments. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts fall within the scope of protection of the present invention.
[0049] Currently, existing PDF watermark removal solutions can only remove watermarks from documents with PDF standard watermarks added, and cannot automatically remove watermarks from documents with non-standard watermarks added. Based on this, the embodiments of the present invention provide a method, system, device, and medium for automatically removing watermarks from PDF documents, which can efficiently and high-quality complete the removal of standard watermarks and non-standard watermarks in PDF documents, making the processes of reading, printing, sharing, etc. of PDF documents smoother.
[0050] For ease of understanding of this embodiment, first, a method for automatically removing watermarks from PDF documents disclosed in the embodiments of the present invention will be introduced in detail. This method is applied to a system that deploys a format conversion task pool and a watermark removal task pool. SeeFigure 1 A schematic flowchart of an automatic watermark removal method for PDF documents, the method mainly includes the following steps S102 to step S108:
[0051] Step S102, parse the PDF document to be processed to detect whether the PDF pages in the parsed PDF document to be processed contain watermark elements of non-standard watermark types.
[0052] In the PDF specification, Artifacts refer to those page elements that have no impact on the content and reading order. Artifacts elements may include: headers and footers, page numbers, borders, watermarks, and other decorative elements. In the general industry usage, the PDF watermark in the general sense refers to the watermark type elements in the Artifacts elements, that is, the watermark elements of the standard watermark type. Watermark elements other than this are watermark elements of non-standard watermark types.
[0053] In one example, if the watermark elements of the standard watermark type are detected on the PDF page, they can be directly removed from the PDF page; if the watermark elements of non-standard watermark types are detected in the original PDF page or the PDF page after removing the watermark elements of the standard watermark type, they can be cached in the temporary task queue for subsequent steps to allocate the tasks in the temporary task queue to the format conversion task pool.
[0054] Step S104, if so, allocate the PDF page to the first task node in the format conversion task pool, and the first task node performs a format conversion task on the allocated PDF page to obtain the picture file corresponding to the PDF page.
[0055] Among them, the format conversion task is used to convert the PDF page from the PDF format to a Bitmap (bitmap) object, and then save the Bitmap object in the picture format to obtain the picture file.
[0056] In one example, the number of the first task nodes is 1, and the first task node traverses each PDF page in a loop to convert it into a picture file.
[0057] In another example, the number of first task nodes is multiple. The priorities can be assigned to the PDF pages according to the metadata included in the PDF pages, and all the PDF pages are added to the priority queue according to the priorities. Then, the PDF pages are allocated to each first task node in batches according to the priority queue. Each first task node performs the following operations in parallel: converting the allocated PDF pages into Bitmap objects and saving the Bitmap objects in picture format to obtain picture files. Optionally, after any task node finishes the format conversion task, it can send a message notification to the watermark removal task pool, so that the watermark removal task pool assigns corresponding second task nodes to the picture files obtained by the format conversion.
[0058] Step S106: Allocate the picture files to the second task nodes in the watermark removal task pool, and perform the watermark removal task on the picture files allocated to it through the second task nodes, so as to remove the watermark elements from the picture files to obtain new picture files.
[0059] In one example, the number of second task nodes is 1. Then the first task node traverses each picture file in a loop to remove the watermark elements from the picture files to obtain new picture files.
[0060] In another example, the number of second task nodes is multiple. Each second task node in the watermark removal task pool can be traversed to determine whether the resource pressure it bears exceeds the load after the picture files are allocated to the second task node. Then, the picture files are allocated to the relatively idle second task nodes. The second task node locates the area where the watermark elements in the picture files are located, and performs color elimination processing on the area where the watermark elements are located to obtain new picture files.
[0061] Step S108: Generate a watermark-free PDF document based on the new picture files.
[0062] In one example, a blank PDF document (referred to as a new PDF document) can be created, and the new picture files are written into the new PDF document in turn to obtain a watermark-free PDF document.
[0063] The PDF document automatic watermark removal method provided by the embodiments of the present invention parses the PDF document to be processed to detect the watermark elements of the standard watermark type or non-standard watermark type included in the PDF pages. For the PDF pages containing the watermark elements of the non-standard watermark type, the PDF pages are converted into picture files through the format conversion task pool and the watermark removal task pool, and the watermark elements in the picture files are removed. Then, a watermark-free PDF document is generated based on the new picture files. The present invention can efficiently and high-quality remove the standard watermarks and non-standard watermarks in the PDF document, making the processes of reading, printing, sharing, etc. of the PDF document smoother.
[0064] For the sake of easy understanding, an embodiment of the present invention provides a specific implementation manner of a method for automatically removing watermarks from PDF documents.
[0065] For the aforementioned step S102, the process of parsing the PDF document is as follows: If, after parsing the PDF document, it is found that the document contains Artifacts elements and these elements contain watermark types, it is only necessary to traverse each page of the PDF document, find the watermark type elements in the Artifacts on that page, and delete them to complete the watermark removal; If, after parsing the PDF document, it is found that the document does not contain Artifacts elements or contains Artifacts elements but these elements do not contain watermark types, then it is necessary to jump to step S104 for processing.
[0066] For the aforementioned step S104, the content of the PDF document is divided into text and graphic elements and is distributed in each page data. When rendering the content of the PDF page, the rendering of the page content and the page annotation content will be distinguished, so as to ensure the complete display of all content on the PDF page. Based on this, the process of the format conversion task is as follows: (1) Extract the page content contained in the PDF page and render the page content onto a Bitmap object; (2) Loop to extract the annotation content contained in the PDF page and superimpose and render all the annotation content onto the same Bitmap object; (3) Save the Bitmap object in image format to obtain the image file corresponding to the PDF page. The Bitmap object after superimposed rendering contains the complete content of the PDF page, and saving this Bitmap object as an image file is sufficient.
[0067] For the aforementioned step S106, all the page content of the PDF document has been saved on different image files. Next is to perform watermark removal processing on the images. The embodiment of the present invention selects the technique of removing shading in image processing for the document watermark scenario. Specifically, the process of the watermark removal task is as follows: Call the watermark removal model, and remove the watermark elements from the image file through the watermark removal model to obtain a new image file; Among them, the watermark removal model is used to locate the area where the watermark elements are located in the image file and perform color elimination processing on the area where the watermark elements are located.
[0068] The specific process is as follows: Capture the area where the watermark elements are located in the image file, establish a circular sampling band at the outer edge of the area where the watermark elements are located, and based on the color information of the pixel points contained in the circular sampling band, perform color elimination processing on the area where the watermark elements are located.
[0069] In one embodiment, the process of capturing the area where the watermark element is located in the picture file is as follows: Multimodal feature fusion detection can be performed through algorithms such as frequency-domain analysis and positioning, morphological enhancement detection, and deep learning-assisted recognition to accurately capture the area where the watermark element is located in the picture file. Among them, the image is transformed into the frequency-domain space based on the Fourier transform, and periodic shading is identified by analyzing the distribution characteristics of high-frequency / low-frequency components. The watermark usually appears as discrete frequency spikes at a specific angle. After suppressing the corresponding frequency components using a band-stop filter, an inverse transform can be used to obtain the binary mask of the potential watermark area. The opening and closing operations of the image are combined using multi-scale structural elements, including: Gradient morphology: The difference operation between the dilation and erosion results to strengthen the edge contour of the watermark; Top-hat transform: Calculate the difference between the original image and the result of the opening operation to highlight the light shading; Directional erosion: Use a linear structural element to iteratively erode along a specific angle to extract stripe-shaped watermarks. Deploy a hybrid attention model based on the U-Net architecture. When the picture file is input, the following operations are performed simultaneously: Local texture analysis: Capture repetitive patterns through dilated convolutions; Global context awareness: The Transformer module models long-range dependencies; Multi-scale feature fusion: The pyramid pooling layer integrates features at different granularities. The hybrid attention model outputs a pixel-level watermark probability heat map, which is fused with the results output by frequency-domain analysis and positioning and morphological enhancement detection through a logical OR operation to determine the area where the watermark element is located.
[0070] In one embodiment, the process of establishing an annular sampling band at the outer edge of the area where the watermark element is located is as follows: An annular sampling band is established at the outer edge of the area where the watermark element is located, which is divided into 36 sectors in the polar coordinate system, and the median color of each sector is taken as the reference benchmark point.
[0071] In one embodiment, the process of eliminating the color of the area where the watermark element is located based on the color information of the pixel points included in the annular sampling band is as follows: The color of the area where the watermark element is located is eliminated based on the reference benchmark point using adaptive color processing to ensure that the color of the area where the watermark element is located after color elimination is the same as the color of the area without the watermark; PatchMatch algorithm is combined for context-aware restoration to protect the sharpness of the stroke edges in the picture file.
[0072] For the foregoing step S108, the image files after the PDF document conversion have all undergone watermark removal processing for the images. Next, these image files need to be rewritten into a new PDF document. The process of generating a watermark-free PDF document is as follows: (1) Obtain a new PDF document. (2) Create a blank PDF page in the new PDF document, and write the new image files into the blank PDF page according to the page numbers of the new image files to obtain a watermark-free PDF page. (3) Continue to create new blank PDF pages in the new PDF document until the number of watermark-free PDF pages contained in the new PDF document is the same as the number of PDF pages contained in the PDF document to be processed, thereby obtaining a watermark-free PDF document. In specific implementation, each PDF page in the PDF document carries a page number. Based on this page number, a unique identifier for each PDF page can be generated, which also reflects the order of each PDF page. Thus, the image files can be written into the blank PDF pages in the required order of the pages.
[0073] Through the above four steps, whether the original PDF document undergoes standard watermark removal or non-standard watermark removal, a good watermark removal effect can be obtained, and the visual effect of the generated new PDF document is basically the same as that of the original PDF document, which is more suitable for the subsequent usage requirements of the PDF document. The above method provided by the embodiments of the present invention can efficiently and high-quality restore the document content before watermarking for the watermarked PDF document through this method, making the PDF document more conducive to subsequent processing. Currently, this function has been applied to actual business scenarios and has been widely recognized by the market.
[0074] On the basis of the foregoing embodiments, the embodiments of the present invention provide a specific implementation manner of a method for automatically removing watermarks from a PDF document by taking the scenario where the number of the first task nodes and the second task nodes is both 1 as an example. Refer to Figure 2The technical framework diagram of an automatic PDF document watermark removal method is shown as follows, including: parsing the PDF document; determining whether it contains a PDF standard watermark; if so, deleting the standard watermark on each page of the PDF document; if not, looping through the steps of the following format conversion task: obtaining the PDF content of each page and rendering it as a Bitmap, obtaining all the annotations on that page and rendering them onto the Bitmap, and outputting the final Bitmap content as a file; looping through the steps of the following watermark removal task: looping through and reading the content of the generated Bitmap file, calling the image watermark removal technology for processing, and saving the processed new Bitmap file; looping through the steps of generating a watermark-free PDF document: looping through and reading the content of the generated new Bitmap file, creating a new PDF page, and writing the new Bitmap content to that page; saving the PDF document after removing the watermark. Among them, the detailed explanations of the above steps such as parsing the PDF document, format conversion task, watermark removal task, and generating a watermark-free PDF document can be found in the foregoing embodiments, and the embodiments of the present invention will not elaborate on them here.
[0075] On the basis of the foregoing embodiments, the embodiments of the present invention provide a specific implementation manner of an automatic PDF document watermark removal method by taking the scenario where the number of the first task nodes and the second task nodes are both multiple as an example, including:
[0076] (a) Parsing the PDF document to be processed to detect whether the PDF pages in the parsed PDF document to be processed contain watermark elements of non-standard watermark types.
[0077] (b) Allocating the PDF pages to the first task nodes in the format conversion task pool, and the first task nodes perform the format conversion task on the allocated PDF pages to obtain the corresponding image files of the PDF pages, such as Figure 3 The architecture diagram of a format conversion task pool as shown.
[0078] In an implementation manner, the process of allocating the PDF pages to the first task nodes in the format conversion task pool is as follows:
[0079] (b1) Pre-scanning the PDF pages to obtain the metadata complexity included in the PDF pages. Among them, the metadata complexity is related to metadata such as the text density and image ratio in the PDF pages. For example, the higher the text density and the lower the image ratio, the higher the metadata complexity.
[0080] (b2) Based on the metadata complexity and the volume of the PDF page, predict the predicted duration of the format conversion task for the PDF page through the task duration prediction model. In one example, the task duration prediction model can be a neural network model or a mathematical model. Input the metadata complexity, the volume of the PDF page, and the benchmark duration into the task duration prediction model, and the model can output the predicted duration value.
[0081] (b3) Determine the priority corresponding to the PDF page based on the predicted duration value. In one example, according to the actual requirements, the priority can be assigned to the PDF page in the order from high to low or from low to high of the predicted duration value.
[0082] (b4) Add the PDF page to the priority queue according to the priority.
[0083] (b5) According to the priority queue, allocate the PDF page to the first task node in the format conversion task pool. In one example, assuming the number of the first task nodes is N1, then the first N1 PDF pages in the priority queue are respectively allocated to each first task node; when it is monitored that the format conversion task of any first task node is completed, the (N1 + 1)-th PDF page in the priority queue can be allocated to this first task node; repeat this process until all PDF pages have been converted into picture files.
[0084] (c) Allocate the picture file to the second task node in the watermark removal task pool, and the second task node performs the watermark removal task on the allocated picture file to remove the watermark element from the picture file to obtain a new picture file, such as Figure 4 the architecture diagram of a watermark removal task pool shown.
[0085] In one implementation, when the format conversion task of any first task node is completed, the format conversion task pool will send a message notification to the watermark removal task pool to allocate the picture file to the second task node in the watermark removal task pool according to the following process:
[0086] (c1) Pre-allocate the picture file to the second task node in the watermark removal task pool, and update the watermark removal task queue of the second task node. Among them, the watermark removal task queue includes one or more picture files already allocated to this second task node and the picture file pre-allocated to this second task node.
[0087] (c2) Based on the number of picture files included in the watermark removal task queue, sense the pressure index corresponding to the second task node. In one example, the pressure index is positively correlated with the number of picture files. Optionally, the product of the number of picture files, the processing delay of the second task node, and the resource saturation of the second task node can be used as the pressure index.
[0088] (c3) When the pressure index is higher than the pressure threshold, pre-allocate the picture file to the next second task node in the watermark removal task pool until the pressure index corresponding to the watermark removal queue of the second task node is lower than the pressure threshold, and then allocate the picture file to the second task node.
[0089] (d) Generate a watermark-free PDF document based on the new picture file.
[0090] Among them, for the detailed explanations of the above steps such as parsing the PDF document, format conversion task, watermark removal task, and generating a watermark-free PDF document, reference can be made to the foregoing embodiments, and the embodiments of the present invention will not elaborate on them here.
[0091] Based on the foregoing embodiments, the embodiments of the present invention provide a PDF document automatic watermark removal system. This system is deployed with a format conversion task pool and a watermark removal task pool. Refer to Figure 5 the structural schematic diagram of a PDF document automatic watermark removal system shown, and this system mainly includes the following parts:
[0092] A PDF parsing module 502, which is used to parse the PDF document to be processed to detect whether the PDF pages in the parsed PDF document to be processed contain watermark elements of non-standard watermark types;
[0093] A format conversion module 504, which is used to, when the detection result of the PDF parsing module 502 is yes, allocate the PDF page to the first task node in the format conversion task pool, and the first task node performs a format conversion task on the allocated PDF page to obtain a picture file corresponding to the PDF page;
[0094] A watermark removal module 506, which is used to allocate the picture file to the second task node in the watermark removal task pool, and the second task node performs a watermark removal task on the allocated picture file to remove the watermark elements from the picture file to obtain a new picture file;
[0095] A PDF generation module 508, which is used to generate a watermark-free PDF document based on the new picture file.
[0096] The PDF document automatic watermark removal system provided by the embodiments of the present invention parses the PDF document to be processed to detect watermark elements of standard watermark types or non-standard watermark types included in the PDF pages. For the PDF pages containing watermark elements of non-standard watermark types, the PDF pages are converted into picture files through a format conversion task pool and a watermark removal task pool, and the watermark elements in the picture files are removed. Then, a watermark-free PDF document is generated based on the new picture files. The present invention can efficiently and high-quality remove standard watermarks and non-standard watermarks in PDF documents, making the processes of reading, printing, sharing, etc. of PDF documents smoother.
[0097] In one implementation, the format conversion module 504 is specifically configured to:
[0098] Extract the page content included in the PDF page and render the page content onto a Bitmap object;
[0099] Loop to extract the annotation content included in the PDF page and superimpose and render all the annotation content onto the same Bitmap object;
[0100] Save the Bitmap object in picture format to obtain the picture file corresponding to the PDF page.
[0101] In one implementation, the watermark removal module 506 is specifically configured to:
[0102] Call the watermark removal model to remove the watermark elements from the picture file through the watermark removal model to obtain a new picture file; wherein, the watermark removal model is used to locate the area where the watermark elements are located in the picture file and perform color elimination processing on the area where the watermark elements are located.
[0103] In one implementation, the watermark removal module 506 is specifically configured to:
[0104] Capture the area where the watermark elements are located in the picture file, establish a circular sampling band at the outer edge of the area where the watermark elements are located, and perform color elimination processing on the area where the watermark elements are located based on the color information of the pixel points included in the circular sampling band.
[0105] In one implementation, the PDF generation module 508 is specifically configured to:
[0106] Obtain a newly created PDF document;
[0107] Create a blank PDF page in the newly created PDF document, and write the new picture file into the blank PDF page according to the page number of the new picture file to obtain a watermark-free PDF page;
[0108] Continue to create new blank PDF pages in the newly created PDF document until the number of watermark-free PDF pages in the newly created PDF document is the same as the number of PDF pages in the PDF document to be processed, obtaining a watermark-free PDF document.
[0109] In one embodiment, the number of first task nodes is multiple; the format conversion module 504 is specifically configured to:
[0110] Perform a pre-scan on the PDF page to obtain the metadata complexity included in the PDF page;
[0111] Through the task time-consuming prediction model, based on the metadata complexity and the volume of the PDF page, predict the predicted value of the time consumed for the format conversion task of the PDF page;
[0112] Determine the priority corresponding to the PDF page based on the predicted time value;
[0113] Add the PDF page to the priority queue according to the priority;
[0114] According to the priority queue, allocate the PDF page to the first task node in the format conversion task pool.
[0115] In one embodiment, the number of second task nodes is multiple; the watermark removal module 506 is specifically configured to:
[0116] Pre-allocate the picture file to the second task node in the watermark removal task pool and update the watermark removal task queue of the second task node;
[0117] Based on the number of picture files included in the watermark removal task queue, perceive the pressure index corresponding to the second task node;
[0118] In the case where the pressure index is higher than the pressure threshold, pre-allocate the picture file to the next second task node in the watermark removal task pool until the pressure index corresponding to the watermark removal queue of the second task node is lower than the pressure threshold, and then allocate the picture file to the second task node. The device provided by the embodiments of the present invention has the same implementation principle and the same technical effects as the foregoing method embodiments. For the sake of brief description, for the parts not mentioned in the device embodiments, reference may be made to the corresponding contents in the foregoing method embodiments.
[0119] The embodiments of the present invention provide an electronic device. Specifically, the electronic device includes a processor and a storage device; a computer program is stored on the storage device, and when the computer program is run by the processor, it executes the method according to any one of the foregoing embodiments.
[0120] Figure 6A schematic structural diagram of an electronic device provided by an embodiment of the present invention. The electronic device 100 includes: a processor 60, a memory 61, a bus 62, and a communication interface 63. The processor 60, the communication interface 63, and the memory 61 are connected through the bus 62. The processor 60 is configured to execute an executable module stored in the memory 61, such as a computer program.
[0121] Among them, the memory 61 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 63 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. can be used.
[0122] The bus 62 can be an ISA bus, a PCI bus, an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity of representation, Figure 6 only a bidirectional arrow is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0123] Among them, the memory 61 is used to store a program. After receiving an execution instruction, the processor 60 executes the program. The method executed by the device defined by the flow process disclosed in any one of the foregoing embodiments of the present invention can be applied to the processor 60 or implemented by the processor 60.
[0124] The processor 60 may be an integrated circuit chip with the ability to process signals. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in the processor 60 or the instructions in the form of software. The above-mentioned processor 60 may be a general-purpose processor, including a central processing unit (CPU for short), a network processor (NP for short), etc.; it may also be a digital signal processor (DSP for short), an application specific integrated circuit (ASIC for short), a field-programmable gate array (FPGA for short) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present invention can be directly embodied as being executed and completed by a hardware decoding processor, or executed and completed by a combination of the hardware and software modules in the decoding processor. The software module may be located in a mature storage medium 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. This storage medium is located in the memory 61, and the processor 60 reads the information in the memory 61 and combines its hardware to complete the steps of the above method.
[0125] The computer program product of the readable storage medium provided by the embodiments of the present invention includes a computer-readable storage medium storing program codes, and the instructions included in the program codes can be used to execute the methods described in the foregoing method embodiments. For specific implementation, reference can be made to the foregoing method embodiments and will not be elaborated here.
[0126] When the above-mentioned functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.
[0127] Finally, it should be noted that the above-mentioned embodiments are only specific embodiments of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: any person skilled in the art within the technical scope disclosed by the present invention can still modify the technical solutions recorded in the foregoing embodiments, or can easily conceive of changes, or perform equivalent replacements on some of the technical features; and these modifications, changes, or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered by the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.
Claims
1. A method for automatically removing watermarks from PDF documents, characterized in that: The method is applied to a system, wherein the system is deployed with a format conversion task pool and a watermark removal task pool, and the method comprises: Parsing the PDF document to be processed to detect whether the PDF page in the parsed PDF document to be processed contains a watermark element of a non-standard watermark type; If yes, the PDF page is assigned to a first task node in the format conversion task pool, and the first task node performs a format conversion task on the PDF page assigned thereto to obtain an image file corresponding to the PDF page; Assigning the image file to a second task node in the watermark removal task pool, and having the second task node perform a watermark removal task on the image file assigned thereto, so as to remove the watermark element from the image file to obtain a new image file; Generate a watermark-free PDF document based on the new image file.
2. The method for automatically removing watermarks from a PDF document according to claim 1, characterized in that: The first task node performs a format conversion task on the PDF page assigned thereto to obtain a picture file corresponding to the PDF page, including: Extract the page content contained in the PDF page, and render the page content onto a Bitmap object; Circularly extract the annotation contents contained in the PDF page, and overlay and render all the annotation contents onto the same Bitmap object; The Bitmap object is saved in a picture format to obtain the picture file corresponding to the PDF page.
3. The method for automatically removing watermarks from a PDF document according to claim 1, characterized in that: The second task node performs a watermark removal task on the picture file assigned thereto, so as to remove the watermark element from the picture file to obtain a new picture file, including: Calling a watermark removal model, and removing the watermark element from the image file through the watermark removal model to obtain a new image file; wherein the watermark removal model is used to locate the area where the watermark element is located in the image file, and to eliminate the color of the area where the watermark element is located.
4. The method for automatically removing watermarks from a PDF document according to claim 3, characterized in that: Removing the watermark element from the image file by the watermark removal model to obtain a new image file includes: The area where the watermark element is located in the image file is captured, a circular sampling band is established at the outer edge of the area where the watermark element is located, and the color of the area where the watermark element is located is eliminated based on the color information of the pixels contained in the circular sampling band.
5. The method for automatically removing watermarks from a PDF document according to claim 1, characterized in that: Generate a watermark-free PDF document based on the new image file, including: Get the newly created PDF document; Creating a blank PDF page in the newly created PDF document, and writing the new image file into the blank PDF page according to the page sequence number of the new image file, to obtain a watermark-free PDF page; Continue to create new blank PDF pages in the newly created PDF document until the number of watermark-free PDF pages contained in the newly created PDF document is consistent with the number of PDF pages contained in the PDF document to be processed, thereby obtaining a watermark-free PDF document.
6. The method for automatically removing watermarks from a PDF document according to claim 1, characterized in that: The number of the first task nodes is multiple; allocating the PDF page to the first task node in the format conversion task pool includes: Pre-scanning the PDF page to obtain metadata complexity contained in the PDF page; The task time prediction model is used to predict the time taken to perform the format conversion task on the PDF page based on the metadata complexity and the volume of the PDF page. Determine the priority corresponding to the PDF page based on the predicted duration value; Adding the PDF page to a priority queue according to the priority; According to the priority queue, the PDF page is allocated to a first task node in the format conversion task pool.
7. The method for automatically removing watermarks from a PDF document according to claim 1, characterized in that: The number of the second task nodes is multiple; allocating the image file to the second task node in the watermark removal task pool includes: Pre-allocating the image file to the second task node in the watermark removal task pool, and updating the watermark removal task queue of the second task node; Based on the number of the image files included in the watermark removal task queue, sensing a pressure index corresponding to the second task node; When the pressure index is higher than the pressure threshold, the image file is pre-allocated to the next second task node in the de-watermarking task pool until the pressure index corresponding to the de-watermarking queue of the second task node is lower than the pressure threshold, and the image file is allocated to the second task node.
8. A PDF document automatic watermark removal system, characterized in that: The system is deployed with a format conversion task pool and a watermark removal task pool, and the system includes: A PDF parsing module, used for parsing a PDF document to be processed, so as to detect whether a PDF page in the PDF document to be processed after parsing contains a watermark element of a non-standard watermark type; a format conversion module, configured to assign the PDF page to a first task node in the format conversion task pool if the detection result of the PDF parsing module is yes, and to perform a format conversion task on the PDF page assigned thereto by the first task node to obtain an image file corresponding to the PDF page; a watermark removal module, configured to assign the image file to a second task node in the watermark removal task pool, and execute a watermark removal task on the image file assigned thereto by the second task node, so as to remove the watermark element from the image file to obtain a new image file; The PDF generation module is used to generate a watermark-free PDF document based on the new image file.
9. An electronic device, characterized in that: The method 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 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the method according to any one of claims 1 to 7.
Citation Information
Cited By
Distributed document analysis method and device, equipment and medium
CN121581033A
