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

Free Support Forum - aspose.com

Buffered Stream usage when converting image to PDF

We are using Aspose to create a PDF out of images. The following code throws an exception.

Using oStrm As Stream = New BufferedStream(New FileStream(sInputFile, FileMode.Open, FileAccess.Read, FileShare.Read))

Dim oImage As System.Drawing.Image
Dim oImageType As Aspose.Pdf.Generator.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg
Dim oPDF As New Aspose.Pdf.Generator.Pdf
Dim oSecTIF As Aspose.Pdf.Generator.Section = Nothing
Dim oImgTIF As Aspose.Pdf.Generator.Image = Nothing

oImage = System.Drawing.Image.FromStream(oStrm)

oSecTIF = oPDF.Sections.Add
oImgTIF = New Aspose.Pdf.Generator.Image(oSecTIF)
oSecTIF.Paragraphs.Add(oImgTIF)

oImgTIF.ImageInfo.ImageStream = oStrm
oImgTIF.ImageInfo.ImageFileType = oImageType

oPDF.Save(sPdfFile)

End Using Using oStrm As Stream = New BufferedStream(New FileStream(sInputFile, FileMode.Open, FileAccess.Read, FileShare.Read))

Dim oImage As System.Drawing.Image
Dim oImageType As Aspose.Pdf.Generator.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg
Dim oPDF As New Aspose.Pdf.Generator.Pdf
Dim oSecTIF As Aspose.Pdf.Generator.Section = Nothing
Dim oImgTIF As Aspose.Pdf.Generator.Image = Nothing

oImage = System.Drawing.Image.FromStream(oStrm)

oSecTIF = oPDF.Sections.Add
oImgTIF = New Aspose.Pdf.Generator.Image(oSecTIF)
oSecTIF.Paragraphs.Add(oImgTIF)

oImgTIF.ImageInfo.ImageStream = oStrm
oImgTIF.ImageInfo.ImageFileType = oImageType

oPDF.Save(sPdfFile)

End Using

The exception happens on the save, and the message is:

"System.ArgumentException: Unknown image type : JpegSystem.ArgumentException: Unknown image type : Jpeg"

If we change the using to just use a FileStream, then it works fine. Are nested streams not supported? Or is it the BufferedStream causing the problem?

Hi Jon,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample code.

I am able to generate your mentioned issue after an initial test. Your issue has been registered in our issue tracking system with issue id: PDFNEWNET-34124 for rectification. You will be notified via this forum thread regarding any updates against your issue.

Sorry for the inconvenience,

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

Blog post for this release can be viewed over this link


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

Hi Jon,


Thanks for your patience.

We are pleased to share that the issue PDFNEWNET-34124 reported earlier is resolved in latest release of Aspose.Pdf for .NET 9.4.0. Please try using the latest release and in case you still face the same problem or you have any further query, please feel free to contact.

[C#]

using (Stream jpegStream = new BufferedStream(new FileStream(@“D:\AP
Data\August2012\DocProps.jpg”
, FileMode.Open, FileAccess.Read, FileShare.Read)))<o:p></o:p>

{

System.Drawing.Image netImage = default(System.Drawing.Image);

Aspose.Pdf.Generator.ImageFileType asposeImageType = Aspose.Pdf.Generator.ImageFileType.Jpeg;

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

Aspose.Pdf.Generator.Section pdfDocSection = null;

Aspose.Pdf.Generator.Image asposeImage = null;

netImage = System.Drawing.Image.FromStream(jpegStream);

pdfDocSection = pdfDocument.Sections.Add();

asposeImage = new Aspose.Pdf.Generator.Image(pdfDocSection);

pdfDocSection.Paragraphs.Add(asposeImage);

asposeImage.ImageInfo.ImageStream = jpegStream;

asposeImage.ImageInfo.ImageFileType = asposeImageType;

pdfDocument.Save(@"D:\AP Data\August2012\DocProps.pdf");

}