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

Free Support Forum - aspose.com

The size of file Aspose.Pdf generates when converting from image

Hello team,

The file that Aspose.Pdf generates is more than twice as big as the file that Aspose.Pdf.Generator generates.

This is my code.

  private MemoryStream ConvertSingleImageToPdf()
        var pdfStream = new MemoryStream();

        // Instantiate the License class
        var license = new Aspose.Pdf.License();
        var pdf = new Aspose.Pdf.Document();

        using (var image = Image.FromStream(this._stream))
            // PDFファイルにページを追加
            var pdfPage = pdf.Pages.Add();
            // ページの余白を0に、ページサイズを画像の大きさに設定
            pdfPage.PageInfo.Margin.Top = 0;
            pdfPage.PageInfo.Margin.Bottom = 0;
            pdfPage.PageInfo.Margin.Left = 0;
            pdfPage.PageInfo.Margin.Right = 0;
            pdfPage.PageInfo.Width = image.Width;
            pdfPage.PageInfo.Height = image.Height;

            // PDFイメージオブジェクトを作成
            var pdfImage = new Aspose.Pdf.Image()
                FixWidth = image.Width,
                FixHeight = image.Height,
                ImageStream = this._stream,

            // PDF保存

        return pdfStream;

Thank you,

Kindly send us your source image file and let us know the difference between the output PDF file sizes. We will investigate your scenario in our environment and share our findings with you. Your response is awaited.

Best Regards,
Imran Rafique

Hello team,
I have attached the image files and the pdf files.
Aspose.pdf.zip (1.1 MB)

I think this incident is similar.
Aspose.Pdf generates larger files than Aspose.Pdf.Generator

Thank you,

We have generated a new PDF and inserted all your input images with the latest version 17.8 of Aspose.Pdf for .NET API. The output PDF file has the least file size than your output PDF documents. This is the output PDF: Aspose.pdf.17.8.pdf (307.4 KB)

Source code C#

 // Instantiate Document Object
Document doc = new Document();
for (int i = 1; i <= 5; i++)
    // Add a page to pages collection of document
    Aspose.Pdf.Page page = doc.Pages.Add();
    // 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;

    // Load the source image file to Stream object
    FileStream fs = new FileStream(@"C:\Pdf\test198\page_" + i + ".jpg", FileMode.Open, FileAccess.Read);
    byte[] tmpBytes = new byte[fs.Length];
    fs.Read(tmpBytes, 0, int.Parse(fs.Length.ToString()));

    MemoryStream mystream = new MemoryStream(tmpBytes);
    // Instantiate BitMap object with loaded image stream
    Bitmap b = new Bitmap(mystream);

    page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);
    // Create an image object
    Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
    // Add the image into paragraphs collection of the section
    // Set the image file stream
    image1.ImageStream = mystream;
// Save resultant PDF file

Hello team,

I have checked in Aspose 17.8 and it seems OK.

Thank you,

Thank you for the confirmation. It is nice to hear from you that the problem has been resolved. Please feel free to let us know in case of any further assistance or questions.

Best Regards,
Imran Rafique