Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Sample JPEG produces blank PDF

$
0
0
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
sec1.Paragraphs.Add(image1);

//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;
}
pdfGen.Save(targetFile);

Thanks,
Jeff

Viewing all articles
Browse latest Browse all 3131

Trending Articles