1. Home
  2. Foxit Quick PDF Library
  3. Display watermark only when a PDF is printed

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);
Updated on April 9, 2017

Was this article helpful?

Related Articles

Ready to try Foxit PDF SDK?
Click the link below to download your trial
Free Trial