We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Importing Image and Keep width and Height proportional to the PDF Page

I want to import an image from a file(png or jpeg) to a pdf document and I want to keep the size of the image as is if it is less than the width and height of the document.


If it is bigger I want to import it with its width and height resized proportionally.

I have this code sof ar

Image image = new Image();
image.IsInLineParagraph = false;
image.ImageStream = new FileStream(“C:\temp\images.jpg”, FileMode.Open);
Page page = pdfDocument.Pages.Add();
page.Paragraphs.Add(image);

pdfDocument.Save(“C:\temp\MyImagePDF.pdf”);

Hi Helen,


Thanks for your inquiry. Please check following documentation link for converting Image to PDF. It sets PDF page dimensions as per image dimensions. However if you want set image as per Page dimensions then do not set page properties but image FixHeight and FixWidth as following. You can compare image and page dimensions and device your logic accordingly. Hopefully it will help you to accomplish the requirements.

// Set margins so image will fit, etc.

//page.PageInfo.Margin.Bottom = 0;<o:p></o:p>

//page.PageInfo.Margin.Top = 0;<o:p></o:p>

//page.PageInfo.Margin.Left = 0;<o:p></o:p>

//page.PageInfo.Margin.Right = 0;<o:p></o:p>

//page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);<o:p></o:p>

// Create an image object<o:p></o:p>

Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();<o:p></o:p>

image1.FixHeight = page.Rect.Height;<o:p></o:p>

image1.FixWidth = page.Rect.Width;<o:p></o:p>


Please feel free to contact us for any further assistance.


Best Regards,