Hi Ryan,
I'm sorry but the stamper accuracy works perfectly only over the first document's page (previously I have given my positive answer without going through the whole document, I'm sorry). When I go through the document, again the stamper is no more accurate. Well it's better now, but still I click on a point and the stamper appears far away (but still on the page). Normally upper w.r.t. the mouse click point (or touch point on the tablet as well). Please note that the x/y offset values are not responsible of this behaviour (I tried to comment those lines, of course).
Here is my final code version (leaving off try/catch and if doc != null):
PDFViewViewer view = (PDFViewViewer) sender;
const string folder = @"..\..\Images\";
string imageFile = view.StampName + ".png";
PDFViewWPF currentView = view.Current_View;
PDFDoc doc = currentView.GetDoc();
System.Windows.Point position = e.GetPosition(currentView);
double x = position.X;
double y = position.Y;
currentView.ConvScreenPtToPagePt(ref x, ref y, currentView.CurrentPageNumber);
x -= XOffset;
y -= YOffset;
currentView.DocLock(true);
using (Stamper s = new Stamper(Stamper.SizeType.e_absolute_size, 32, 32))
{
Image img = Image.Create(doc, folder + imageFile);
s.SetAsBackground(false);
s.SetTextAlignment(Stamper.TextAlignment.e_align_left);
s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_left,
Stamper.VerticalAlignment.e_vertical_bottom);
s.SetPosition(x, y);
s.SetAsAnnotation(true);
s.StampImage(doc, img, new PageSet(currentView.CurrentPageNumber));
}
Config cfg = doc.GetOCGConfig();
Context ocgCtx = new Context(cfg);
currentView.SetOCGContext(ocgCtx);
currentView.DocUnlock();
// since you are adding the stamp as an annotation, you can get the annot bounding box and just update that area (as an optimization)
pdftron.PDF.Page page = currentView.GetDoc().GetPage(currentView.CurrentPageNumber);
Annot annot = page.GetAnnot(page.GetNumAnnots() - 1); // annots are always added to the end of the list, so this will be the stamp.
currentView.Update(annot, currentView.CurrentPageNumber);
// if not adding as annotation, you need to call regular update
//currentView.Update();
Any further suggestion?
Thank you
Paolo