2

I m searching for a way with a free dll library modify a pdf. I want to insert an image to a certain position into a pdf document.

I already found iTextSharp, but this only add a page before my document.

How do I insert an image to specific position?

var reader = new PdfReader(inputPdfStream);
var stamper = new PdfStamper(reader, outputPdfStream);
var pdfContentByte = stamper.GetOverContent(1);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
iTextSharp.text.Rectangle r_01 = new iTextSharp.text.Rectangle(30,10);
PdfContentByte page1 = stamper.GetOverContent(1);
image.SetAbsolutePosition(0,0);
page1.AddImage(image);
stamper.Close();
SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
Florentin Arno
  • 33
  • 1
  • 1
  • 4
  • You *"want to insert an image to a certain position"*, in your code do `image.SetAbsolutePosition(0,0)`, and have no idea what to try next? Furthermore, you say *"this only add a page before my document"* but the code you show does not add a page at all. – mkl Oct 16 '17 at 19:42
  • Thank you for this comment , i just put a code that was good actually. I played via the SetAbsP parameter and this is working now. I just cannot resize the image i m putting – Florentin Arno Oct 17 '17 at 08:14
  • You may want to look at the `ScaleAbsolute`, `ScalePercent`, and `ScaleToFit` overloads. – mkl Oct 17 '17 at 09:54

1 Answers1

0

ITextSharp is a good one, and you can actually add images to existing pages. We use it to auto-generate our product templates and add QR codes.

See Darin Dimitrov's answer here: How can I insert an image with iTextSharp in an existing PDF?

Lucax
  • 407
  • 2
  • 10