Implemeting a custom interactive 'stamp' tool in PDFView control.

Q: I am implementing a function to interactively stamp PDF documents
with next content (some text). I am deriving my class from PDFView and
and an implementing a custom tool... similar to your PDFView markup

I write text to a PDF doc as follows, causing subsequent SAVEs to add
pages onto the end of the PDF document:

    ElementWriter writer = new ElementWriter();
    writer.Begin(p); // Begin writing to page
    ElementBuilder eb = new ElementBuilder();
    Element element = eb.CreateTextBegin(pdftron.PDF.Font.Create(doc,
pdftron.PDF.Font.StandardType1Font.e_times_roman), 12);

    string data = text.Text;
    element = eb.CreateTextRun(data);
    element.SetTextMatrix(1, 0, 0, 1, lastMouse.X, lastMouse.Y);
    GState gstate = element.GetGState();

    writer.End(); // save changes to the current page


Any ideas what might be causing subsequent SAVEs to add extra pages
onto the end of the PDF?
A: The problem is that you are adding a new copy of the page to the
existing document (using doc.PagePushBack(p)). To fix this simply
comment-out this line.