Class Watermarker

java.lang.Object
com.lowagie.toolbox.plugins.watermarker.Watermarker

public class Watermarker extends Object
This class is the API equivalent of the WatermarkerTool. It lets you add a text watermark to all pages of a document given in input.
  • Field Details

    • reader

      private final PdfReader reader
    • outputStream

      private final ByteArrayOutputStream outputStream
    • stamp

      private final PdfStamper stamp
    • text

      private final String text
    • fontsize

      private final int fontsize
    • opacity

      private final float opacity
    • color

      private Color color
    • font

      private BaseFont font
  • Constructor Details

    • Watermarker

      public Watermarker(byte[] input, String text, int fontsize, float opacity) throws IOException, DocumentException
      The main constructor with all mandatory arguments. By default, the color stays black.
      Parameters:
      input - the pdf content as a byte[]
      text - the text to write as watermark
      fontsize - the fontsize of the watermark
      opacity - the opacity of the watermark
      Throws:
      IOException - on error
      DocumentException - on error
  • Method Details

    • withColor

      public Watermarker withColor(Color color)
      To change the default black color by a new one.
      Parameters:
      color - the new color to use
      Returns:
      the current builder instance
    • withFont

      public Watermarker withFont(BaseFont font)
    • write

      public byte[] write() throws IOException, DocumentException
      Write the watermark to the pdf given in entry.
      Returns:
      a brand new byte[] without modifying the original one.
      Throws:
      IOException - on error
      DocumentException - on error