Skip to main content
. 2023 Aug 23;23(17):7365. doi: 10.3390/s23177365
Algorithm 1 Embedding algorithm
Input: Original PDF file, watermark bit sequence w1,w2,,wN
Output: Watermarked PDF file
  • 1:

    Convert the original PDF file into a series of images I1,,In

  • 2:

    for each image I do

  • 3:   

    Map I from the RGB color space to the YCbCr color space, decompose the Y component, mark it as IY, and convert it into a binary text image Ib.

  • 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 {Bi|i=1,2,,K,K=2P}, P is the number of text lines.

  • 10:

      for each sub-block Bi do

  • 11:     

    Calculate the number of black pixels in each row of Bi and find the row with the highest number of black pixels, denoted as rlong.

  • 12:

         Extract the columns with black pixels from rlong and mark them as L=l1,l2,,ln, n<ci.

  • 13:

         for each column in L do

  • 14:        

    Extract all pixels of that column, find the white pixel closest to rlong, and mark it as p=Ib(x,y).

  • 15:

            if wi is “1” then

  • 16:          

    When p is above rlong, flip the pixel in IY with position (x,y+1) to a white pixel; When p is located below rlong, flip the pixel in IY with position (x,y1) to a white pixel.

  • 17:

            end if

  • 18:

            if wi is “0” then

  • 19:

              Flip the pixel at position (x,y) in IY to black pixels.

  • 20:

            end if

  • 21:

         end for

  • 22:

       end for

  • 23:

       Get the watermarked image IYW.

  • 24:

       Replace the Y channel in the YCbCr color space with IYW, map it back to RGB space.

  • 25:

       Save the watermarked image IW.

  • 26:

    end for

  • 27:

    Combine all watermarked images in the original order and convert to a PDF file with watermarks.