|
Algorithm 1 Embedding algorithm |
|
Input: Original PDF file, watermark bit sequence
|
|
Output: Watermarked PDF file |
-
1:
Convert the original PDF file into a series of images
-
2:
for each image I do
-
3:
Map from the RGB color space to the YCbCr color space, decompose the component, mark it as , and convert it into a binary text image .
-
4:
Perform character segmentation and text line information extraction.
-
5:
for each text line do
-
6:
Confirm the left and right boundaries of each text line.
-
7:
Calculate the spacing between each two characters and select the maximum spacing to divide the current line into two sub-blocks.
-
8:
end for
-
9:
Obtain the set of sub-blocks , P is the number of text lines.
-
10:
for each sub-block do
-
11:
Calculate the number of black pixels in each row of and find the row with the highest number of black pixels, denoted as .
-
12:
Extract the columns with black pixels from and mark them as , .
-
13:
for each column in L do
-
14:
Extract all pixels of that column, find the white pixel closest to , and mark it as .
-
15:
if is “1” then
-
16:
When p is above , flip the pixel in with position to a white pixel; When p is located below , flip the pixel in with position to a white pixel.
-
17:
end if
-
18:
if is “0” then
-
19:
Flip the pixel at position in to black pixels.
-
20:
end if
-
21:
end for
-
22:
end for
-
23:
Get the watermarked image .
-
24:
Replace the Y channel in the YCbCr color space with , map it back to RGB space.
-
25:
Save the watermarked image .
-
26:
end for
-
27:
Combine all watermarked images in the original order and convert to a PDF file with watermarks.
|