Exception while inserting a image in PDF doc

Hi,

I am trying to add an image to PDF document. If I use images which came with source code, they are coming up fine. But if I load any other valid images I am getting exception.

Image img1 = new Image(sec1);

img1.getImageInfo().setFile("D:/aspose/samples/resources/graphics/asposeBanner.gif");//this is working fine.

img1.getImageInfo().setFile("D:/barcode.gif"); // this is not working and image size is 18KB

java.lang.IllegalArgumentException: Invalid image handle in GetImageWidth method:
at aspose.pdf.figure.Abc.l(SourceFile:871)
at aspose.pdf.xml.Abh.a(SourceFile:232)
at aspose.pdf.xml.Abh.a(SourceFile:609)
at aspose.pdf.xml.Abi.a(SourceFile:576)
at aspose.pdf.xml.Aaj.a(SourceFile:471)
at aspose.pdf.xml.Acb.a(SourceFile:182)
at aspose.pdf.xml.Acj.a(SourceFile:463)
at aspose.pdf.xml.Abe.a(SourceFile:445)
at aspose.pdf.xml.Acc.b(SourceFile:684)
at aspose.pdf.xml.Acd.a(SourceFile:753)
at aspose.pdf.xml.Aar.a(SourceFile:97)
at aspose.pdf.xml.Aba.a(SourceFile:112)
at aspose.pdf.Pdf.save(SourceFile:923)

What am I doing wrong here?

Thanks

Mamatha

Hi Mamatha,

Thanks for using our products. I just have tested the scenario while converting one of my sample GIF image into PDF format using Aspose.Pdf for Java 3.0.1 and I am unable to notice any issue. Can you please share the sample image causing issues so that we cna test the scenario at our end. We apologize for your inconvenience.

[Java]


//Create pdf document
Pdf pdf1 = new Pdf();
//Add a section into the pdf document
Section sec1 = pdf1.getSections().add();
//Add a text paragraph into the section
Image img1 = new Image(sec1);
// set image file path
img1.getImageInfo().setFile(“D:/pdftest/halifaxletterhead1.gif”);//this is working fine.
// set image file type information
img1.getImageInfo().setImageFileType(ImageFileType.Gif);
// add iamge to paragraphs collection of section object
sec1.getParagraphs().add(img1);
//Save the document
pdf1.save(“d:/pdftest/GIF-to-PDF.pdf”);

Hi,

Here is my code and image which I have used. It is not working for me. I am using Aspose.pdf for java 2.8.0.

Pdf pdf = new Pdf();
Section sec1 = pdf.getSections().add();
Image img1 = new Image(sec1);
img1.getImageInfo().setFile("D:/sunset.jpeg");
img1.getImageInfo().setImageFileType(ImageFileType.Jpeg);
img1.getImageInfo().setFixWidth(50);
img1.getImageInfo().setFixHeight(25);

sec1.getParagraphs().add(img1);
pdf.save("D:/temp/pdfHolder/ImageTable.pdf");

Thanks

Mamatha

Hello Mamatha,

Thanks for sharing the resource files.

I have tested the scenario while using Aspose.Pdf for Java 3.0.1 and I am unable to notice any problem. The image file is properly being placed inside the PDF document. Please try using v3.0.1 and in case you still face any problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

For your reference, I have also attached the resultant PDF that I have generated. Please take a look.


Hi,

It is working fine now.

Thanks

Mamatha