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

Free Support Forum - aspose.com

Sample JPEG produces blank PDF

We use Aspose.PDF for converting various image files to PDF. Most all images we convert have no problem. But we’ve recently encountered a couple of .jpg image files that will not convert.

The files do open successfully in MS Paint and Windows Photo Viewer.

I’ve attached one of those for your testing (wont_convert.jpg).

Oddly enough, I have taken that same attached file and (using MS Paint) converted it to:

- .tif

- .png

- .bmp

Those all successfully convert to PDF using Aspose.PDF.

Finally, if I re-convert the .png back to .jpg (again using MS Paint), the resulting .jpg file successfully converts to PDF with Aspose.PDF.

So it appears there is something in the initial format of these troublesome files that Aspose is not recognizing.

Here’s a snippet of code showing how we use Aspose.PDF for image conversion:

//Instantiate a Pdf object by calling its empty constructor

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

//Create a section in the Pdf object

Aspose.Pdf.Generator.Section sec1 = pdfGen.Sections.Add();

//Create an image object in the section

Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);

//Add image object into the Paragraphs collection of the section


//Set the path of image file

image1.ImageInfo.File = file;

//Set the type of image using ImageFileType enumeration

string ext = Path.GetExtension(file).ToUpper();

switch (ext)


case “TIFF”:

case “TIF”:

image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff; break;

case “BMP”:

image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp; break;

case “GIF”:

image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Gif; break;

case “JPG”:

case “JPEG”:

image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; break;

case “PNG”:

image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png; break;





A couple of things I forgot before hitting the Post button on the previous post.

When the troublesome .jpg files fail…the conversion to PDF actually DOES produce a file, but it completely empty (size = 0 bytes), and there are no exceptions thrown or any way of knowing the conversion was NOT successful.

Is there any means that I’m not using that will indicate success or failure to my code while converting?


Hi Jeff,

Thanks for your inquiry. We have noticed the issue and logged it as PDFNEWNET-37085 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

Moreover, as a workaround you can use new DOM approach to convert Image to PDF. Hopefully it will help you to accomplish the task.

string outFile =
myDir + “iamgetopdf_DOM.pdf”;<o:p></o:p>

string inFile = myDir + ("wont_convert.jpg");

Document doc = new Document();

Page page = doc.Pages.Add();

// Set margins so image will fit, etc.

page.PageInfo.Margin.Bottom = 0;

page.PageInfo.Margin.Top = 0;

page.PageInfo.Margin.Left = 0;

page.PageInfo.Margin.Right = 0;

page.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;

page.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;

//Create an image object

Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();

//Add the image into paragraphs collection of the section


image1.File = inFile;


Please feel free to contact us for any further assistance.

Best Regards,

Thank you for your response.

I see that the DOM method does successfully convert the sample JPEG file, However, it does not convert any .gif image I’ve tried. I get a GDI+ exception when doc.Save(targetFile) is called.
Is this expected?

So…is the DOM method the preferred method of converting the image files rather than using the Pdf.Generator?

Hi Jeff,

Thanks for your feedback. I have tried a sample GIF file for the conversion and unable to notice the issue. We will appreciate if you please share your sample GIF file, so we will test the scenario and will update you accordingly.

Moreover in reference to your DOM approach question, yes it is more efficient and reliable than old generator(Aspose.Pdf.Generator).

Best Regards,

Attached are 3 such example .gif files that I’m getting a GDI+ exception while trying to save.

Hi Jeff,

Thanks for sharing source GIF images. I am afraid we are unable to notice the reported exception, while testing the scenario with Aspose.Pdf for .NET 9.3.0. Please download and try latest version of Aspose.Pdf for .NET, hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Jeff,

We will appreciate it if you please confirm whether your above Image to PDF conversion issue is fixed with new DOM approach. So either we investigate it further or close as resolved.

Looking forward to your input.

Best Regards,