3

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Reinier
  • 33
  • 1
  • 4
  • 3
    I don't think this is possible. For one thing, how will you prevent people from printing a screenshot? – SLaks Jan 07 '10 at 19:23
  • How will you prevent them from using Photoshop? – Hamish Grubijan Jan 07 '10 at 19:26
  • Are you sure you want to do this? I always thought one of the points of PDF was to create an electronic document that is viewable on nearly any platform, and displays exactly how it would be printed. With the latter in mind, I would include a watermark on the electronic view. – Jay Jan 07 '10 at 19:29
  • If you can figure out how to do this: http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=549 programatically, then you may be on to something. – leeand00 Jan 27 '10 at 18:41

4 Answers4

8

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.

yms
  • 10,361
  • 3
  • 38
  • 68
2

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));
        pdfWriterD.SetPdfVersion(PdfWriter.PDF_VERSION_1_7);
        document.Open();
        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;

            document.SetPageSize(pageSizeS);
            document.NewPage();
            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.BeginLayer(layer1);
            pdfContentByteD.SetColorFill(BaseColor.RED);
            pdfContentByteD.SetFontAndSize(bf, 30);

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

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

        }
        document.Close();
        pdfReaderS.Close();
1

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.

Stephan Eggermont
  • 15,847
  • 1
  • 38
  • 65
  • Thank you very much for your help... I guess I won't do this anyway... looks like it's not possible after all... Now I'm spending some time studying PDF deeply :). – Reinier Jan 09 '10 at 11:40
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

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404