PDF Watermark for printing only, programmatically

I can watermark any PDF already, and the images inside, everything ok, but now I need the watermark only showing up when the PDF is printed... Is this possible? How?

I need to do this programmatically of course.


You should probably make use of the fact that the screen uses RGB and the printer CMYK. You should be able to create two colors in CMYK that map to the same RGB value. This is of course not enough against a determined specialist.

For future readers, this is possible to do by wrapping the watermark in a PDF layer (Optional Content Group), then configuring the Usage attribute of this layer as Print-Only. See the PDF Reference Document, Chapter 4-Graphics, part 4.10-Optional Content for more details.

Specifically, using itextsharp, I was able to get it working with the following, specifically - pdf version 1.7, and SetPrint("Watermark",true)

        string oldfile = @"c:\temp\oldfile.pdf";
        string newFile = @"c:\temp\newfile.pdf";
        PdfReader pdfReaderS = new PdfReader(oldfile);
        Document document = new Document(pdfReaderS.GetPageSizeWithRotation(1));
        PdfWriter pdfWriterD = PdfWriter.GetInstance(document, new FileStream(newFile, FileMode.Create, FileAccess.Write));
        PdfContentByte pdfContentByteD = pdfWriterD.DirectContent;

        BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        int n = pdfReaderS.NumberOfPages;

        string text = "UNCONTROLLED";

        for (int i = 1; i <= n; i++)
            iTextSharp.text.Rectangle pageSizeS = pdfReaderS.GetPageSizeWithRotation(i);
            float pageWidth = pageSizeS.Width / 2;
            float pageheight = pageSizeS.Height / 2;

            PdfImportedPage pdfImportedPage = pdfWriterD.GetImportedPage(pdfReaderS, i);

            PdfLayer layer1 = new PdfLayer("Watermark", pdfWriterD);
            layer1.SetPrint("Watermark", true);
            layer1.View = false;
            layer1.On = false;
            layer1.OnPanel = false;

            pdfContentByteD.SetFontAndSize(bf, 30);

            ColumnText.ShowTextAligned(pdfContentByteD, Element.ALIGN_CENTER, new Phrase(text), 300, 700, 0);

            pdfContentByteD.AddTemplate(pdfImportedPage, 0, 0);//, 0, 1, 0, 0);


The bOnScreen parameter determines whether the watermark will be displayed when the PDF is viewed on the computer screen, and bOnPrint determines whether it will be displayed when the PDF is printed.

-- https://acrobatusers.com/tutorials/watermarking-a-pdf-with-javascript

Need Your Help

How to expose Stored Procedure in Teiid OData

stored-procedures jboss odata teiid

I have created a virtual procedure in JBoss Teiid ,i want to call it using odata protocol.

Requesting data from Freebase API

.net json google-api freebase

I need help with returning data from the Freebase API, using the Google APIs .NET library - the documentation for the library is practically non-existent, which is making life pretty difficult.