Foxit Quick PDF Library

Display watermark only when a PDF is printed

With the use of Optional Content Groups (OCGs), aka Layers in Acrobat lingo, it is possible to make specific content only appear when the PDF is viewed on screen or printed. The sample code demonstrates how this can be done by showing you three different examples of text drawn on a page.

// Draw text that will display when viewed on screen and printed

QP.DrawText(100, 500, "No OCG (View and print)");

// Create new content stream for text
// that will only display when printed

QP.NewContentStream();
QP.DrawText(100, 400, "Apple OCG (No view, print)");
int OC1 = QP.NewOptionalContentGroup("Apple");
QP.SetContentStreamOptional(OC1);

// Create new content stream for text
// that will only display on screen
// and won't show when printed

QP.NewContentStream();
QP.DrawText(100, 300, "Banana OCG (View, no print)");
int OC2 = QP.NewOptionalContentGroup("Banana");
QP.SetContentStreamOptional(OC2);

// Specify which optional content groups
// are displayed on screen and when printed

QP.SetOptionalContentGroupVisible(OC1, 0);
QP.SetOptionalContentGroupPrintable(OC1, 1);
QP.SetOptionalContentGroupVisible(OC2, 1);
QP.SetOptionalContentGroupPrintable(OC2, 0);

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: