PDF rendering using Canvas or PixelBuffer
Andrea Vacondio
andrea.vacondio at gmail.com
Wed Apr 7 13:22:14 UTC 2021
Hi,
I hope this is the right channel, I'm creating a PDF tool where users can
see thumbnails of the pages of a PDF file and do things on them (rotate,
move, select, delete..). Pages are currently laid out in a Flow panel and I
am evaluating different options to render them and so far I tried:
1 - PixelBuffer pretty much like it's used here
https://github.com/mipastgt/JFXToolsAndDemos/blob/master/jfxtools-awtimage/src/main/java/de/mpmediasoft/jfxtools/awtimage/AWTImage.java
2 - Canvas using https://github.com/jfree/fxgraphics2d
In both cases I used SAMBox https://github.com/torakiki/sambox a PDFBox
fork, to render the pages (I can share more details if needed).
I tried to profile both approaches and there is an order of magnitude in
terms of memory consumption. Rendering a 300 pages file I get 700mb of heap
used with the PixelBuffer approach and 60mb with the canvas. Moreover using
the PixelBuffer implementation the application starts to do the robot dance
and when I try to move the mouse around it moves in snaps with a
considerable lag. With the Canvas impl everything is super responsive.
I know others have experience with PDF rendering with JavaFX and maybe can
share some thoughts on this. Currently the PixelBuffer impl is unusable for
me and I'm trying to figure out if I'm doing something wrong or if these
results are somehow expected.. or maybe there is a bug somewhere.
Thanks
Andrea
More information about the openjfx-discuss
mailing list