CMapAwareDocumentFont extends DocumentFont { @Override public int getWidth(int char1) { if (char1 == ' ') return spaceWidth != 0 ? spaceWidth : defaultWidth; return super.getWidth(char1); } CMapAwareDocumentFont(PdfDictionary font);  CMapAwareDocumentFont(PRIndirectReference refFont); @Override int getWidth(int char1); String decode(byte[] cidbytes, final int offset, final int len); String encode(byte[] bytes, int offset, int len);  }
@Test public void testWidths() throws Exception{ final PdfReader pdfReader = TestResourceUtils.getResourceAsPdfReader(this, "fontwithwidthissue.pdf"); try { PdfDictionary fontsDic = pdfReader.getPageN(1).getAsDict(PdfName.RESOURCES).getAsDict(PdfName.FONT); PRIndirectReference fontDicIndirect = (PRIndirectReference)fontsDic.get(new PdfName("F1")); CMapAwareDocumentFont f = new CMapAwareDocumentFont(fontDicIndirect); Assert.assertTrue("Width should not be 0", f.getWidth('h') != 0); } finally { pdfReader.close(); } }