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

Free Support Forum - aspose.com

Exception when converting JPG to PDF


I’m getting an exception when trying to convert a JPG to PDF.

I’m using the latest version of Aspose.Pdf ( The same piece of code works fine with BMP, GIF, PNG and TIF images. I have attached the jpg file I’m using.

The code I’m running is the following:

PdfGenerator.Pdf pdf = new PdfGenerator.Pdf();

PdfGenerator.Section section = pdf.Sections.Add();

PdfGenerator.Image image = new PdfGenerator.Image(section);


image.ImageInfo.ImageStream = file.Stream;

image.ImageInfo.ImageFileType = ImageFileType.Jpeg;

using(var stream = new MemoryStream())


return stream.GetBuffer();

The exception I get is the following:

Unknown image type : Jpeg Stack: at ?.?.□□(? , Int32 , ImageFileType , String
, String , String , Int32 , Int32 , Boolean , Boolean , Boolean , Boolean ,
Byte[] , Stream , □ )
at ?.?.□□(Image , ImageFileType , String , String ,
String , Int32 , Int32 , Boolean , Boolean , Byte[] , Stream , □ )
?.?.□□(Pdf , Image )
at ?.?.□□(Pdf , Section , Table , Row , Cell , Image
,  , □ )
at ?.?.□□(Pdf , Section , HeaderFooter , Table , Row , Cell ,
Image ,  , □ , Boolean )
at ?.□.□□(Pdf , Section ,  )
?.?.□□(Pdf )
at ?.?.□□(□ , Pdf )
Aspose.Pdf.Generator.Pdf.Save(Stream stream)
file, ImageFileType imageFileType)

Hi Joao,

Thank you for sharing the details.

I check the issue you mentioned with the latest version of Aspose.Pdf for .NET and I am unable to reproduce the issue with JPEG image file. Please share your Image file which is causing the problem and we will check it to reproduce the issue.

Thank You & Best Regards,


The image file is attached to the initial post.

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

I checked the shared image and it works fine with your sample code using Aspose.Pdf for .NET v6.4.2. Please download and try it at your end and if you still face any issue, please create a sample application to show the issue and post it here, we will check it soon. For your reference, I have attached the resultant file with the reply.

Thank You & Best Regards,


I apologize for the confusion. The issue was with the input stream (which was taken from SharePoint).

After copying the contents of that stream to a new MemoryStream it started working.

Sorry once again,