Closed lqlau closed 3 years ago
@lqlau I saw you already read tiff page by page and the OutOfMemoryError coming from the creation of the PDF by PDFBox itself not from ICAFE.
I have no idea how big the original tiff is and whether or not there is a way to assemble pages of PDF to one afterwards with PDFBox (I bet it should be). If that is possible, you can save the tiff to PDF page by page first then concate them together; or you can split the tiff into single page Tiffs first, then create PDF from them.
Don't know which way will work or not.
You can simply increase a bit of heap size and hopefully it will give you enough room to finished the job.
As for speeding up the conversion speed, I don't know which process is your bottle neck without profiling.
@lqlau I saw you already read tiff page by page and the OutOfMemoryError coming from the creation of the PDF by PDFBox itself not from ICAFE.
I have no idea how big the original tiff is and whether or not there is a way to assemble pages of PDF to one afterwards with PDFBox (I bet it should be). If that is possible, you can save the tiff to PDF page by page first then concate them together; or you can split the tiff into single page Tiffs first, then create PDF from them.
Don't know which way will work or not.
You can simply increase a bit of heap size and hopefully it will give you enough room to finished the job.
As for speeding up the conversion speed, I don't know which process is your bottle neck without profiling.
Thanks @dragon66! I will try to split a single page into smaller chunks/tile by calling getSubImage() and then stitch them together piece by piece by calling drawImage() to get a whole page. I'll let you know if that works.
This is my code:
public static void generatePdfFromTiff(File file) throws Exception { FileInputStream fin = new FileInputStream(file.getAbsoluteFile()); PDDocument doc = new PDDocument();
This is my error:
java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Unknown Source) at java.io.ByteArrayOutputStream.toByteArray(Unknown Source) at org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory.createFromGrayImage(LosslessFactory.java:161) at org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory.createFromImage(LosslessFactory.java:84)
Also, any ways to make the conversion from tiff to pdf faster?