Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Aspose fails to create large files

$
0
0
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!");



Viewing all articles
Browse latest Browse all 3131