Hello,
We are converting TIFF G4 (bitonal) images to PDF. This works fine but the resultant PDF is very much larger than the original TIFF file. For example, one customer has TIFF G4 A3 10 page documents at 600dpi which is about 7mb. When converted to PDF it is over 50mb, which is a problem.
What I think is happening is that the bitonal image is being converted to something like a 32 bit image and then put into the PDF.
I would expect/hope that the PDF is only slightly larger than the source TIFF, probably by keeping the image pretty much as is and placing it into the PDF.
I am using aspose-imaging 21.2 jdk16, though I was originally using slightly earlier versions. I have also hunted through the Java docs and tried various things to preserve the original image compression, all without success.
Any help much appreciated, Mark.
@mawheadon
We need to investigate the requirements internally on our end and for that a ticket with ID IMAGINGJAVA-2070 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be addressed.
Thanks for that. In the meantime I have done a bit more experimentation and managed to save the PDF at 10Mb now, which I guess is about right. The only problem is that my 10 page TIFF has turned into a 20 page PDF where all the odd numbered pages are blank and black and all the even numbered pages are the correct image page from the TIFF. Here is a bit of my code (I have previously extracted each page of the TIFF from the source TIFF and put it in bais2 - ByteArrayInputStream).
int collectionSize = pdfPageCollection.size();
log.info("There are now {} pages", collectionSize);
PageInfo pdfPageInfo = pdfPage.getPageInfo();
pdfPageInfo.setHeight(frameHeight);
pdfPageInfo.setWidth(frameWidth);
com.aspose.pdf.Image img = new com.aspose.pdf.Image();
img.setBlackWhite(true);
img.setImageStream(bais2);
Paragraphs paras = pdfPage.getParagraphs();
paras.add(img);
log.info("Tiff page {} added to PDF", ii);
The img.setBlackWhite(true); is critical because without it the resultant PDF file is 62Mb.
Either way though I get 10 blank black pages along with my image pages and I can’t work out how to not get them.
Any ideas?
Thanks, Mark.
@mawheadon
I have added additional information in our issue tracking system and will share the feedback with you as soon as the issue will be addressed.
@mawheadon
We have internally verified the issue w.r.t Aspose.Imaging. The API supports only Jpeg images for export to PDF and the max you can do using API is to set jpeg quality less.
For example:
Image image = Image.load("some.tif");
try
{
final PdfCoreOptions pdfCoreOptions = new PdfCoreOptions();
pdfCoreOptions.setJpegQuality(5); // this can reduce significantly the result pdf's size
PdfOptions options = new PdfOptions();
options.setPdfCoreOptions(pdfCoreOptions);
image.save("output.pdf", options);
}
finally
{
image.close();
}
How Aspose.PDF handles this situation we may not address that here and for that you can consult Aspose.PDF team about this.