Exception when converting JPG to PDF

Hi,


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

I’m using the latest version of Aspose.Pdf (6.4.0.0). 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);

section.Paragraphs.Add(image);

image.ImageInfo.ImageStream = file.Stream;

image.ImageInfo.ImageFileType = ImageFileType.Jpeg;

using(var stream = new MemoryStream())
{

pdf.Save(stream);

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 , □ )
at
?.?.□□(Pdf , Image )
at ?.?.□□(Pdf , Section , Table , Row , Cell , Image
,  , □ )
at ?.?.□□(Pdf , Section , HeaderFooter , Table , Row , Cell ,
Image ,  , □ , Boolean )
at ?.□.□□(Pdf , Section ,  )
at
?.?.□□(Pdf )
at ?.?.□□(□ , Pdf )
at
Aspose.Pdf.Generator.Pdf.Save(Stream stream)
at
Netcompany.CCM.Business.DocumentManipulation.Pdf.AsposePdfConverter.ConvertImageToPDF(IFile
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,

Hi,


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,

Hi,


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,
Joao