Create pdf from image setting dpi

Hi,

I try to generate a pdf from a jpg-file that is scanned with 200dpi.
The jpg-file has a resolution of 1653 * 2338 Pixel. That is 210 * 297mm in pagesize.
My resulting pdf-file has 583 * 824mm in pagesize. What am I doing wrong?
This is the code I use: (the value for dpi and imagesize is hardcoded for my tests, I want to use them dynamically later on)

string strFile = @“C:\Temp\image2Pdf_1.JPG”;

Aspose.Pdf.Generator.Pdf objPdf = new Aspose.Pdf.Generator.Pdf();

Aspose.Pdf.Generator.Section sec2 = objPdf.Sections.Add();

sec2.PageInfo.Margin.Left = 0;

sec2.PageInfo.Margin.Right = 0;

sec2.PageInfo.Margin.Top = 0;

sec2.PageInfo.Margin.Bottom = 0;

FileStream fs = File.OpenRead(strFile);

float fWidth;

float fHeight;

byte[] data = new byte[fs.Length];

fs.Read(data, 0, data.Length);

MemoryStream ms = new MemoryStream(data);

fs.Close();

Aspose.Pdf.Generator.Image img2 = new Aspose.Pdf.Generator.Image(sec2);

fWidth = 1653.0f;

fHeight = 2338.0f;

sec2.PageInfo.PageWidth = fWidth;

sec2.PageInfo.PageHeight = fHeight;

img2.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;

img2.ImageInfo.FixWidth = sec2.PageInfo.PageWidth;

img2.ImageInfo.FixHeight = sec2.PageInfo.PageHeight;

img2.VectorGraphicsRenderingDPI = 200;

img2.ImageInfo.ImageStream = ms;

sec2.Paragraphs.Add(img2);

objPdf.Save(strFile + ".pdf");

Kind regards,
Oliver

Hi Oliver,

Thanks for your inquiry. Please note that Point is the measuring unit of Aspose.Pdf, so you need to change the size to points as suggested below. Hopefully, it will help you to accomplish your requirements.

// Aspose.Pdf measuring unit is point and 1 inch = 72 points
// convert mm to points
float fWidth = (float)(0.0393701*210*72);
float fHeight = (float)(0.0393701*297*72)

Please feel free to contact us for any further assistance.
Best Regards,

Hi Tilal,

thank you for your help, Yes with this calculation it works fine.

Kind regards,
Oliver

Hi Oliver,


Thanks for your feedback. It is good to know that you have managed to resolve your issue.

Please feel free to contact us for any further assistance, we will be more than happy to extend our support.

Best Regards,.