I have been looking at a customer PDF file which seems to ‘hang’ on a page. It actually shows up the limitations of Java Shape code performance.
The page in question contains a couple of very high resolution Vector graphics – the command stream is 252 million characters long! Seems a bit excessive but it opens quickly in Acrobat. Most of the stream commands consist of clipping commands and shapes to draw the shading on a picture of a giraffe – it does look really cool if you zoom in to 6400% in Acrobat! We handle shapes and clipping in Java using the Shape and Area classes.
When we profiled the page, we found that the page contained 9000 complex clips and that the ‘hanging’ was actually the time executing the Shape code. In particular the Area methods equals() and intersect() are VERY slow on complex shapes. The performance hit is down to the complexity of the shapes not the number of shapes.
So the fix is to use the outline of the Shapes, not the shapes themselves if they are too complex. It is a compromise and it would be nice to see Oracle improve the performance of these classes…
Do you need to work with PDF or Image Files in Java?
|Convert PDF to HTML5 or SVG||Convert AcroForms and XFA to HTML5|
|Java PDF SDK for working with PDF files||Java Image SDK for working with Image files|