How do I stamp PDF but hide content from printing?

Q: How do I stamp PDF but hide content from printing?

I am testing a demo version of the PDFNET SDK. I am trying to do a
solution whereby I can stamp a URL linked (image/text) to the lower
right hand corner of every page in a pdf document. I also want to be
able to see this text/image on the page(s) but when I print to my
printer, I don’t want this bmp_image/text to show up on the prints.


A: If you are creating a custom annotation you can set its flags so
that is visible on screen but not visible when printed
(annot.SetFlag(Annot.Flag.e_print, false) etc.

If case you are adding content as part of the page you could add
content as an OCG layer which could be conditionally turned off when
printed (among many other possibilities). As a starting point please
refer to PDFLayers sample (http://www.pdftron.com/pdfnet/
samplecode.html#PDFLayers). To skip printing a layer you can add the
following code at the end of any CreateGroup helper function:

// As an example of further configuration, set the image layer to
// be visible on screen, but not visible when printed…

// The AS entry is an auto state array consisting of one or more usage
application
// dictionaries that specify how conforming readers shall
automatically set the
// state of optional content groups based on external factors.
Obj cfg = doc.GetOCGConfig().GetSDFObj();
Obj auto_state = cfg.FindObj(“AS”);
if (auto_state == null) auto_state = cfg.PutArray(“AS”);
Obj print_state = auto_state.PushBackDict();
print_state.PutArray(“Category”).PushBackName(“Print”);
print_state.PutName(“Event”, “Print”);
print_state.PutArray(“OCGs”).PushBack(layer);

Obj layer_usage = layer.PutDict(“Usage”);

Obj view_setting = layer_usage.PutDict(“View”);
view_setting.PutName(“ViewState”, “ON”);

Obj print_setting = layer_usage.PutDict(“Print”);
print_setting.PutName(“PrintState”, “OFF”);

//-------------------------------------------------------------------------------------
Download a full sample from Files section of this group:
http://groups.google.com/group/pdfnet-sdk/web/PDFLayerNoPrint.zip
//-------------------------------------------------------------------------------------

A VB version would look very similar…

Dim cfg As Obj = doc.GetOCGConfig().GetSDFObj()
Dim auto_state As Obj = cfg.FindObj(“AS”)
If auto_state is Nothing Then
auto_state = cfg.PutArray(“AS”)
EndIf
Dim print_state As Obj = auto_state.PushBackDict()
print_state.PutArray(“Category”).PushBackName(“Print”)
print_state.PutName(“Event”, “Print”)
print_state.PutArray(“OCGs”).PushBack(layer)

Dim layer_usage As Obj = layer.PutDict(“Usage”)

Dim view_setting As Obj = layer_usage.PutDict(“View”)
view_setting.PutName(“ViewState”, “ON”)

Dim print_setting As Obj = layer_usage.PutDict(“Print”)
print_setting.PutName(“PrintState”, “OFF”)