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

Free Support Forum - aspose.com

Error on adding TIFF-Image to PDF

I try to add an TIFF Image (attached) to a new created PDF and got an exception!

Here the code

Pdf doc = null;
ByteArrayOutputStream byteArrayOutputStream = null;

doc = new Pdf();
doc.setConformance(PdfFormat.PDF_A_1B);


aspose.pdf.PageSetup ps = new aspose.pdf.PageSetup();
Section section = null;
RenderedOp image = JAI.create(“fileload”, new File("/home/mburger/tmp/imageMan/Test.tif").getAbsolutePath());;

System.out.println("image.getHeader().getHeight() -> " + image.getHeight());
System.out.println("image.getHeader().getWidth() -> " + image.getWidth());
ps.setPageHeight(image.getHeight());
ps.setPageWidth(image.getWidth());
doc.setPageSetup(ps);

// image
section = doc.getSections().add();

Image pdfImage = new Image(section);


BufferedImage bImage = image.getAsBufferedImage();
pdfImage.getImageInfo().setSystemImage(bImage);

pdfImage.getImageInfo().setFixHeight(image.getHeight());
pdfImage.getImageInfo().setFixWidth(image.getWidth());


section.getParagraphs().add(pdfImage);

byteArrayOutputStream = new ByteArrayOutputStream();
doc.save(byteArrayOutputStream);


and here the ERROR
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: -1
at aspose.pdf.internal.z284.m1(Unknown Source)
at aspose.pdf.internal.z284.m1(Unknown Source)
at aspose.pdf.internal.z285.m1(Unknown Source)
at aspose.pdf.internal.z303.m1(Unknown Source)
at aspose.pdf.xml.DocumentBase.m1(Unknown Source)
at aspose.pdf.internal.z277.m1(Unknown Source)
at aspose.pdf.Pdf.m1(Unknown Source)
at aspose.pdf.Pdf.save(Unknown Source)
at

it.siag.imageman.aspose.test.PrintTiffToPDF.main(PrintTiffToPDF.java:53)


I’m using PDF 3.9.1 for JAVA, can you help me?

thx
Michael

Hi Michael,


Thanks for your inquiry. We have tested the scenario with Aspose.Pdf for Java 9.3.1 using DOM approach to convert Image to PDF and unable to replicate the issue. Please download and try latest version of Aspose.Pdf for Java, it will help.

String outFile = myDir + “ImageToPDF.pdf”;<o:p></o:p>

String inFile = myDir + "Test (2).tif";

Document doc = new Document();

Page page = doc.getPages().add();

java.io.FileInputStream imageStream = new java.io.FileInputStream(new java.io.File(inFile));

//Create an image object

com.aspose.pdf.Image image1 = new com.aspose.pdf.Image();

//Add the image into paragraphs collection of the section

page.getParagraphs().add(image1);

//Set the ImageStream to a MemoryStream object

image1.setImageStream(imageStream);

//Set margins so image will fit, etc.

page.getPageInfo().getMargin().setBottom(0);

page.getPageInfo().getMargin().setTop(0);

page.getPageInfo().getMargin().setLeft(0);

page.getPageInfo().getMargin().setRight(0);

doc.save(outFile);

Please feel free to contact us for any further assistance.


Best Regards,