I'm using the following code to do a direct-to-file create of a PDF from a collection of image streams. The p.Close() statement fails with a NullReferenceException. What am I doing wrong?
string tmpFile = Utilities.UtilityTools.getTempFilenameWithExtension(".pdf");
System.IO.FileStream fs = new System.IO.FileStream(tmpFile, System.IO.FileMode.Create);
Aspose.Pdf.Pdf p = new Aspose.Pdf.Pdf(fs);
Aspose.Pdf.Section section = p.Sections.Add();
section.PageInfo.Margin.Bottom = 0;
section.PageInfo.Margin.Left = 0;
section.PageInfo.Margin.Right = 0;
section.PageInfo.Margin.Top = 0;
// figure out size of image and set the pagesize of the pdf.
using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(webViewerController.SavedState.ImageStreams[0]))
{
section.PageInfo.PageHeight = (bmp.PhysicalDimension.Height / bmp.VerticalResolution) * 72;
section.PageInfo.PageWidth = (bmp.PhysicalDimension.Width / bmp.HorizontalResolution) * 72;
}
// add images to pdf
for (int i = 0; i < webViewerController.SavedState.ImageStreams.Length; i++)
{
Aspose.Pdf.Image img = new Aspose.Pdf.Image(section);
if (webViewerController.SavedState.MimeType.Equals("image/jpeg"))
img.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Jpeg;
else
img.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Tiff;
img.ImageInfo.ImageStream = webViewerController.SavedState.ImageStreams[i];
section.Paragraphs.Add(img);
}
p.Close();
Thanks,
MAC