red6 / pdfcompare

A simple Java library to compare two PDF files
Apache License 2.0
220 stars 66 forks source link

Getting error while Executing my Document has more than 20 pages #33

Closed venkywarriors closed 6 years ago

venkywarriors commented 6 years ago

[Draw-1-thread-1] ERROR de.redsix.pdfcompare.PdfComparator - Error while rendering page 3 for expected document java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space at java.util.concurrent.FutureTask.report(Unknown Source) at java.util.concurrent.FutureTask.get(Unknown Source) at de.redsix.pdfcompare.PdfComparator.getImage(PdfComparator.java:238) at de.redsix.pdfcompare.PdfComparator.lambda$drawImage$11(PdfComparator.java:219) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.(Unknown Source) at java.awt.image.Raster.createPackedRaster(Unknown Source) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source) at java.awt.image.BufferedImage.(Unknown Source) at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:205) at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:150) at de.redsix.pdfcompare.PdfComparator.renderPageAsImage(PdfComparator.java:284) at de.redsix.pdfcompare.PdfComparator.lambda$null$8(PdfComparator.java:216) at de.redsix.pdfcompare.PdfComparator$$Lambda$6/5238162.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) ... 3 common frames omitted [Draw-1-thread-1] ERROR de.redsix.pdfcompare.PdfComparator - Error while rendering page 4 for expected document java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space at java.util.concurrent.FutureTask.report(Unknown Source) at java.util.concurrent.FutureTask.get(Unknown Source) at de.redsix.pdfcompare.PdfComparator.getImage(PdfComparator.java:238) at de.redsix.pdfcompare.PdfComparator.lambda$drawImage$11(PdfComparator.java:219) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.(Unknown Source) at java.awt.image.Raster.createPackedRaster(Unknown Source) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source) at java.awt.image.BufferedImage.(Unknown Source) at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:205) at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:150) at de.redsix.pdfcompare.PdfComparator.renderPageAsImage(PdfComparator.java:284) at de.redsix.pdfcompare.PdfComparator.lambda$null$8(PdfComparator.java:216) at de.redsix.pdfcompare.PdfComparator$$Lambda$6/5238162.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) ... 3 common frames omitted [Draw-1-thread-1] ERROR de.redsix.pdfcompare.PdfComparator - Error while rendering page 5 for expected document java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space at java.util.concurrent.FutureTask.report(Unknown Source) at java.util.concurrent.FutureTask.get(Unknown Source) at de.redsix.pdfcompare.PdfComparator.getImage(PdfComparator.java:238) at de.redsix.pdfcompare.PdfComparator.lambda$drawImage$11(PdfComparator.java:219) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

venkywarriors commented 6 years ago

using Pdfcompare version 1.1.33 & PDFbox 2.0.11

Ebsy commented 6 years ago

Have a look at the bottom of the README for alternative memory options. You're getting out of memory errors.

Also there are some internal settings for memory limits, that can be changed. Just add a file called "application.conf" to the root of the classpath. This file can have some or all of the following settings to overwrite the defaults given here:

venkywarriors commented 6 years ago

can you share me application.conf file if you have

finsterwalder commented 6 years ago

I use a Page Overflow strategy as follows: new PdfComparator(expectedPath, actualPath, new CompareResultWithPageOverflow(5))

finsterwalder commented 6 years ago

Since you didn't report back for some time, I'll close the issue. If your problems persist or you need further support, please reopen the issue.

Sulasdeli commented 4 years ago

Hi,

I'm currently facing the same issue. I tried setting new CompareResultWithPageOverflow() and changing various memory options (even the JVM Heap Size, i.e. org.gradle.jvmargs -Xmx1G) but none of those methods helped.

de.redsix.pdfcompare.PdfComparator: Error while rendering page 2 for actual document ! java.lang.OutOfMemoryError: Java-Heapspeicher ! at java.awt.image.DataBufferInt.(DataBufferInt.java:75) ! at java.awt.image.Raster.createPackedRaster(Raster.java:467) ! at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) ! at java.awt.image.BufferedImage.(BufferedImage.java:324) ! at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:296) ! at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:243) ! at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:215) ! at de.redsix.pdfcompare.PdfComparator.renderPageAsImage(PdfComparator.java:417) ! at de.redsix.pdfcompare.PdfComparator.lambda$drawImage$9(PdfComparator.java:351) ! at de.redsix.pdfcompare.PdfComparator$$Lambda$172/0000000000000000.call(Unknown Source) ! at java.util.concurrent.FutureTask.run(FutureTask.java:266) ! ... 3 common frames omitted ! Causing: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java-Heapspeicher ! at java.util.concurrent.FutureTask.report(FutureTask.java:122) ! at java.util.concurrent.FutureTask.get(FutureTask.java:206) ! at de.redsix.pdfcompare.PdfComparator.getImage(PdfComparator.java:371) ! at de.redsix.pdfcompare.PdfComparator.lambda$drawImage$11(PdfComparator.java:353) ! at de.redsix.pdfcompare.PdfComparator$$Lambda$149/0000000000000000.run(Unknown Source) ! at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ! at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ! at java.lang.Thread.run(Thread.java:821)

