Search code examples
javapdfpdfboxandroid-bitmap

Incorrect shape points in PdfBox renderImageWithDpi


Using Android PDFBox API I am extracting page thumbnails to show on a PDF page picker component.

public Bitmap getPdfPageThumb (int pageIndex) {
    try {
        PDRectangle pageBox = pdfDoc.getPage(pageIndex).getBBox();
        float targetDpi = Math.max(
                targetWidth * 72f / pageBox.getWidth(),
                targetHeight * 72f / pageBox.getHeight());
        return renderer.renderImageWithDPI(pageIndex, targetDpi);
    }
    catch (Exception e) {
        return null;
    }
}

The resulting PDFs have ugly artefacts which look like misplaces shape points - see below. Is there a way to avoid this?

enter image description here

Thanks


Solution

  • As mentioned in the comment this is a PDFBox bug in Android, solution is to use the PdfiumAndroid library which renders much nicer pages.