Direct-to-file PDF from images fails

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

Hi,

Please use the section.AddParagraph() to write the paragraph and here is a example list as below.

Thanks.

[C#]

string tmpFile = "d://PDF.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;
for (int i = 0; i < 100; i++)
{
System.IO.FileStream fs1 = new System.IO.FileStream("c:/scanned.jpg", System.IO.FileMode.Open);
Aspose.Pdf.Image img = new Aspose.Pdf.Image(section);

img.ImageScale = 0.2F;
img.ImageInfo.ImageFileType = ImageFileType.Jpeg;
img.ImageInfo.ImageStream = fs1;

//when you want to use stream mode, you need to use section.AddParagraph();
section.AddParagraph(img);
fs1.Close();
}

p.Close();

Yes, that works fine.

Thanks,
MAC