PDF Printing with Watermarks in C#’

It’s possible to use PDF layers — or optional content groups (OCGs) — to add a watermark that’s invisible onscreen but visible when a PDF is printed (or vice versa). This guide demonstrates how to configure an existing OCG to be visible when a document is printed and invisible when the document is viewed onscreen.

To learn how to add an OCG to a PDF document, see our PDF layers guide.

if (status == GdPictureStatus.OK)
if ((pdf.SetOCGLockedState(ocgId, true) == GdPictureStatus.OK) &&
    (pdf.SetOCGPrintState(ocgId, PdfOcgState.StateOn) == GdPictureStatus.OK) &&
    (pdf.SetOCGViewState(ocgId, PdfOcgState.StateOff) == GdPictureStatus.OK))
{
    pdf.SaveToFile("orpalis-demo-watermarked.pdf");
}

The code above calls: