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

Free Support Forum - aspose.com

Aspose.Pdf generates larger files than Aspose.Pdf.Generator

We are using Aspose.Pdf 17.4.0 for .NET to take a series of JPEG images and place them one per page into a new PDF file. Strangely, using the Aspose.Pdf namespace creates a PDF approximately two or three times size as the obsolete Aspose.Pdf.Generator namespace (depending upon the number of images).

For one sample run, we had 5 JPEG files of sizes 68 KB, 68 KB, 73 KB, 73 KB, 74 KB for a total of 352 KB. The PDF created using Aspose.Pdf.Generator was 358 KB (for about 6 KB of overhead for the PDF which seems reasonable). The PDF created using Aspose.Pdf was 713 KB, nearly double the size!

We have tried things like calling Aspose.Pdf.Document.OptimizeResources using CompressImages = true and changing the ImageQuality parameter, but it does not seem to have any effect.

Below is a minimal sample for reproducing the problem:

using Aspose.Pdf;
using Aspose.Pdf.Generator;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;

public string CreatePdf(IEnumerable files /* paths to .jpg files */)
var directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Guid.NewGuid().ToString());

// Old way
var pdf = new Pdf();

// New way
using (var document = new Document())
foreach (var file in files)
File.Copy(file, Path.Combine(directory, Path.GetFileName(file)));

// Old way
var section = pdf.Sections.Add();
section.PageInfo.Margin.Bottom = 0;
section.PageInfo.Margin.Left = 0;
section.PageInfo.Margin.Right = 0;
section.PageInfo.Margin.Top = 0;

var image = new Aspose.Pdf.Generator.Image(section);
image.ImageInfo.File = file;
image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;

// New way
var page = document.Pages.Add();
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;
page.PageInfo.Margin.Top = 0;
using (var bitmap = new Bitmap(file))
page.CropBox = new Aspose.Pdf.Rectangle(0, 0, bitmap.Width, bitmap.Height);

page.Paragraphs.Add(new Aspose.Pdf.Image()
File = file

pdf.Save(Path.Combine(directory, "Aspose.Generator.pdf"));
document.Save(Path.Combine(directory, "Aspose.pdf"));
// Directory on the desktop will now contain all the JPEG files and both PDFs for comparison.

Hi Antonio,

Thanks for contacting support.

I have tested the scenario in our environment and observed that the size of generated document was larger than expected. Hence, I have logged an issue as PDFNET-42918 in our issue tracking system. We will further investigate the issue and keep you updated with the status of its rectification. Please be patient and spare us little time.

However, we will really appreciate if you can please share some sample images along with generated document at your end. This would help us in investigating the scenario accordingly.

We are sorry for the inconvenience.

Best Regards,


Thanks for your patience.

We are pleased to share that the issue reported earlier as PDFNET-42918, is resolved in latest release of Aspose.Pdf for .NET 17.8. Please try using the latest release version and in case you experience any issue or you have any further query, please feel free to contact.