Class Watermarker


  • public class Watermarker
    extends java.lang.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.
    • Constructor Summary

      Constructors 
      Constructor Description
      Watermarker​(byte[] input, java.lang.String text, int fontsize, float opacity)
      The main constructor with all mandatory arguments.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Watermarker withColor​(java.awt.Color color)
      To change the default black color by a new one.
      Watermarker withFont​(BaseFont font)  
      byte[] write()
      Write the watermark to the pdf given in entry.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • outputStream

        private final java.io.ByteArrayOutputStream outputStream
      • text

        private final java.lang.String text
      • fontsize

        private final int fontsize
      • opacity

        private final float opacity
      • color

        private java.awt.Color color
    • Constructor Detail

      • Watermarker

        public Watermarker​(byte[] input,
                           java.lang.String text,
                           int fontsize,
                           float opacity)
                    throws java.io.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:
        java.io.IOException - on error
        DocumentException - on error
    • Method Detail

      • withColor

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

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