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

Free Support Forum - aspose.com

Set DPI for Images inside the PDF using C#

Hi we are using Aspose.Pdf for creating a pdf. The input image resolution is 300 DPI. But after creating the PDF, the DPI becomes 96. Is there any way to set the DPI as 300.
We did not find any property for setting resolution in Aspose.Pdf.Generator.Pdf , Aspose.Pdf.Generator.Section , Aspose.Pdf.Generator.Image
Below is the code snippet we are using:

        string tempLocalPDFPath = System.IO.Path.GetTempFileName();
        tempLocalPDFPath = tempLocalPDFPath.Replace(".tmp", ".pdf");
        MemoryStream mystream = null;
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();               
            foreach (byte[] image in ImageArray)
                    Aspose.Pdf.Generator.Section sect1 = new 
                    mystream = new MemoryStream(image);
                    Bitmap bitmap = new Bitmap(mystream); 
                    sect1.PageInfo.Margin.Top = 5;
                    sect1.PageInfo.Margin.Bottom = 5;
                    sect1.PageInfo.Margin.Left = 5;
                    sect1.PageInfo.Margin.Right = 5;
                  sect1.PageInfo.PageWidth = (bitmap.Width / bitmap.HorizontalResolution) * 72;
                    sect1.PageInfo.PageHeight = (bitmap.Height / bitmap.VerticalResolution) * 72;                      
                    Aspose.Pdf.Generator.Image image2 = new 
                    image2.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;
                    image2.ImageInfo.ImageStream = mystream;
                    image2.ImageScale = 0.95F;                                                
                catch (Exception e) {
                    throw e;


The old legacy Aspose.Pdf.Generator approach has been obsoleted in latest release of Aspose.Pdf for .NET. In latest release you can work with DOM (Document Object Model) approach and create DOM based XML templates to generate PDF documents. For more information please visit following helpful links of API documentation.

Basics of Aspose.PDF DOM API
Add Image to PDF
Set Image Size

Could you please specify the version of the latest Aspose dll. We are using
Also is there any property to set resolution of the image using DOM approach, like this (setting width of the image) - img.FixWidth = 100


Please use the latest version of Aspose.PDF for .NET 21.11.

Unfortunately, Aspose.PDF does not provide APIs to set the resolution of image in PDF. However, we have logged a feature request as PDFNET-50952 in our issue tracking system. We will check the possibility of implementation of this feature and inform you via this forum thread once there is an update available on it.