Hi,
Please, do you know why The position given to a stamp in a scanned document is not respected ?
Best regard
//load original pdf
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"Test.pdf");
//create a new pdf
PdfDocument newPdf = new PdfDocument();
//load the image to fill stamp
PdfImage image = PdfImage.FromFile(@"logo.png");
foreach (PdfPageBase page in doc.Pages)
{
PdfPageBase newPage;
//judge if the page rotated and rotate it back
if (page.Rotation == PdfPageRotateAngle.RotateAngle90)
newPage = newPdf.Pages.Add(new SizeF(page.Size.Height, page.Size.Width), new PdfMargins(0));
else if (page.Rotation == PdfPageRotateAngle.RotateAngle270)
newPage = newPdf.Pages.Add(new SizeF(page.Size.Height, page.Size.Width), new PdfMargins(0));
else
newPage = newPdf.Pages.Add(page.Size, new PdfMargins(0));
page.CreateTemplate().Draw(newPage, new PointF(0, 0));
//add an image stamp on the top left
PdfRubberStampAnnotation loStamp = new PdfRubberStampAnnotation(new RectangleF(new PointF(10, 10), new SizeF(20, 20)));
PdfAppearance loApprearance = new PdfAppearance(loStamp);
PdfTemplate template = new PdfTemplate(30, 30);
template.Graphics.DrawImage(image, 0, 0);
loApprearance.Normal = template;
loStamp.Appearance = loApprearance;
newPage.AnnotationsWidget.Add(loStamp);
}
newPdf.SaveToFile(@"result.pdf", Spire.Pdf.FileFormat.PDF);