0

When PDF(fillable) is converted to Jpeg using Pdfbox.The tick in checkbox is converted to a box character

WARN [org.apache.pdfbox.rendering.Type1Glyph2D] No glyph for code 52 (a20) in font ZapfDingbats

public static void main(String[] args) throws Exception{

    try (final PDDocument document = PDDocument.load(new File("C:\\Users\\priyadarshini.s\\Downloads\\ADWE3244_Merge(1).pdf"))){

        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        InputStream is = classloader.getResourceAsStream("zapfdingbats.ttf");

        PDFRenderer pdfRenderer = new PDFRenderer(document);
        PDFont font = PDType0Font.load(document,is); //PDTrueTypeFont.loadTTF(document, new File( "c:/arial.ttf" ));
        //font.s sesetWidths(PDType1Font.HELVETICA.getWidths());


        for (int page = 0; page < document.getNumberOfPages(); ++page)
        {

            BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);

            String fileName = OUTPUT_DIR + "image-" + page + ".jpg";
            ImageIOUtil.writeImage(bim, fileName, 300);
        }


        document.close();


    } catch (IOException e){
        System.err.println("Exception while trying to create pdf document - " + e);
    }
}

How do i set the font to the PDF to image code ?

PDS
  • 54
  • 12

1 Answers1

1

The problem may related with fonts. (Zapf Dingbats and/or MS Gothic may be missing)

Can you try to install missing fonts in a directory "./fonts" or "/usr/share/fonts" for Linux,

"/Windows/Fonts" for Windows

  • WARN [org.apache.pdfbox.rendering.Type1Glyph2D] No glyph for code 52 (a20) in font ZapfDingbats 2018-11-13 20:01:01,280 WARN [org.apache.pdfbox.pdmodel.font.PDType1Font] Using fallback font LiberationSans for ZapfDingbats where do i install in aix server ? – PDS Nov 14 '18 at 08:13
  • Link https://issues.apache.org/jira/browse/PDFBOX-1296, Link https://issues.apache.org/jira/browse/PDFBOX-490 – yusuf hayırsever Nov 14 '18 at 09:22
  • You do not have to set the font in the code. You need to install it on your system. If you don't know how to install the font (most likely you just copy it there), ask your admin, or create a directory `.fonts` in your home directory and copy the font there. – Tilman Hausherr Nov 14 '18 at 09:37
  • But is there a way that we could do in code itself ? – PDS Nov 15 '18 at 05:29
  • No, because fontbox checks what is in the file system at predefined places. – Tilman Hausherr Nov 15 '18 at 08:11