Frequently Asked Question:
Add an image to a PDF and preserve the aspect ratio when it’s drawn
Question
I want to draw an image on top a PDF but maintain its aspect ratio. It would also be good if I could control its rotation and alignment.
Answer
It's possible to preserve the aspect ratio and control the rotation and alignment of an image when adding it to a PDF file by using the FitImage function instead of the DrawImage function.
Here is some JScript sample code that demonstrates how to do this:
// Load a sample image into memory
QP.AddImageFromFile("temp.bmp", 1);
// Set page size as A4
QP.SetPageSize("A4");
// Get the width and height of the page
lWidth = QP.PageWidth();
lHeight = QP.PageHeight();
// Draw the image onto the page using the specified width/height
QP.FitImage(0, lHeight, lWidth, lHeight, 1, 1, 0);
// Store the updated PDF where you like
QP.SaveToFile("temp.pdf");