Q: Hi, I was looking thru the code examples looking for the best way
to add an jpeg image to a PDF that I already have. Right now I have
how to create a new PDF with the image, but don't know how to add it
to a specific spot on another PDF.
Can you provide me with guidelines in how to do this please?
Thanks in advance.
A: The process of adding an image to a blank new page (or a new
document) is exactly the same as adding the image to an existing PDF
To place the image on the page you need to set the transformation
matrix (similar to text). For example (assuming C#),
// Embed System.Drawing.Bitmap in PDF.
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap("pdfnet.gif");
Image img = Image.Create(doc, bmp);
// Create a graphical Element on the page from the Image.
Element element = f.CreateImage(img, new Matrix2D(bmp.Width, 0, 0,
bmp.Height, 50, 350)); writer.WritePlacedElement(element);
The lower-left coordinate of the image rectangle is specified in the
last two parameters of Matrix2D class. The first parameter 'bmp.Width'
represents the horizontal scaling and the fourth parameter
'bmp.Height' represents the vertical scaling (i.e. the image height as
it appears on the page).
For more samples, please take a look at AddImage sample project: