Hi
I’d like to create a PDF Document, which must be linearized, from a bunch of PNG-Files, which can be up to 500. I am using the following code:
Document pdfDocument = new Document();
foreach (string file in Directory.GetFiles(“C:\Temp\PNG”))
{
Page page = pdfDocument.Pages.Add();
FileStream fs = new FileStream(file, FileMode.Open);
byte[] tmpBytes = new byte[fs.Length];
fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));
MemoryStream mystream = new MemoryStream(tmpBytes);
// Instantiate BitMap object with loaded image stream
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.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
page.Paragraphs.Add(image1);
// Set the image file stream
image1.ImageStream = mystream;
// Save resultant PDF file
fs.Flush();
fs.Close();
pdfDocument.Optimize();
pdfDocument.Save(“C:\Temp\Output.pdf”);
}
Troubles so far:
- Save Method must be called in foreach block, otherwise it will quit with a OutOfMemoryException when adding a large number of PNG
- After creating 5 Pages in the PDF it crashes with NullReferenceException on Page page = pdfDocument.Pages.Add();
- The size of the first page is correct, the size of the following pages are too small
- When trying to do this Document pdfDocument = new Document(“C:\Temp\Output.pdf”); I get a Aspose.Pdf.Exceptions.InvalidPdfFileFormatException "Incorect file format"
I am using Aspose.Pdf 10.7.0.0
Regards
Christian
Hi Christian,
as PDFNEWNET-39345 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.
Hi Christian,
Hi
Thank you for your reply. This problems are related to any images.
May I ask you, when you would think you can fix this problem? For us this is very urgent, because we have to deliver something in the next one or two weeks!
What I have to say also is, that I am disappointed about that behaviour. Whe had an issue in the barcode library https://forum.aspose.com/t/10389 and had to wait 1.5 years for a new version that is working. Now we spent 4.5 K in the new library and the very first thing I have tested comes to an issue!
Regards
Christian
Hi Christian,
The issues you have found earlier (filed as PDFNET-39345) have been fixed in Aspose.PDF for .NET 18.3. This message was posted using BugNotificationTool from Downloads module by asad.ali