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
sample.
I write text to a PDF doc as follows, causing subsequent SAVEs to add
pages onto the end of the PDF document:
doc.Lock();
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);
writer.WriteElement(element);
string data = text.Text;
element = eb.CreateTextRun(data);
element.SetTextMatrix(1, 0, 0, 1, lastMouse.X, lastMouse.Y);
GState gstate = element.GetGState();
gstate.SetCharSpacing(0);
gstate.SetWordSpacing(0);
gstate.SetLineWidth(1);
gstate.SetTextRenderMode(GState.TextRenderingMode.e_fill_text);
gstate.SetStrokeColorSpace(ColorSpace.CreateDeviceRGB());
gstate.SetStrokeColor(color);
gstate.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
gstate.SetFillColor(color);
writer.WriteElement(element);
writer.WriteElement(eb.CreateTextEnd());
writer.End(); // save changes to the current page
doc.PagePushBack(p);
eb.Dispose();
writer.Dispose();
doc.Unlock();
view.Update();
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.