PDF rendering using Canvas or PixelBuffer

Andrea Vacondio andrea.vacondio at gmail.com
Fri Apr 9 15:49:13 UTC 2021


Thanks for the reply.
I double checked and both implementations render the pages using the same
parameters. Your hint got me thinking.. I have a zoom slider to drive
thumbnails size and in the Canvas impl I scale the canvas node based on
that while in the ImageView I was changing the size and using the fitTo
methods so I thought maybe that causes the memory consumption differences.
I changed the impl to scale the ImageView and match the Canvas impl but
results are the same, 10x heap used with PixelBuffer.
I'll review the code to make sure I'm not doing something different/wrong
in my PixelBuffer impl but so far I get consistently 10x memory usage even
with different PDF files.

Il giorno mer 7 apr 2021 alle ore 18:24 Michael Paus <mp at jugs.org> ha
scritto:

> This is probably not the right place to discuss such issues. Stackoverflow
> might be better suited. But while we are at it there are a few issues you
> might want to look at. Initially I had similar problems like you but then
> I found that they were mostly caused by rendering too large images.
> Set the output size for the PDF renderer so that it has the same size
> as your Canvas, so that you do not render huge images which are lated
> just reduced to the desired output size by the ImageView.
>
>
> Am 07.04.21 um 15:22 schrieb Andrea Vacondio:
> > 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