Watermarks with PDFNet

Q: I am writing to enquire about the use of watermarks with your
library. I am evaluating the trial version and everything seems to
work fine. However, I am not able to put watermarks in a document
created from a stream. I checked the examples included in the
distribution but unfortunately there was not any describing how to
implement watermarks.

I am creating a document in this way (I use C++):

PDF::PDFDoc doc(mem, dwFileSize);

The PDF is created and visualized without problems, but as soon as I
tried to create a watermark, the application crashes. My code is:

std::auto_ptr<PDF::Annots::Watermark> wm(new
PDF::Annots::Watermark());
PDF::Rect pos;
pos.Set(0,0,200,200);
wm->SetPage(doc->GetPage(2));

I alternatively tried the following approach, but it failed as well:

std::auto_ptr<PDF::PDFDoc> doc(new PDF::PDFDoc(mem, dwFileSize));
std::auto_ptr<PDF::Annots::Watermark> wm(new
PDF::Annots::Watermark());
m_Wm = wm;
PDF::Rect pos;
pos.Set(0,0,200,200);
m_Wm->Create(*doc, pos);
UString ss (L"Test");
m_Wm->SetRect(pos);
m_Wm->SetContents(ss);
----------------------------
A: If you would like to stamp existing PDF files you should use either
‘pdftron.PDF.Stamper’ or ElementBuilder/ElementWriter.

I agree that the name of Watermark annotations is somewhat confusing
(blame the PDF spec).

'pdftron.PDF.Stamper' is a utility class that can be used to PDF pages
with text, images, or with other PDF content in only a few lines of
code (for sample code, please see PDFNet/Samples/StamperTest).
Although Stamper is very simple to use compared to ElementBuilder/
ElementWriter it is not as powerful or flexible. In case you need full
control over PDF creation use ElementBuilder/ElementWriter to add new
content to existing PDF pages as shown in the ElementBuilder sample
project (http://www.pdftron.com/pdfnet/samplecode.html#ElementBuilder)
and 'How do I add a watermark to a page?' in PDFNet FAQ (http://
www.pdftron.com/pdfnet/faq.html).

In case you are working on a document which is opened in PDFViewCtrl,
please do not forget to lock the document (doc.Lock(); action on doc;
doc.Unlock()) whenever you read/write and direct or indirect document
data. Failure to lock the document in this case could lead to
threading issues and weird errors.

In case you are working with annotations a good starting point would
be AnnotationTest sample project (http://www.pdftron.com/pdfnet/
samplecode.html#Annotation). Please note that you don’t need to
allocate PDFDoc or annotations on the heap since they are already
managed by the C++ wrapper.