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

Free Support Forum - aspose.com

Image Size Error when inserting into PDF

Hi,


We have created images with specific width, height and DPI settings. When importing the image into a Word document it works and keeps the original size. However, when we create the imagestream in Aspose PDF .net and insert the image into the PDF the image is very big and not according to the size we specified. Also, when you look at the size of the image in word it is according to our specified sizes.

I have attached the word document and the image for your perusal and would appreciate if you can provide an example of code to be able to insert the image into PDF with the specified width and length as required.

The .png file has been created with the following setting and need the width and lenght exactly the same in PDF document.

600 DPI
Height = 50.673 mm
Width = 10.00 mm

Hope you can help

Regards

Hi Eugene,


Thanks for contacting support.

In order to set the Image Height and Width inside resultant PDF document, please try using FixHeight and FixWidth properties of Aspose.Pdf.Image class. Now concerning to your requirement, I have tested the scenario using following code snippet and as per my observations, the BarCode image appears in dimensions specified in code (even though it looks weird because Image Height is larger than width for this landscape image). Also please note that the default unit in Aspose.Pdf is Point, where 1 inch = 72 points and 1 cm = 1/2.54 inch = 0.3937 inch = 28.3 points.

[C#]

Aspose.Pdf.Document
doc = new Document();<o:p></o:p>

doc.Pages.Add();

Aspose.Pdf.Image img = new Aspose.Pdf.Image();

img.File = "c:/pdftest/2015-07-06_1147.png";

// 1cm = 28.3 points

// 1 mm = 0.1 cm

// Height 50.673 mm = 5.06 cm = 5.06 X 28.3 = 143.198 points

img.FixHeight= 143.198;

// Width 10.00 mm = 1.0 cm = 1.0 X 28.3 = 28.3 points

img.FixWidth = 28.3;

// in case of Images with DPI, pixels = ( points / 72 ) * DPI

doc.Pages[1].Paragraphs.Add(img);

doc.Save(“c:/pdftest/Sequence_Closed_Image_in_PDF.pdf”);