Watermark

    You can watermark inFile exactly once. The watermark is centered on the page and using description you can configure various aspects like rotation, scaling and opacity. For text based watermarks you can also configure font name, font size, fill color and render mode.


    WARNINGA watermark resides in the background of a page. How much of the watermark will be rendered visible on a page depends on the layers on top and the transparency involved. This applies to PDF in general. Eg. scanned PDF files usually consist of bitmap images spanning whole pages and will hide anything in the background including any watermark. For these cases use pdfcpu stamp with an opacity < 1 instead to get a similar result.



    NOTEIn the Adobe world a watermark is text or an image that appears either in front of or behind existing document content, like a stamp comment aka stamp annotation that anybody reading the PDF can open, edit, move around and delete. The difference here is that a watermark is integrated into a PDF page as a fixed element. Within pdfcpu the meaning of these terms is slightly different:

    • stamp is any content that appears in front of the existing page content - sitting on top of everything else on a page

    • watermark is any content that appears behind the existing page content - residing in the page background

    where content may be text, an image or a PDF page.


    Arguments

    A configuration string to specify watermark parameters.

    The first entry of the description configures the type. It is one of the following:

    • text string (Use \n for a multiline watermark)
    • PDF file name followed by an optional page number

    Only one of rotation and diagonal is allowed.

    The following description parameters are for text based watermarks only:

    • font name
    • font size
    • color
    • render mode

    Default description

    1. 'f:Helvetica, p:24, s:0.5 rel, c:0.5 0.5 0.5, r:0, d:1, o:1, m:0'

    The default watermark configuration is:

    • fixed center page position (free positioning will be part of a future release)
    • scale factor 0.5 relative to page dimensions
    • positive rotation along the diagonale from the lower left to the upper right page corner (d:1).
    • fully opaque watermark by defining pacity 1In addition for text based watermarks:

    • font size 24 points
    • render mode fill (m:0)You only have to specify parameters that differ from the default.

    Examples

    Text Based Watermarks

    Create a watermark using defaults only:

    1. pdfcpu watermark 'This is a watermark' test.pdf out.pdf

    Create a watermark using scale factor 1:

    1. pdfcpu watermark 'This is a watermark, s:1' test.pdf out.pdf

    Watermark  - 图2

    Create a watermark along the second diagonale using scale factor 0.9, default render mode fill and a fill color:

    1. pdfcpu watermark 'This is a watermark, s:.9, d:2, c:.6 .2 .9' test.pdf out.pdf

    Watermark  - 图4

    Create a watermark with 0 degree rotation using scale factor 0.9 and render mode stroke:

    Create a watermark with a counterclockwise rotation of 45 degrees using scale factor 1, render mode fill & stroke and a fill color:

    Watermark  - 图6

    Create a watermark with default rotation, using scale factor 1, font size 48, default render mode fill, a fill color and set opacity to 0.6:

    1. pdfcpu watermark 'Draft, p:48, s:1, c:.8 .8 .4, o:.6' test.pdf out.pdf

    1. pdfcpu watermark -pages even 'Intentionally left blank" test.pdf out.pdf

    We also could have used pdfcpu stamp. There is really no difference since we apply only to empty pages here.

    Create a watermark using defaults only:

    1. pdfcpu watermark 'pic.jpg' test.pdf out.pdf

    Watermark  - 图8

    Create a watermark using 0 degree rotation and relative scaling of 1.0:

    Create a watermark using 0 degree rotation and absolute scaling of 1.0:

    1. pdfcpu watermark 'pic.jpg, s:1 abs, r:0' test.pdf out.pdf

    Watermark  - 图10

    Create a watermark using a clockwise rotation of 30 degrees and absolute scaling of 1.0:

    1. pdfcpu watermark 'pic.jpg, r:-30, s:1 abs' test.pdf out.pdf

    Create a watermark using a clockwise rotation of 30 degrees and absolute scaling of 0.25:

    1. pdfcpu watermark 'pic.jpg, r:-30, s:.25 abs' test.pdf out.pdf

    Watermark  - 图12

    PDF Based Watermarks

    Create a watermark using defaults only. This will apply page 1 of some.pdf:

    1. pdfcpu watermark 'some.pdf' test.pdf out.pdf

    This is how to create a watermark using defaults and page 2 of some.pdf: