Thanks for the files.

I wonder if there is some memory leak, in PDFBox or in java itself. The H21 file has a pattern that contains an image (the company logo). That pattern has an XStep and YStep of 23438 although the image is 2148 x 440. Because of a matrix scale of 0.0673396 the image pattern size is 1578 x 1578 at 72 dpi. So at 1200 dpi the size would be about 26300 x 26300.

You can limit this by setting pdfbox.rendering.tilingpaint.maxedge to a smaller value than the default of 3000. However this may have a bad influence on other files.

I tried to show the H21 file in PDFDebugger at 1000% which would be 720 dpi. This worked until the last image. But no problem when displaying the last image first. That is why I suspect a memory leak. I remember we noticed something similar years ago, BufferedImage objects that stayed despite nobody using them.

Tilman

Am 02.11.2021 um 20:06 schrieb Kevin Day:
Sorry it took so long to respond - I had to get permission to share these.

I did test with 2.0.24 and it did not help.


Here are some files that cause the problem:

https://github.com/trumpetinc/boottest/blob/main/JrachvUniverse_H21.pdf
https://github.com/trumpetinc/boottest/blob/main/PP%20Opera%20Building_A53.pdf


Here is some quick code that demonstrates the problem (update for your
printer name and PDF path):

https://github.com/trumpetinc/boottest/blob/main/SimplifiedPdfBoxPdfPrinter.java



Maybe in TilingPaint#getImage(PageDrawer, PDTilingPattern, PDColorSpace,
PDColor, AffineTransform, Rectangle2D), the BufferedImage could
benefit from something similar to BigBufferedImage described in this post?
(
https://stackoverflow.com/questions/3854200/why-does-a-bufferedimage-require-so-much-memory-beyond-the-size-of-its-data-arra
).  Or maybe there is something in the scaling logic?






On Thu, Oct 28, 2021 at 11:12 AM Tilman Hausherr <thaush...@t-online.de>
wrote:

Huge buffered images can happen in patterns if the pattern matrix and/or
the current transformation matrix result in a huge scale.

You could retry with 2.0.24, but I'm pessimistic. Please share the PDF
(upload to a sharehoster).

Tilman

Am 28.10.2021 um 01:17 schrieb Kevin Day:
Using PDFBox 2.0.20

We use the following to print the PDF:

      HashPrintRequestAttributeSet attributes = new
HashPrintRequestAttributeSet();

      try(PDDocument doc = PDDocument.load(pdf,
MemoryUsageSetting.setupMixed(5000000L))){
          job.setPageable(new PDFPageable(doc));
          job.print(attributes);
      }

This works really well for thousands of PDFs, but we've run into one
particular PDF that causes an OutOfMemoryException.


The problem PDF is rendered (does not contain bitmaps).

I've provided a huge amount of heap (over 1GB now), and it is still
failing.
As near as I can tell from the stack trace (which I'll include below), it
seems like the problem is with creation of a huge buffered image.

The physical page size in the PDF is 8.5 x 11".

The PDFPrintable is configured as follows:

Scaling is ACTUAL_SIZE
dpi is 0.0
subsamplingAllowed is false
renderingHints is null


Here is the stack trace:

java.lang.OutOfMemoryError: Java heap space
at
java.desktop/java.awt.image.DataBufferInt.<init>(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.<init>(BufferedImage.java:333)
at org.apache.pdfbox.rendering.TilingPaint.getImage(TilingPaint.java:143)
at org.apache.pdfbox.rendering.TilingPaint.<init>(TilingPaint.java:103)
at

org.apache.pdfbox.rendering.TilingPaintFactory.create(TilingPaintFactory.java:60)
at org.apache.pdfbox.rendering.PageDrawer.getPaint(PageDrawer.java:351)
at

org.apache.pdfbox.rendering.PageDrawer.getNonStrokingPaint(PageDrawer.java:719)
at org.apache.pdfbox.rendering.PageDrawer.fillPath(PageDrawer.java:819)
at

org.apache.pdfbox.contentstream.operator.graphics.FillEvenOddRule.process(FillEvenOddRule.java:37)
at

org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:932)
at

org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:510)
at

org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:484)
at

org.apache.pdfbox.contentstream.PDFStreamEngine.showForm(PDFStreamEngine.java:187)
at org.apache.pdfbox.rendering.PageDrawer.showForm(PageDrawer.java:1462)
at

org.apache.pdfbox.contentstream.operator.graphics.DrawObject.process(DrawObject.java:86)
at

org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:932)
at

org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:510)
at

org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:484)
at

org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:156)
at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:271)
at

org.apache.pdfbox.rendering.PDFRenderer.renderPageToGraphics(PDFRenderer.java:431)
at org.apache.pdfbox.printing.PDFPrintable.print(PDFPrintable.java:246)
at

java.desktop/sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:2430)
at
java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1654)


Next, I tried setting subsampling to true - this made no difference.


Next, I tried hard coding the dpi to 300f - this works with no problems.


Next, I tried hard coding the dpi to 600f - this does not throw the heap
space error - but with strange results:
- I see "java.lang.OutOfMemoryError" on sys.err - it does NOT throw an
exception
- The pages come off the printer as blank pages


Does anyone have any suggestions on how we can print using the printer's
full resolution?

Thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org

Reply via email to