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

Free Support Forum - aspose.com

Aspose fails to create large files

I’m using Aspose.PDF to create a PDF from a directory of JPG files. When the total size of the JPG files is up to 200 MB or so, the file is create properly. However, if I add in 250MB of JPG files, the Aspose.Pdf.Generator.Pdf.Save() routine saves a file with zero bytes.


To be clear: with the very same code, running Save() with 200 MB (or even 215 MB) of JPG files creates a good file, but running Save() with 250MB (or even just 239MB) of JPG files results in a zero-byte file.

The code that I am using follows below. As an example, you can use the set of JPG files that I’ve uploaded here: https://www.dropbox.com/sh/a8iao16hpiw6n2k/AAA-sCsDnmj430k5jj1v2tKsa
There are 560 jpg files in the directory, 437KB each, for a total of 239MB. The files are all identical in content. If you run the code on these files, a zero-byte file results. However, if you delete 100 of the files and run the code on the remaining 460 files, a proper PDF file results.

Aspose.Pdf.License lic = new License();
lic.SetLicense(“Aspose.Pdf.lic”);
string curdir = System.Environment.CurrentDirectory;

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

string[] files = Directory.GetFiles(curdir, “.”);

if (files.Length == 0) {
Console.WriteLine(“No files found!”);
return;
}

for (int ifile = 0; ifile < files.Length; ifile++) {
Console.WriteLine("Adding image " + ifile + " out of " + files.Length);

FileStream fs = new FileStream(files[ifile], FileMode.Open, FileAccess.Read);
byte[] tmpBytes = new byte[fs.Length];
fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));

MemoryStream mystream = new MemoryStream(tmpBytes);
Bitmap b = new Bitmap(mystream);
Aspose.Pdf.Generator.Section sec2 = new Aspose.Pdf.Generator.Section(pdf1);

// Set margins so image will fit
sec2.PageInfo.Margin.Top = 0;
sec2.PageInfo.Margin.Bottom = 0;
sec2.PageInfo.Margin.Left = 0;
sec2.PageInfo.Margin.Right = 0;
sec2.PageInfo.PageWidth = (b.Width / b.HorizontalResolution) * 72;
sec2.PageInfo.PageHeight = (b.Height / b.VerticalResolution) * 72;

//Add the section in the sections collection of the Pdf document
pdf1.Sections.Add(sec2);

//Create an image object
Aspose.Pdf.Generator.Image image2 = new Aspose.Pdf.Generator.Image(sec2);

//Add the image into paragraphs collection of the section
sec2.Paragraphs.Add(image2);
image2.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;

//Set the ImageStream to the MemoryStream object
image2.ImageInfo.ImageStream = mystream;

}

//Save the Pdf
pdf1.Save(curdir + “\newfile.pdf”);
Console.WriteLine(“Done!”);


Hi there,

We are sorry for the inconvenience caused. While testing the scenario with the latest version of Aspose.Pdf for .NET 9.3.0, we have managed to reproduce the reported issue and logged it in our bug tracking system as PDFNEWNET-37074 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

Hi there,


Thanks for your patience. We have investigated the issue and will recommend you to use new DOM approach and use File property of Image class instead ImageStream, it will help you to accomplish your requirement without any issue. Please check following code snippet for the purpose.

string curdir = “E:/Data/Images”;<o:p></o:p>

Document doc122 = new Document();

string[] files = Directory.GetFiles(curdir, ".");

if (files.Length == 0)

{ Console.WriteLine("No files found!");

return;

}

for (int ifile = 0; ifile < files.Length; ifile++)

{

Console.WriteLine("Adding image " + ifile + " out of " + files.Length);

Page page = doc122.Pages.Add();

// Bitmap b = new Bitmap(mystream);

// 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;

//page.PageInfo.Height = (b.Width / b.HorizontalResolution) * 72;

//page.PageInfo.Width = (b.Height / b.VerticalResolution) * 72;

//page.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;

//page.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;

//Create an image object

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

//Add the image into paragraphs collection of the section

page.Paragraphs.Add(image);

//Set the ImageStream to a MemoryStream object

image.File = files[ifile];

}

//Save the Pdf

doc122.Save(curdir + "newfileDOM.pdf");

Console.WriteLine("Done!");

Please feel free to contact us for any further assistance.


Best Regards,

The issues you have found earlier (filed as PDFNEWNET-37074) have been fixed in Aspose.Pdf for .NET 9.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.