Dear all
We have some Tiff-Documents that we cannot convert to a PDF.
The exception is the following:
Caused by: com.aspose.pdf.internal.ms.System.l5if: Page have not room to place a paragraphs
at com.aspose.pdf.ADocument.processParagraphs(Unknown Source) ~[aspose-pdf-23.4.jar:23.4]
at com.aspose.pdf.Document.processParagraphs(Unknown Source) ~[aspose-pdf-23.4.jar:23.4]
…
e2641548-9776-4c39-912d-5070b82bfac3.tiff.zip (35.4 KB)
We are not doing anything special:
private void convertTiffImage(TiffImage tiffImage, OutputStream pdfStream) {
try (Document pdf = new Document()) {
for (TiffFrame frame : tiffImage.getFrames()) {
com.aspose.pdf.Image pdfImage = tiffFrameToPdfImage(frame);
addImageToPdfPage(pdf, pdfImage, frame);
}
pdf.convert(new PdfFormatConversionOptions(PdfFormat.PDF_A_1B));
pdf.save(pdfStream);
}
}
private com.aspose.pdf.Image tiffFrameToPdfImage(TiffFrame frame) {
com.aspose.pdf.Image pdfImage = new com.aspose.pdf.Image();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
frame.save(stream, frame.getFrameOptions());
// set blackAndWhite manually, there is no automatic detection
pdfImage.setBlackWhite(frame.getBitsPerPixel() == 1);
pdfImage.setImageStream(new ByteArrayInputStream(stream.toByteArray()));
return pdfImage;
}
private Page addImageToPdfPage(Document document, com.aspose.pdf.Image image, TiffFrame frame) {
Page page = document.getPages().add();
page.getPageInfo().setWidth(frame.getWidth());
page.getPageInfo().setHeight(frame.getHeight());
page.getParagraphs().add(image);
return page;
}
Best regards