0

How can I add an image to given coordinates (x,y) on a PDF page, using IronPdf? Using the samples, I managed easily to add a "stamp", but that is placed in the center of the page. I would need to be able to pass (x,y) as parameters when adding the image to each page, and I find this info nowhere in the class documentation.

var stamper = new IronPdf.Editing.ImageStamper(Image);
pdf.ApplyStamp(stamper, pageNumber);

See code above that adds the image in the page center.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • I added the bitmap to another bitmap, in the top left corner (the new bmp obj is as large as the PDF page). Then used the newly generated bitmap as an argument to ImageStamper. – Alexandra Dan Oct 25 '22 at 22:01
  • @KJ, I'll give it a try with your suggestion, could be better for performance. – Alexandra Dan Oct 25 '22 at 22:02

1 Answers1

0

You can set HorizontalOffset and VerticalOffset by IronPdf.Editing.Length .

I wrote sample code as below, hope it helps:

var pdf = new PdfDocument("./test.pdf");
ImageStamper logoImageStamper = new ImageStamper("[YOUR IMAGE PATH]/cat.jpg");
logoImageStamper.HorizontalOffset = new Length(300, MeasurementUnit.Pixel);
logoImageStamper.VerticalOffset = new Length(-500, MeasurementUnit.Pixel);
pdf.ApplyStamp(logoImageStamper);
pdf.SaveAs("test_new.pdf");

Code running effect: enter image description here

cg-zhou
  • 528
  • 3
  • 6