PDFBox uses Java AWT RenderingHints before converting a PDF page to a BufferedImage
object. Of the eleven options RenderingHints
offers, PDFBox uses only three, as follows, and can be checked at PDFBox’s PDFRenderer
class.
KEY_INTERPOLATION
The INTERPOLATION hint controls how image pixels are filtered or resampled during an image rendering operation.
PDBox uses the VALUE_INTERPOLATION_NEAREST_NEIGHBOR
, the color sample of the nearest neighboring integer coordinate sample in the image is used.
KEY_RENDERING
The RENDERING hint is a general hint that provides a high level recommendation as to whether to bias algorithm choices more for speed or quality when evaluating tradeoffs.
PDFBox uses the VALUE_RENDER_QUALITY
, rendering algorithms are chosen with a preference for output quality.
KEY_ANTIALIASING
The ANTIALIASING hint controls whether or not the geometry rendering methods of a Graphics2D object will attempt to reduce aliasing artifacts along the edges of shapes. A typical antialiasing algorithm works by blending the existing colors of the pixels along the boundary of a shape with the requested fill paint according to the estimated partial pixel coverage of the shape.
PDFBox uses the VALUE_ANTIALIAS_OFF
, rendering is done without antialiasing.
The other RenderingHints
keys available are:
KEY_DITHERING
KEY_TEXT_ANTIALIASING
KEY_TEXT_LCD_CONTRAST
KEY_FRACTIONALMETRICS
KEY_ALPHA_INTERPOLATION
KEY_COLOR_RENDERING
KEY_STROKE_CONTROL
KEY_RESOLUTION_VARIANT
If you want to modify the default PDFBox values or use other RenderingHints keys, you should create a new RenderingHints
object and set it into PDFRenderer with its setRenderingHints
method.
RenderingHints r = new RenderingHints(null);
r.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
r.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
r.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
PDFRenderer pdfRenderer = new PDFRenderer(document);
pdfRenderer.setRenderingHints(r);