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.
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; //page.PageInfo.Margin.Top = 0; //page.PageInfo.Margin.Left = 0; //page.PageInfo.Margin.Right = 0; //page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height); // Create an image object Aspose.Pdf.Image image1 = new Aspose.Pdf.Image(); image1.FixHeight = page.Rect.Height; image1.FixWidth = page.Rect.Width
Please feel free to contact us for any further assistance.