-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OutOfMemoryError: Java heap space when generating PDF #45
Comments
Can you check if your last chapter has some image (png) that makes the PDF converter consume so much memory? |
The last chapter indeed has a few PNG images of 1.3 MB each. Not excessive I think? In the mean time, I tried to run |
Same here ... I have 320 images in the document ... I need to give above 2G of memory to be able to get the PDF. The size of those images is 12Mb..even if those will be kept in memory, encoded, enhanced (whatever it needs to be done to write them in PDF), it does not explain why it needs so much memory. Same document, no images (so it complains about missing images) generates the document faster and with less than 300MB of used memory. |
Mystery solved ... switch to JPEG format ... unfortunately. I was able to generate the PDF with 330MB old generation vs 1.1G (and it was never maxed out). The "issue" seems to be in the Prawn PNG class, which does a lot of StringIO creation to transform the PNG because PDF does not support much of the PNG?? Kind of disappointing that the great PDF format needs its images pre-processed. But it is what it is :) Anyway, I do not understand why Prawn (and it seems to be a common pattern across Ruby projects) to use StringIO to process a stream of bytes (images in this case). In Java, bytes are processed using a stream, not a string that can let you iterate/read bytes. To me, it looks like an inefficient way of adapting a PNG image in Prawn. The JPG implementation does almost noting, just writes the bytes into the PDF and that's the reason why it is faster and consumes less than 1/3 of memory. Also, the generated PDF is almost twice as big as JPG images vs PNG images (the JPG image is at least 2x compared with PNG) at the default compression ratio. Going lower, than 0.75, reduces the quality of the image in a significant way since these are application screenshots (text). Even at 0.75, you can see a difference between PNG and JPG. But until Prawn is changed to stop using strings, we need to use JPG. Should I open an issue with Prawn or AsciiDoctorJ members could have a better argument to ask for a performance enhancement/optimization? |
Most of the changes in Prawn PNG class are older than 10 years ... maybe PDF supports PNG better these days? |
asciidoctorj-pdf is just a repackaging of https://github.com/asciidoctor/asciidoctor-pdf so that it can be consumed with asciidoctorj. |
Found the root-cause in the corresponding prawnpdf issues: prawnpdf/prawn#1153 |
today I had the same problem. But I discovered an interesting solution: Some images where referenced as inline-images ( So, I replaced all those image-references with only one |
Did this issue get reported to |
I am using Asciidoc to write a book and have not had any issues so far to generate a PDF using Maven with the following versions:
However, I added an extra chapter and now the build fails with:
I increased the available memory for Maven by creating a
.mvn/jvm.config
file at the project root to increase the Java heap:I also tried with
-Xmx3048m
, but none of that helped. Removal of the last chapter makes it work again. Removing the last chapter and including the 2nd to last chapter 2 times also makes it fail. Using only the last chapter and removing all other chapters also works.Is there anything else I can try to make it work again?
The text was updated successfully, but these errors were encountered: