Watermark processing method, electronic device, and computer-readable storage medium
By adjusting the width of English characters and embedding watermark information, the problem of file readability and format compatibility caused by the failure to distinguish character characteristics in existing technologies is solved, achieving efficient and covert copyright protection.
Patent Information
- Application Number
- CN202511680715.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-17
- Publication Date
- 2026-07-10
Smart Images

Figure CN122367703A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of digital watermarking technology, and more specifically, to a watermarking processing method, electronic device, and computer-readable storage medium. Background Technology
[0002] Digital watermarking, as a technology that embeds hidden identifiers without significantly affecting the original content, is widely used in multimedia carriers such as images, audio, video, and documents. Existing watermarking methods for document content mainly fall into two categories: one is to overlay a visible watermark on the document page, and the other is to embed the watermark information into the document metadata or achieve invisible markings by modifying the document structure.
[0003] However, in practical applications, the aforementioned watermarking methods do not consider or differentiate the impact of different character characteristics on watermarks. For example, Chinese characters have fixed-width or complex glyph structures, making them less sensitive to width changes and prone to causing layout errors. In contrast, English characters have significant differences in proportional width and a rich variety of font variations. Therefore, there is an urgent need for a watermarking method specifically designed for documents containing English characters, in order to achieve an efficient and covert copyright protection mechanism while ensuring document readability and format compatibility. Summary of the Invention
[0004] The purpose of this application is to address the shortcomings of the prior art by providing a watermarking method, electronic device, and computer-readable storage medium to solve the problem that the prior art does not consider and distinguish the impact of different types of character characteristics on watermarks, and to provide a watermarking method specifically for files containing English characters, so as to achieve an efficient and covert copyright protection mechanism while ensuring file readability and format compatibility.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows: In a first aspect, embodiments of this application provide a watermark processing method, the method comprising: Obtain the file to be processed and the first watermark key; The file to be processed is parsed to extract the target text lines containing English characters; Based on the first watermark key, the text layout parameters of the target text line are adjusted to obtain the adjusted layout parameters of the target text line, wherein the adjusted layout parameters include the target width of each English character in the target text line. Based on the adjusted layout parameters of the target text line, a target file with watermark information is generated, wherein the watermark information is represented by the target width of each English character in the target text line.
[0006] As one possible implementation, parsing the file to be processed and extracting target text lines containing English characters includes: Extract text lines containing English characters from the file to be processed; The English characters in the text line are offset to obtain the target text line.
[0007] As one possible implementation, the step of offsetting the English characters in the text line to obtain the target text line includes: Extract the smallest bounding rectangle corresponding to each English character in the text line; Offset the smallest bounding rectangle corresponding to each English character to obtain the offset bounding rectangle corresponding to each English character; If the outer bounding boxes corresponding to two adjacent English characters overlap, then the two adjacent English characters are merged to obtain the target text line.
[0008] As one possible implementation, adjusting the text layout parameters of the target text line based on the first watermark key includes: Determine the minimum bounding region of the target text line, and extract the region image of the minimum bounding region; The region image is input into a pre-trained font classification model, which determines the font type of each English character in the target text line. Determine the standard width of each English character in the target text line based on the font type of each English character in the target text line; The text layout parameters of the target text line are adjusted based on the font type of each English character in the target text line, the standard width of each English character in the target text line, and the first watermark key.
[0009] As one possible implementation, determining the standard width of each English character in the target text line based on the font type of each English character in the target text line includes: Based on the font type of each English character in the target text line, determine the font ratio corresponding to the font type; Based on the font ratio, determine the average font size of the target text line; The standard width of each English character in the target text line is determined based on the font type of each English character in the target text line and the average font size of the target text line.
[0010] As one possible implementation, adjusting the text layout parameters of the target text line based on the font type of each English character in the target text line, the standard width of each English character in the target text line, and the first watermark key includes: Convert the first watermark key into a first binary sequence; Traverse each English character in the target text line. For the current English character, if the current binary bit corresponding to the first binary sequence is a first value, then subtract the preset offset from the standard width of the current English character to obtain the target width of the current English character. If the current binary bit corresponding to the first binary sequence is a second value, then add the preset offset to the standard width of the current English character to obtain the target width of the current English character.
[0011] As one possible implementation, generating a target file with watermark information based on the adjusted layout parameters of the target text line includes: The text content of the file to be processed is rendered to generate a vector graphic, where one element in the vector graphic corresponds to one English character in the file to be processed. Based on the target width of each English character in the target text line, determine the horizontal scaling ratio of each English character in the target text line; The vector graphic is adjusted based on the horizontal scaling ratio of each English character in the target text line to obtain the adjusted vector graphic. The adjusted vector graphic is then converted to a different format to obtain the target file.
[0012] As one possible implementation, after generating the target file with watermark information based on the adjusted layout parameters of the target text line, the method further includes: The target file is identified, and text lines containing English characters are extracted; The binary value corresponding to each English character is determined based on the difference between the actual width and the standard width of each English character in the text line. A second binary sequence is generated based on the binary value corresponding to each English character, and the second binary sequence is converted into a second watermark key; The second watermark key is compared with the first watermark key to obtain the watermark verification result.
[0013] Secondly, embodiments of this application provide a watermark processing apparatus, the apparatus comprising: The acquisition module is used to acquire the file to be processed and the first watermark key; The parsing module is used to parse the file to be processed and extract the target text lines containing English characters; The adjustment module is used to adjust the text layout parameters of the target text line according to the first watermark key to obtain the adjusted layout parameters of the target text line, wherein the adjusted layout parameters include the target width of each English character in the target text line. The generation module is used to generate a target file with watermark information based on the adjusted layout parameters of the target text line. The watermark information is represented by the target width of each English character in the target text line.
[0014] As one possible implementation, the parsing module is specifically used for: Extract text lines containing English characters from the file to be processed; The English characters in the text line are offset to obtain the target text line.
[0015] As one possible implementation, the parsing module is specifically used for: Extract the smallest bounding rectangle corresponding to each English character in the text line; Offset the smallest bounding rectangle corresponding to each English character to obtain the offset bounding rectangle corresponding to each English character; If the outer bounding boxes corresponding to two adjacent English characters overlap, then the two adjacent English characters are merged to obtain the target text line.
[0016] As one possible implementation, the adjustment module is specifically used for: Determine the minimum bounding region of the target text line, and extract the region image of the minimum bounding region; The region image is input into a pre-trained font classification model, which determines the font type of each English character in the target text line. Determine the standard width of each English character in the target text line based on the font type of each English character in the target text line; The text layout parameters of the target text line are adjusted based on the font type of each English character in the target text line, the standard width of each English character in the target text line, and the first watermark key.
[0017] As one possible implementation, the adjustment module is specifically used for: Based on the font type of each English character in the target text line, determine the font ratio corresponding to the font type; Based on the font ratio, determine the average font size of the target text line; The standard width of each English character in the target text line is determined based on the font type of each English character in the target text line and the average font size of the target text line.
[0018] As one possible implementation, the adjustment module is specifically used for: Convert the first watermark key into a first binary sequence; Traverse each English character in the target text line. For the current English character, if the current binary bit corresponding to the first binary sequence is a first value, then subtract the preset offset from the standard width of the current English character to obtain the target width of the current English character. If the current binary bit corresponding to the first binary sequence is a second value, then add the preset offset to the standard width of the current English character to obtain the target width of the current English character.
[0019] As one possible implementation, the generation module is specifically used for: The text content of the file to be processed is rendered to generate a vector graphic, where one element in the vector graphic corresponds to one English character in the file to be processed. Based on the target width of each English character in the target text line, determine the horizontal scaling ratio of each English character in the target text line; The vector graphic is adjusted based on the horizontal scaling ratio of each English character in the target text line to obtain the adjusted vector graphic. The adjusted vector graphic is then converted to a different format to obtain the target file.
[0020] As one possible implementation, the generation module is further configured to: The target file is identified, and text lines containing English characters are extracted; The binary value corresponding to each English character is determined based on the difference between the actual width and the standard width of each English character in the text line. A second binary sequence is generated based on the binary value corresponding to each English character, and the second binary sequence is converted into a second watermark key; The second watermark key is compared with the first watermark key to obtain the watermark verification result.
[0021] Thirdly, embodiments of this application provide an electronic device, including: a processor, a storage medium, and a bus. The storage medium stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the watermarking processing method as described in any of the first aspects above.
[0022] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the watermarking method as described in any of the first aspects above.
[0023] According to the watermarking processing method, electronic device, and computer-readable storage medium of this application, a file to be processed and a first watermark key are obtained; the file to be processed is parsed to extract target text lines containing English characters; the text layout parameters of the target text lines are adjusted according to the first watermark key to obtain adjusted layout parameters of the target text lines, the adjusted layout parameters including the target width of each English character in the target text lines; based on the adjusted layout parameters of the target text lines, a target file with watermark information is generated, the watermark information being represented by the target width of each English character in the target text lines. According to the embodiments of this application, by parsing the file to be processed and extracting target text lines containing English characters, and adjusting the text layout parameters of the target text lines based on the first watermark key, the watermark information is subtly encoded into the character width. This watermarking method, based on character width adjustment, does not affect the readability and format compatibility of the file, and achieves an efficient and covert copyright protection mechanism. Furthermore, by specifically targeting the characteristics of English characters for watermarking processing, it effectively solves the problem that the prior art does not consider and distinguish the impact of different types of character characteristics on watermarks. Attached Figure Description
[0024] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 A schematic flowchart of a watermarking method provided in an embodiment of this application is shown; Figure 2 A flowchart illustrating a method for determining target text lines provided in an embodiment of this application is shown. Figure 3 This illustration shows a schematic diagram of an outer frame merging process provided in an embodiment of this application; Figure 4 A flowchart illustrating a parameter adjustment method provided in an embodiment of this application is shown; Figure 5 A flowchart illustrating a method for determining the standard width of a character according to an embodiment of this application is shown; Figure 6A flowchart illustrating a target file generation method provided in an embodiment of this application is shown; Figure 7 A flowchart illustrating a watermarking method provided in an embodiment of this application is shown; Figure 8 A flowchart illustrating a watermark verification method provided in an embodiment of this application is shown. Figure 9 A flowchart illustrating a watermark verification method provided in an embodiment of this application is shown. Figure 10 This paper shows a schematic diagram of the structure of a watermark processing device provided in an embodiment of this application; Figure 11 A schematic diagram of the structure of an electronic device provided in an embodiment of this application is shown. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the accompanying drawings in this application are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this application. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate operations implemented according to some embodiments of this application. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical contextual relationships may be reversed or implemented simultaneously. In addition, those skilled in the art, guided by the content of this application, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts.
[0027] Furthermore, the described embodiments are merely some, not all, of the embodiments of this application. The components of the embodiments of this application described and illustrated herein can typically be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0028] It should be noted that the term "comprising" will be used in the embodiments of this application to indicate the presence of the features declared thereafter, but does not exclude the addition of other features.
[0029] Digital watermarks are typically embedded in the original media in an imperceptible manner, generally undetectable to users. They may contain additional information such as copyright details, author names, license information, or tracking purposes, but this information does not significantly impact the content of the original media. Furthermore, although hidden, digital watermarks can be extracted when needed to prove the source of content or ensure data integrity.
[0030] Digital watermarking technologies come in various types, commonly including spatial domain watermarking, frequency domain watermarking, watermarking based on improved digital signal processing, visible watermarking, and invisible watermarking. Spatial domain watermarking embeds watermark information directly into pixels or sampling points of media data such as images or audio. This method is simple and fast, but may affect image or audio quality, especially when embedding strong watermarks. Frequency domain watermarking embeds the watermark into the frequency domain of media such as images or audio, such as the Fourier transform domain. Frequency domain watermarking is generally more robust and secure than spatial domain watermarking, but it can also be more complex. Watermarking based on improved digital signal processing refers to using digital signal processing techniques to achieve more stable and secure watermark embedding and extraction. Visible watermarks are directly visible and are typically used to identify ownership or as anti-counterfeiting marks. The purpose of visible watermarks is to remind users of copyright protection and is unlikely to affect the original content. Invisible watermarks are embedded without affecting the observable quality of the original content, aiming to be concealed and difficult to detect.
[0031] This application provides a watermarking method for documents containing English characters, including embedding and extracting an invisible watermark from the document. The method aims to achieve invisible watermark embedding by modifying the width of the English characters in the document. The following will provide a detailed description of the watermarking method provided by this application.
[0032] Figure 1 A schematic flowchart of a watermarking method provided in an embodiment of this application is shown. (Refer to...) Figure 1 As shown, the method specifically includes the following steps: S101. Obtain the file to be processed and the first watermark key.
[0033] Optionally, the file to be processed must contain English characters, be in PDF format and not be a scanned copy. If the file is in Word format, it must be converted to PDF format for subsequent processing.
[0034] Optionally, the first watermark key can be an integer or a string. The specific format of the first watermark key depends on the application scenario and is not limited here.
[0035] S102. Parse the file to be processed and extract the target text lines containing English characters.
[0036] Optionally, a PDF parsing tool supporting character-level positioning is used to extract the Unicode encoding and corresponding bounding box coordinates of each character page by page. English characters whose Unicode code points fall within the range of English letters are selected, and their minimum bounding box is retained as their precise position information, thus achieving initial extraction of each English character in the text line. Then, preliminary line clustering is performed based on the position coordinates and height of the English characters, ensuring that text lines containing at least one English character are retained as candidate lines. Further, by applying a preset horizontal offset to the minimum bounding box of each English character, the character width is adjusted, and horizontal overlap between adjacent characters is identified, merging visually continuous characters into logically coherent text fragments. This ultimately forms a structurally complete and semantically coherent target text line, facilitating subsequent watermark embedding or analysis operations.
[0037] It is worth noting that this approach not only solves the problem of inaccurate line breaks that may exist in the original PDF format of the file to be processed, but also ensures the consistency of character grouping during watermarking and watermark verification through standardized processing, thereby enhancing the robustness and accuracy of the watermarking technology. Furthermore, by precisely controlling the geometric property of character width, this application enables the effective identification and merging of characters belonging to the same logical line even with minor adjustments, thus improving the quality and efficiency of text processing.
[0038] S103. Based on the first watermark key, adjust the text layout parameters of the target text line to obtain the adjusted layout parameters of the target text line.
[0039] Optionally, the adjusted layout parameters include the target width of each English character in the target text line. In this embodiment, a fine-tuning mechanism driven by font recognition, font size estimation, and watermark key is used to achieve precise adjustment of the target text line layout parameters.
[0040] Optionally, the text line region is determined based on the minimum bounding box of the English characters, and the image is cropped. A pre-trained font classification model is used to identify the font type. The font ratio is constructed by combining the rendering width of this font type at a fixed font size. The actual font size of each English character is then calculated, and the average font size of the target text line is calculated. Finally, each English character in the target text line is re-rendered using this average font size to obtain a standard width that conforms to the original typesetting style. Based on this, the first watermark key is converted into a binary sequence. Each bit in the binary sequence is read sequentially according to the character order. If the bit is 0, the standard width of the corresponding English character is subtracted by a preset offset; if the bit is 1, the standard width of the corresponding English character is added to the preset offset, thereby generating the target width of each English character.
[0041] S104. Based on the adjusted layout parameters of the target text lines, generate a target file with watermark information.
[0042] Optionally, the watermark information is represented by the target width of each English character in the target text line. In this embodiment, based on the adjusted layout parameters of the target text line, the original document text content is rendered as a vector graphic, so that each English character corresponds to an independent vector element. Then, according to the target width of each English character determined by the watermark embedding, the horizontal scaling ratio of each English character relative to the original width is calculated, and the transformation matrix of the vector element corresponding to each English character is modified according to the horizontal scaling ratio, achieving pixel-level precise horizontal stretching or compression to obtain the adjusted vector graphic. Further, the adjusted vector graphic is converted back to PDF format using a document generation library. While fully preserving the original document structure, interactive features, and visual appearance, the watermark information is embedded in the character layout in an invisible manner, thereby generating a target file that contains a hidden watermark and is highly consistent with the original document.
[0043] Based on this, the watermarking method according to the embodiments of this application parses the file to be processed and extracts the target text line containing English characters, and adjusts the text layout parameters of the target text line based on the first watermark key, so as to subtly encode the watermark information into the character width. This watermarking method, based on adjusting the character width, does not affect the readability and format compatibility of the file, and achieves an efficient and covert copyright protection mechanism. Furthermore, by specifically targeting the characteristics of English characters for watermarking, it effectively solves the problem that the prior art does not consider and distinguish the influence of different types of character characteristics on watermarks.
[0044] As one possible implementation, step S102 above parses the file to be processed and extracts the target text line containing English characters, including: extracting the text line containing English characters from the file to be processed, offsetting the English characters in the text line, and obtaining the target text line.
[0045] Optionally, the file to be processed is parsed to extract text lines containing English characters. Since the original PDF file to be processed may not be accurately broken into lines, this application performs standardization processing on the extracted text lines containing English characters, specifically offsetting the English characters in the text lines to obtain the target text lines.
[0046] Optionally, the PDF file to be processed can be parsed page by page to obtain all the character content on each page, and then each character can be traversed to filter out English characters. The minimum bounding rectangle of each English character can be extracted, and preliminary line clustering can be performed based on the position coordinates and height of each English character. Based on this, text lines containing at least one English character are retained as candidate lines, thereby realizing the extraction of text lines containing English characters from the file to be processed.
[0047] Figure 2 A flowchart illustrating a method for determining target text lines according to an embodiment of this application is shown. (Refer to...) Figure 2 As shown, the above steps offset the English characters in the text line to obtain the target text line, specifically including the following steps: S201. Extract the smallest bounding rectangle corresponding to each English character in the text line.
[0048] Optionally, when parsing the file to be processed, a PDF parsing tool that supports character-level positioning can be used to extract the Unicode encoding of each character and its corresponding bounding box coordinates page by page. Then, all characters are traversed, and English characters are filtered out by determining whether the Unicode code point of the character falls within the range of English letters. The bounding box corresponding to the English character is determined based on the bounding box coordinates of the English character, and the bounding box corresponding to the English character is used as the minimum bounding rectangle of the English character, thereby realizing the extraction of each English character and its precise position information in the text line.
[0049] S202. Offset the smallest bounding rectangle corresponding to each English character to obtain the offset bounding box corresponding to each English character.
[0050] Optionally, when offsetting the minimum bounding rectangle corresponding to each English character, the left and right boundaries of the minimum bounding rectangle corresponding to the English character can be expanded synchronously while keeping the vertical position of the rectangle unchanged, based on a preset horizontal offset amount, such as μ pixels. Specifically, for the original minimum bounding rectangle (x0, y0, x1, y1), its left boundary is moved to the left by μ pixels, i.e., x0-μ, and its right boundary is moved to the right by μ pixels, i.e., x1+μ, thus obtaining the offset bounding box (x0-μ, y0, x1+μ, y1). In this way, the visual width change of the character caused by the watermark embedding is taken into account, while ensuring that the offset only acts in the horizontal direction and does not affect the line height and vertical alignment, providing an accurate spatial basis for subsequent character merging based on overlap judgment.
[0051] S203. If the outer boxes corresponding to two adjacent English characters overlap, then the two adjacent English characters are merged to obtain the target text line.
[0052] Optionally, after obtaining the bounding box after the offset of each English character, the adjacent character pairs are traversed sequentially according to the original order of the English characters in the text line. It is determined whether the right boundary after the offset of the previous English character is greater than or equal to the left boundary after the offset of the next English character. If so, they are considered to be visually horizontally overlapping and belong to the same continuous text unit. At this time, the two English characters are merged into a logical text segment, and the overlap judgment with subsequent English characters is continued until the entire line is processed. Finally, all the merged continuous English character sequences are spliced into a target text line with complete structure and semantic coherence for subsequent watermark embedding or analysis.
[0053] For example, refer to Figure 3 As shown, each English character in the upper line, such as W, H, and E, is surrounded by a red rectangle, representing its smallest bounding rectangle within the corresponding text line—the precise position and size of the original English character. The lower line displays the bounding rectangles of the processed text line. This is achieved by uniformly expanding the smallest bounding rectangles of all English characters to a fixed width horizontally. If adjacent character boxes overlap horizontally, they are merged into a single continuous text block, ultimately forming a unified rectangle covering the entire line. This method logically groups and standardizes line divisions for fragmented characters in the original text line that might be caused by inconsistent formatting or line breaks. This ensures consistent character grouping during watermarking and verification, thereby guaranteeing the accuracy and robustness of watermark embedding and extraction.
[0054] Based on this, by extracting the smallest bounding rectangle of English characters, performing horizontal offset expansion, and dynamically merging characters based on overlapping relationships, the logical and standardized grouping of text lines is achieved. This not only accurately identifies valid text lines containing English characters, but also ensures that the character grouping strategy is completely consistent during watermark embedding and extraction. It can effectively solve problems such as inaccurate line breaks and character fragmentation caused by complex layout or parsing errors in the original PDF format of the file to be processed.
[0055] Figure 4 A flowchart illustrating a parameter adjustment method provided in an embodiment of this application is shown. (Refer to...) Figure 4 As shown, step S103 above adjusts the text layout parameters of the target text line according to the first watermark key, specifically including the following steps: S401. Determine the minimum bounding region of the target text line and extract the region image of the minimum bounding region.
[0056] Optionally, based on the minimum bounding rectangle of all English characters in the target text line, calculate its overall top, bottom, left, and right boundaries. For example, extract the minimum value of x0, the maximum value of x1, the minimum value of y0, and the maximum value of y1 from the minimum bounding rectangle of all English characters to determine the minimum bounding region of the text line. Then, use an image processing library such as OpenCV to crop the region image corresponding to the minimum bounding region from the corresponding page image, and use this region image as input for subsequent font recognition.
[0057] S402. Input the region image into the pre-trained font classification model, and the font classification model determines the font type of each English character in the target text line.
[0058] Optionally, the font type includes, but is not limited to, any of the following: Times New Roman, Arial, Helvetica, Calibri, Consolas, etc. In this embodiment, the font classification model supports accurate identification of multiple font types. Based on this, the captured region image is input into a pre-trained deep learning-based font classification model, which can identify and output the font type of each English character in the corresponding target text line.
[0059] S403. Determine the standard width of each English character in the target text line based on the font type of each English character in the target text line.
[0060] Optionally, based on the font type identified by the font classification model, all English characters are rendered at a fixed font size. The ratio of the rendered width of each English character to the font size is calculated. Then, combined with the actual physical width of each extracted English character, the font size corresponding to each English character is deduced using this font ratio. The font sizes of all English characters in the target text line are averaged to obtain the average font size of the target text line. Then, each English character is rendered again using this average font size and font type. The pixel width of the rendered English character is used as the standard width of the English character in the current context, thereby providing a precise benchmark for subsequent fine-tuning based on the watermark key.
[0061] Figure 5 A flowchart illustrating a method for determining the standard width of a character according to an embodiment of this application is shown. (Refer to...) Figure 5 As shown, step S403 above determines the standard width of each English character in the target text line based on the font type of each English character in the target text line, specifically including the following steps: S501. Determine the font ratio corresponding to each font type based on the font type of each English character in the target text line.
[0062] For example, the font ratio is the ratio of the actual width to the font size. In this embodiment, based on the font type, a fixed font size is selected to render each English character in the target text line, obtaining the character rendering width at that fixed font size. Dividing the rendering width by the fixed font size yields the font ratio corresponding to that font type. Specifically, each English character in the target text line is rendered at a fixed font size, such as 12pt, and the rendering width of each English character is calculated. The font ratio corresponding to that font type is then obtained by dividing the rendering width of each English character by the fixed font size of 12pt.
[0063] S502. Determine the average font size of the target text line based on the font ratio.
[0064] For example, for each English character in the target text line, the font size of the English character can be obtained by dividing the actual character width of the extracted English character by the font ratio determined above. By calculating the font sizes of all English characters in the target text line in this way, and averaging the font sizes of all English characters in the target text line, the average font size of the target text line can be obtained.
[0065] S503. Determine the standard width of each English character in the target text line based on the font type of each English character in the target text line and the average font size of the target text line.
[0066] For example, each English character in the target text line is re-rendered using the font type of the English characters and the average font size of the target text line. The pixel width of the rendered result is the standard width of the English character in the current context.
[0067] It is worth noting that using the above method to determine the standard width effectively overcomes the problem of inaccurate character widths caused by missing font embeddings, scaling distortions, or differences in rendering engines during PDF parsing, achieving a high-fidelity restoration of the original typesetting intent. Furthermore, by combining the actual observed width with prior font knowledge, not only is the robustness of font size estimation improved, but the standard width also ensures that it accurately reflects the original typesetting style of the document. This provides a reliable reference for minor offsets in character width during watermark embedding, significantly enhancing the watermark's concealment, recoverability, and cross-document consistency.
[0068] S404. Adjust the text layout parameters of the target text line according to the font type of each English character in the target text line, the standard width of each English character in the target text line, and the first watermark key.
[0069] Optionally, the first watermark key is converted into a first binary sequence, and each English character in the target text line is traversed. For the current English character that is traversed, if the current binary bit corresponding to the first binary sequence is a first value, the target width of the current English character is obtained by subtracting a preset offset from the standard width of the current English character. If the current binary bit corresponding to the first binary sequence is a second value, the target width of the current English character is obtained by adding a preset offset to the standard width of the current English character.
[0070] For example, the first value is 0 and the second value is 1. Based on this, the first watermark key is converted into a corresponding binary sequence. Then, each English character is traversed sequentially according to the order of the English characters in the target text line, and the layout width of the English character is fine-tuned according to the bit value of each binary bit in the binary sequence. Specifically, if the current binary bit is 0, the standard width of the English character is reduced by a preset offset; if the current binary bit is 1, the standard width of the English character is increased by a preset offset.
[0071] Based on this, not only was the width of each English character within a line of target text steganographically adjusted, but the overall visual consistency of the document was also maintained. Furthermore, this facilitates the clever embedding of watermark information, enhancing the security and concealment of the watermark while ensuring a precise correspondence between the original text layout parameters and the embedded watermark information.
[0072] Figure 6 A flowchart illustrating a target file generation method provided in an embodiment of this application is shown. (Refer to...) Figure 6 As shown, step S104 above generates a target file with watermark information based on the adjusted layout parameters of the target text lines, specifically including the following steps: S601. Render the text content of the file to be processed to generate a vector graphic.
[0073] Optionally, an element in the vector graphic corresponds to an English character in the file to be processed. In this embodiment, the text content in the file to be processed is converted into a vector graphic representation, ensuring that each English character corresponds to an independent element in a Scalable Vector Graphic (SVG). Specifically, this process can use a PDF rendering engine or specific library functions, such as a PDF to SVG tool, to accurately depict each character in the original file to be processed as a vector graphic. This not only preserves the clarity and scalability of the text to be processed but also lays the foundation for subsequent fine-tuning at the character level.
[0074] S602. Determine the horizontal scaling ratio of each English character in the target text line based on the target width of each English character in the target text line.
[0075] Optionally, for each English character, the horizontal scaling ratio is the ratio of the target width to the original width of the English character. After determining the target width of each English character, the original width of each English character in the original file to be processed is obtained, and the horizontal scaling ratio of the English character can be calculated by dividing the determined target width of the English character by the obtained original width of the English character.
[0076] S603. Adjust the vector graphic based on the horizontal scaling ratio of each English character in the target text line to obtain the adjusted vector graphic.
[0077] Optionally, after determining the horizontal scaling ratio of each English character in the target text line, the English characters can be horizontally stretched or compressed according to that horizontal scaling ratio. Specifically, for each vector graphic element corresponding to an English character, precise horizontal adjustment is achieved by modifying the scaling factor in its transformation matrix, so that the adjusted vector graphic can accurately reflect the subtle layout changes caused by the watermark embedding.
[0078] S604. Convert the format of the adjusted vector graphic to obtain the target file.
[0079] Optionally, the adjusted vector graphics need to be converted to PDF format to generate the final target file with watermark information. Specifically, a specialized document generation library can be used to encode the adjusted vector graphics into a PDF target file, ensuring that all adjusted vector graphic elements are correctly assembled back into the document structure and that the original hierarchy, links, and other interactive features remain unchanged. The final result is a PDF target file containing hidden watermark information but with an appearance almost identical to the original document.
[0080] Based on this, the embodiments of this application employ the aforementioned method to achieve fine-grained adjustment and conversion of text content in PDF format documents, ensuring that each English character is precisely scaled horizontally according to its target width while maintaining the consistency of the original document's layout style and overall design. Specifically, this application renders the text content into a high-quality vector graphic format, guaranteeing that the text maintains clarity and readability at any resolution. It also embeds watermark information without affecting the document's visual effect, ultimately generating a target file with a hidden watermark, thereby enhancing document security and traceability without impacting user experience.
[0081] Figure 7 A schematic flowchart of a watermarking method provided in an embodiment of this application is shown. (Refer to...) Figure 7As shown, this application provides a PDF digital watermark embedding method based on text character width fine-tuning. The specific watermarking process includes: obtaining the file to be processed and the first watermark key, parsing the document content of the file to be processed, extracting the Unicode encoding of each English character and its minimum bounding rectangle, determining the bounding rectangle area of each line of text based on the character position information, then cropping the image of the area and sending it into a pre-trained font classification model, identifying the font type used in the text line through the font classification model, and calculating the average font size of the text line by combining the actual character width and font ratio, and then calculating the standard width of each English character in the text line in the current context.
[0082] Furthermore, the first watermark key is converted into a binary sequence, and each bit is read sequentially character by character. If the read binary bit is 0, the standard width of the corresponding character is subtracted from the offset; if the read binary bit is 1, the standard width of the corresponding character is added to the offset, thus obtaining the target width of the character. Based on this, the horizontal scaling ratio of each character is obtained by calculating the ratio of the old and new widths, and this ratio is applied to the SVG vector graphic generated from the original PDF rendering. This allows for precise horizontal scaling adjustments to each character element, and the modified vector graphic is then converted back to PDF format, outputting a target file with hidden watermark information. This achieves highly concealed and robust text-level watermark embedding.
[0083] Figure 8 A flowchart illustrating a watermark verification method provided in an embodiment of this application is shown. (Refer to...) Figure 8 As shown, after generating the target file with watermark information based on the adjusted layout parameters of the target text lines, the method further includes: S801. Recognize the target file and extract the text lines containing English characters.
[0084] Optionally, after obtaining the target file, a corresponding document image can be generated by printing, scanning, or photographing the target file. Image recognition can then be performed on this document image to extract text lines containing English characters. Specifically, firstly, Optical Character Recognition (OCR) technology is used to process the document image, extracting all text content and the bounding box information of each character. Then, referring to the standardized line clustering logic used in the watermarking stage, the bounding rectangle of each English character is expanded to a fixed width on both sides, and horizontally overlapping characters are merged into the same logical line. The text lines are then re-aggregated to ensure that the character grouping method during watermark verification is completely consistent with that during embedding, thereby accurately reconstructing the text lines containing English characters.
[0085] S802. Determine the binary value corresponding to each English character based on the difference between the actual width and the standard width of each English character in the text line.
[0086] Optionally, for each English character in a text line, the image of its corresponding region is first fed into the same font classification model as in the watermarking stage to identify the font type of the English character. Then, the average font size of the entire text line is calculated by combining the font type and the actual character width of the English character. Based on the average font size of the text line, the standard width of each English character in the current context is calculated. Further, the actual character width obtained by OCR recognition is compared with this standard width. If the actual width is less than the standard width, the corresponding embedded binary bit is determined to be 0; if the actual width is greater than or equal to the standard width, the corresponding embedded binary bit is determined to be 1, thereby assigning a corresponding binary value to each English character.
[0087] S803. Generate a second binary sequence based on the binary value corresponding to each English character, and convert the second binary sequence into a second watermark key.
[0088] Optionally, the binary values corresponding to each English character are collected sequentially according to the order of the English characters in the text line, and concatenated to form a complete second binary sequence. Then, following the same encoding rules as the first watermark key, the second binary sequence is converted into a readable second watermark key.
[0089] S804. Compare the second watermark key with the first watermark key to obtain the watermark verification result.
[0090] Optionally, the converted second watermark key is compared with the original embedded first watermark key. If the first and second watermark keys match, or if the difference between the first and second watermark keys is within the tolerance range, the watermark verification is considered successful, confirming that the document source is trustworthy or has not been tampered with. Otherwise, the verification is considered to have failed, possibly indicating that the document is forged, lacks an embedded watermark, or has undergone severe image distortion. This effectively supports business scenarios such as anti-counterfeiting verification, copyright ownership confirmation, and leakage tracing.
[0091] Based on this, the embodiments of this application ensure the alignment and robustness of watermark extraction by using text line clustering logic, font recognition mechanism, and standard width calculation model that are completely consistent with the watermarking stage. Simultaneously, by judging binary bits based on the slight difference between the actual character width and the standard width, it effectively resists interference from image noise, scaling, and tilt, ultimately achieving high-precision watermark key restoration and verification. This provides reliable, covert, and practical technical support for applications such as document anti-counterfeiting, copyright protection, and source tracking. Therefore, the watermark verification method provided by the embodiments of this application can accurately extract the hidden watermark information embedded in the character width even after the document undergoes physical transformations simulating real-world usage scenarios such as printing, scanning, or photographing.
[0092] Figure 9 A schematic flowchart of a watermark verification method provided in an embodiment of this application is shown. (Refer to...) Figure 9 As shown in the embodiments of this application, a PDF watermark verification method based on character width differences is provided. Specifically, a target file in PDF format with watermark information is acquired, and the target file is scanned to generate a document image. OCR technology is used to recognize the document image, extracting the text line content, character bounding rectangles, and the original text line bounding area. Following the same logic as the watermarking stage, such as character box expansion and overlapping merging, the text lines are reassembled into standard text lines. The text line image is then fed into a pre-trained font classification model to identify the font type. The average font size of the text line is calculated based on the actual character width and font ratio. The standard width of each English character in the text line is then calculated based on this average font size. Finally, by comparing the difference between the actual width and the standard width of each English character, the corresponding binary bits of each English character are determined. All the binary bits corresponding to the English characters are concatenated into a binary sequence and restored to a second watermark key. By comparing the consistency between the generated second watermark key and the first watermark key used in the watermarking stage, effective verification of the document's authenticity and source is achieved, ensuring the extractability and robustness of the watermark information during physical transmission.
[0093] In summary, the watermarking and watermark verification technical solutions provided in this application cleverly utilize subtle differences in character width to embed and extract watermark information, achieving covert and secure marking of important data without affecting document content and style. Based on the characteristic of minimal modification to document content, this application ensures that the addition of the watermark does not cause any visual impact on the original document, guaranteeing the document's professionalism and neatness. Even after physical processing such as printing, scanning, or photographing, the watermark information embedded in the target file can still be accurately read, greatly improving the durability and reliability of the watermark. Furthermore, this application achieves a relatively large data storage capacity; the amount of data that can be embedded per page is approximately half the number of characters on that page, enabling the transmission of rich information even within limited text space, providing strong support for application scenarios that require encrypted storage of additional information in documents.
[0094] Based on the same inventive concept, this application also provides a watermarking device corresponding to the watermarking method. Since the principle of the watermarking device in this application is similar to the watermarking method described above, the implementation of the watermarking device can refer to the implementation of the watermarking method, and the repeated parts will not be described again.
[0095] Reference Figure 10 The diagram shown is a structural schematic of a watermark processing device provided in an embodiment of this application. The watermark processing device 1000 includes: an acquisition module 1001, a parsing module 1002, an adjustment module 1003, and a generation module 1004, wherein: Module 1001 is used to acquire the file to be processed and the first watermark key; Parsing module 1002 is used to parse the file to be processed and extract the target text lines containing English characters; The adjustment module 1003 is used to adjust the text layout parameters of the target text line according to the first watermark key to obtain the adjusted layout parameters of the target text line, which include the target width of each English character in the target text line. The generation module 1004 is used to generate a target file with watermark information based on the adjusted layout parameters of the target text line. The watermark information is represented by the target width of each English character in the target text line.
[0096] Based on this, the watermark processing apparatus according to the embodiments of this application parses the file to be processed and extracts the target text line containing English characters, and adjusts the text layout parameters of the target text line based on the first watermark key, thereby subtly encoding the watermark information into the character width. This watermark addition method, based on adjusting the character width, does not affect the readability and format compatibility of the file, and achieves an efficient and covert copyright protection mechanism. Furthermore, by specifically targeting the characteristics of English characters for watermark processing, it effectively solves the problem that the prior art does not consider and distinguish the influence of different types of character characteristics on the watermark.
[0097] In one possible implementation, the parsing module 1002 is specifically used for: Extract text lines containing English characters from the file to be processed; Offset the English characters in the text line to obtain the target text line.
[0098] In one possible implementation, the parsing module 1002 is specifically used for: Extract the smallest bounding rectangle corresponding to each English character in a text line; Offset the smallest bounding rectangle corresponding to each English character to obtain the offset bounding rectangle corresponding to each English character; If the outer boxes corresponding to two adjacent English characters overlap, then the two adjacent English characters are merged to obtain the target text line.
[0099] In one possible implementation, the adjustment module 1003 is specifically used for: Determine the minimum bounding region of the target text line and extract the region image of the minimum bounding region; The region image is input into a pre-trained font classification model, which determines the font type of each English character in the target text line. Determine the standard width of each English character in the target text line based on the font type of each English character in the target text line; The text layout parameters of the target text line are adjusted based on the font type of each English character in the target text line, the standard width of each English character in the target text line, and the first watermark key.
[0100] In one possible implementation, the adjustment module 1003 is specifically used for: Determine the font proportion corresponding to each font type based on the font type of each English character in the target text line; Determine the average font size of the target text line based on the font proportions; Determine the standard width of each English character in the target text line based on the font type of each English character and the average font size of the target text line.
[0101] In one possible implementation, the adjustment module 1003 is specifically used for: Convert the first watermark key into the first binary sequence; Traverse each English character in the target text line. For the current English character, if the current binary bit corresponding to the first binary sequence is the first value, then subtract the preset offset from the standard width of the current English character to obtain the target width of the current English character. If the current binary bit corresponding to the first binary sequence is the second value, then add the preset offset to the standard width of the current English character to obtain the target width of the current English character.
[0102] In one possible implementation, the above-mentioned generation module 1004 is specifically used for: The text content of the file to be processed is rendered to generate a vector graphic, where one element in the vector graphic corresponds to one English character in the file to be processed. Determine the horizontal scaling ratio of each English character in the target text line based on the target width of each English character in the target text line; The vector graphic is adjusted based on the horizontal scaling ratio of each English character in the target text line to obtain the adjusted vector graphic. The adjusted vector graphic is then converted to its original format to obtain the target file.
[0103] In one possible implementation, the generation module 1004 is further configured to: The target file is identified, and lines of text containing English characters are extracted. The binary value corresponding to each English character is determined based on the difference between the actual width and the standard width of each English character in the text line. A second binary sequence is generated based on the binary value corresponding to each English character, and the second binary sequence is converted into a second watermark key; The second watermark key is compared with the first watermark key to obtain the watermark verification result.
[0104] The processing flow of each module in the device and the interaction flow between each module can be referred to the relevant descriptions in the above method embodiments, and will not be detailed here.
[0105] This application also provides an electronic device 1100, such as... Figure 11The diagram shown is a structural schematic of an electronic device 1100 provided in an embodiment of this application, including: a processor 1101 and a memory 1102, and optionally, a bus 1103. The memory 1102 stores machine-readable instructions executable by the processor 1101. When the electronic device 1100 is running, the processor 1101 and the memory 1102 communicate via the bus 1103. When the machine-readable instructions are executed by the processor 1101, the steps of the watermarking method described in any of the preceding claims are performed.
[0106] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the watermarking method described in any of the preceding claims.
[0107] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the method embodiments, and will not be repeated here. In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection can be through some communication interfaces; the indirect coupling or communication connection of devices or modules can be electrical, mechanical, or other forms.
[0108] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, 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. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.
[0109] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A watermark processing method, characterized in that, include: Obtain the file to be processed and the first watermark key; The file to be processed is parsed to extract the target text lines containing English characters; Based on the first watermark key, the text layout parameters of the target text line are adjusted to obtain the adjusted layout parameters of the target text line, wherein the adjusted layout parameters include the target width of each English character in the target text line. Based on the adjusted layout parameters of the target text line, a target file with watermark information is generated, wherein the watermark information is represented by the target width of each English character in the target text line.
2. The method according to claim 1, characterized in that, The step of parsing the file to be processed and extracting target text lines containing English characters includes: Extract text lines containing English characters from the file to be processed; The English characters in the text line are offset to obtain the target text line.
3. The method according to claim 2, characterized in that, The step of offsetting the English characters in the text line to obtain the target text line includes: Extract the smallest bounding rectangle corresponding to each English character in the text line; Offset the smallest bounding rectangle corresponding to each English character to obtain the offset bounding rectangle corresponding to each English character; If the outer bounding boxes corresponding to two adjacent English characters overlap, then the two adjacent English characters are merged to obtain the target text line.
4. The method according to claim 1, characterized in that, The step of adjusting the text layout parameters of the target text line according to the first watermark key includes: Determine the minimum bounding region of the target text line, and extract the region image of the minimum bounding region; The region image is input into a pre-trained font classification model, which determines the font type of each English character in the target text line. Determine the standard width of each English character in the target text line based on the font type of each English character in the target text line; The text layout parameters of the target text line are adjusted based on the font type of each English character in the target text line, the standard width of each English character in the target text line, and the first watermark key.
5. The method according to claim 4, characterized in that, Determining the standard width of each English character in the target text line based on the font type of each English character in the target text line includes: Based on the font type of each English character in the target text line, determine the font ratio corresponding to the font type; Based on the font ratio, determine the average font size of the target text line; The standard width of each English character in the target text line is determined based on the font type of each English character in the target text line and the average font size of the target text line.
6. The method according to claim 4, characterized in that, The step of adjusting the text layout parameters of the target text line based on the font type of each English character in the target text line, the standard width of each English character in the target text line, and the first watermark key includes: Convert the first watermark key into a first binary sequence; Traverse each English character in the target text line. For the current English character, if the current binary bit corresponding to the first binary sequence is a first value, then subtract the preset offset from the standard width of the current English character to obtain the target width of the current English character. If the current binary bit corresponding to the first binary sequence is a second value, then add the preset offset to the standard width of the current English character to obtain the target width of the current English character.
7. The method according to claim 1, characterized in that, The step of generating a target file with watermark information based on the adjusted layout parameters of the target text line includes: The text content of the file to be processed is rendered to generate a vector graphic, where one element in the vector graphic corresponds to one English character in the file to be processed. Based on the target width of each English character in the target text line, determine the horizontal scaling ratio of each English character in the target text line; The vector graphic is adjusted based on the horizontal scaling ratio of each English character in the target text line to obtain the adjusted vector graphic. The adjusted vector graphic is then converted to a different format to obtain the target file.
8. The method according to claim 1, characterized in that, After generating the target file with watermark information based on the adjusted layout parameters of the target text line, the process further includes: The target file is identified, and text lines containing English characters are extracted; The binary value corresponding to each English character is determined based on the difference between the actual width and the standard width of each English character in the text line. A second binary sequence is generated based on the binary value corresponding to each English character, and the second binary sequence is converted into a second watermark key; The second watermark key is compared with the first watermark key to obtain the watermark verification result.
9. An electronic device, characterized in that, include: A processor and a memory, the memory storing machine-readable instructions executable by the processor, wherein when the electronic device is running, the processor executes the machine-readable instructions to perform the steps of the watermarking method as described in any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the watermarking method as described in any one of claims 1 to 8.
