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

Free Support Forum - aspose.com

Invalid image or template handle in PlaceImage method

Hi,

I am using pdf and pdf.kit to generate and merge multiple pdf files.
Here is part of my code where I am having issue.

Here is my xml template








java code:

Image img =(Image)section1.getObjectByID("imageID1");
img.getImageInfo().setFile("d:\\barcode.jpeg");

this is how I am saving the pdf to memStream.
MemStream ms = new MemStream();
pdf.save(ms);

byte[] b = ms.toArray();
ByteArrayInputStream byteStream = new ByteArrayInputStream(b);
List inStreams = new ArrayList();
inStreams.add(byteStream);

PdfFileEditor pdfEditor = new PdfFileEditor();

InputStream[] ins = new InputStream[inStreams.size()];
for(int i=0;i<inStreams.size();i++)
{
ins[i] = inStreams.get(i);
}
FileOutputStream outStream = new FileOutputStream("d:\\docName.pdf");
pdfEditor.concatenate(ins, outStream);

When there is only one pdf file then I am getting following exception
java.lang.IllegalArgumentException: Invalid image or template handle in PlaceImage method.
at aspose.pdf.figure.Aba.a(SourceFile:521)
at aspose.pdf.xml.Abi.a(SourceFile:729)
at aspose.pdf.xml.Aaj.a(SourceFile:630)
at aspose.pdf.xml.Aca.a(SourceFile:246)
at aspose.pdf.xml.Aci.a(SourceFile:545)
at aspose.pdf.xml.Abt.a(SourceFile:152)
at aspose.pdf.xml.Aas.a(SourceFile:100)
at aspose.pdf.xml.Aba.a(SourceFile:122)
at aspose.pdf.Pdf.save(SourceFile:1167) at aspose.pdf.Pdf.save(SourceFile:1113)

But if there are one file then I am not getting any exception.

Can you please tell what am I doing wrong. And why do we get that exception.

Thanks
Mamatha

Hello,

Can somebody please respond to it. It's little urgent.

Thanks

Mamatha

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

Please provide us the original XML file and complete sample code. This will help us identify the issue soon and get back to you.

Thank You & Best Regards,

Hi,

I have included the Zip file which has java code, template.xml and image used in the document.

Can you please check why it's failing.

Thanks

Mamatha

Hi,

I didn't here any response.

Sorry for bugging you guys, but we have rolled it out last week and end users are complaining about it. So we need to fix it ASAP.

Thanks

Mamatha

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

Thank you for sharing the sample code and template file.

Regarding your issue, I checked it using Aspose.Pdf.Java v3.0.1 and the code runs fine without any exception. The code for generating PDF file is working fine and generates a proper PDF file (using Aspose.Pdf for Java, file is attached for reference). However, the concatenate method of Aspose.Pdf.Kit for java in your code generates a corrupt PDF file. But regarding the concatenation, could you please re-check your code as there is only one file and you are passing it to concatenate method. I am also moving this issue to Aspose.Pdf.Kit forum, so our team can check this issue regarding concatenate method and get back to you.

Sorry for the inconvenience,

Hi,

Thanks for getting back.

In the sample code we are printing a single file.

In real time we need to print single or multiple files. That's why we have used concatenate method.

Thanks

Mamatha

Hi Mamatha,

I would like to share that the concatenate method requires at least two files to work properly. If you pass a single file as input it will not work as expected. So, in case, you have only single file you could check the size of the input array before hand and skip the concatenate method at all.

I hope this helps. If you still find any issue or have further questions, please do let us know.
Regards,

Hi,

Can you please provide be sample code to convert input stream to pdf file without using concatenate.

Thanks

Mamatha

Hi,

I modified the code to use concatenate only if there are more than one file. And it is working now.

I would be great if concatenate itself has knowledge of what to do in case of single file.

Thanks for all your help

Mamatha

Hi Mamatha,

I’m glad to know that the issue is resolved for your particular scenario. As far as handling single file scenario for concatenate method is concerned, it is the prerequisite of the method to have at least two files to concatenate. Moreover, we haven’t yet received any other such requests to handle single file scenarios automatically. However, we’ll further look into this and see if it would be feasible for us to cater such scenario in the future.

If you find any further questions, please do let us know.
Regards,