Any idea on how to solve this?

finsterwalder commented 4 years ago

1GB is probably not enough for 5 pages. Please try 3GB or 4GB. Just to make sure that it works, please try 4GB and two pages. Then you can start to tune from there. You could also try to use the CompareResultWithMemoryOverflow. I never used it much, though. ;-)

Sulasdeli commented 4 years ago

I finally managed to solve it by just disabling parallel processing and lowering the DPI to 100. With parallel processing enabled, starting the Main class worked just fine. For some reason, when running the comparisons as a Gradle task the OutOfMemory exception was thrown. After disabling it, both methods seem to work :).

finsterwalder commented 4 years ago

I have no idea how "running it as a Gradle task" influences all of this. For sure you would have to give the JVM that executes the PdfCompare enough memory. I don't know, whether you have to change the client VM or the build VM. (See: https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory) Running in parallel uses more memory, of course, since multiple pages are rendered at the same time. That's what parallel means. ;-) And more DPI uses more memory as well. Glad you found a setting, that works for you.

harmatii-moodys commented 3 years ago

Hi,

Facing the same issue, but only when running my test through Jenkins on separate server, all good when running on local machine. Tried with CompareResultWithPageOverflow() and CompareResultWithMemoryOverflow() but nothing helped. Do you guys have any suggestions?

finsterwalder commented 3 years ago

How much memory does the VM have, that executes your tests? How small did you set Page- and Memory Overflow? What does Runtime.maxMemory() give you?

harmatii-moodys commented 3 years ago

for CompareResultWithPageOverflow() tried different numbers like 1, 5, 11, 20

12:40:05.149 [Draw-1-thread-1] ERROR de.redsix.pdfcompare.PdfComparator - An error occurred, while rendering this page de.redsix.pdfcompare.RenderingException: Error while rendering page 3 of expected document at de.redsix.pdfcompare.PdfComparator.getImage(PdfComparator.java:491) at de.redsix.pdfcompare.PdfComparator.lambda$drawImage$13(PdfComparator.java:451) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:205) at de.redsix.pdfcompare.PdfComparator.getImage(PdfComparator.java:483) ... 4 common frames omitted Caused by: java.lang.OutOfMemoryError: Java heap space at java.desktop/java.awt.image.DataBufferInt.(DataBufferInt.java:75) at java.desktop/java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.desktop/java.awt.image.BufferedImage.(BufferedImage.java:324) at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:125) at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:80) at de.redsix.pdfcompare.PdfComparator.renderPageAsImage(PdfComparator.java:529) at de.redsix.pdfcompare.PdfComparator.lambda$drawImage$10(PdfComparator.java:448) at de.redsix.pdfcompare.PdfComparator$$Lambda$379/0x163aba28.call(Unknown Source) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ... 3 common frames omitted Exception in thread "Draw-1-thread-1" java.lang.OutOfMemoryError: Java heap space at java.desktop/java.awt.image.DataBufferInt.(DataBufferInt.java:75) at java.desktop/java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.desktop/java.awt.image.BufferedImage.(BufferedImage.java:324) at de.redsix.pdfcompare.StacktraceImage.getImage(StacktraceImage.java:29) at de.redsix.pdfcompare.PdfComparator.addErrorPage(PdfComparator.java:477) at de.redsix.pdfcompare.PdfComparator.lambda$drawImage$13(PdfComparator.java:466) at de.redsix.pdfcompare.PdfComparator$$Lambda$378/0x163aa228.run(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834)

about "How much memory does the VM have, that executes your tests?" waiting for the response from other people as I don't have access to those machines

finsterwalder commented 3 years ago

You could also reduce memory consumption by reducing the DPI density. This give only a little less accurate comparisons. And you can add a call to Runtime.maxMemory() to your code and write it to the log and see that in Jenkins.

harmatii-moodys commented 3 years ago

changed DPI to 250 but it didn't help, what DPI would you suggest to try? I ran Runtime.getRuntime().maxMemory() on local and Jenkins and this is what I got local: 1883242496 Jenkins: 259522560

SoltauFintel commented 3 years ago

@harmatii-moodys I use DPI 150. That's enough for text reports. I also leave out pages that have no errors.

finsterwalder commented 3 years ago

So your Jenkins environment has only 250MB of memory available. That might well be too little... Your local environment currently has 1,8GB. You can try around locally with the -Xmx JVM Parameter to find the amount of memory that works.

harmatii-moodys commented 3 years ago

I tried DPI 150 and it seems to be working, do you think comparison will still be accurate?

finsterwalder commented 3 years ago

It's probably accurately enough. But I would suggest to increase the memory on Jenkins to have more room anyways...

SoltauFintel commented 3 years ago

DPI 150

A low value does not bring any speed advantages and a slightly higher value does not bring any quality advantages. 150 seems to be optimal. For text reports. However, if you want to check graphs, for example, DPI 300 may be required.

harmatii-moodys commented 3 years ago

I'm afraid increasing memory on Jenkins will be painful process in my case, so I'll try to go with 150 DPI as my PDFs are mostly text. Thank you all for help guys!