I get the same result as the OP using PDFBox version 1.8.4. In version 2.0.0-SNAPSHOT, though, it looks better:
Here only some arrows are thinner and some arrow parts are mis-drawn as boxes.
Thus,
how do i make pdfbox take something like a direct snapshot image?
The current release versions (up to 1.8.4) seem to have greater deficits when rendering PDFs as images. You may switch to a current development version (e.g. the current trunk, 2.0.0-SNAPSHOT) or wait until the improvements are released.
Furthermore, some minor deficits are even in 2.0.0-SNAPSHOT. You might want to present your sample document to the PDFBox people (i.e. create an according issue in their JIRA) so that they improve PDFBox even further to suit your needs.
also, i noticed that the image quality of the png is not so good, is there any way to increase the resolution of the generated image?
There are convertToImage
overloads with resolution
parameters. Your current code actually sets the resolution to screenResolution
. Increase this resolution value.
PS: The code to render a PDF page to image has been refactored in 2.0.0-SNAPSHOT. Instead of
BufferedImage image = page.convertToImage();
you now do
BufferedImage image = RenderUtil.convertToImage(page);
I assume this has been done to remove direct AWT references from the core classes because AWT is not available on e.g. Android.
PS: The SNAPSHOT I used last year in this answer merely was a snapshot subject to changes. The 2.0.0 release is still under development, many things have changed. Especially there is no RenderUtil
class anymore. Instead one currently has to use the PDFRenderer
in the org.apache.pdfbox.rendering
package...