Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-922

True type PDFont subclass only supports WinAnsiEncoding (hardcoded!)

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.3.1
    • Fix Version/s: 2.0.0
    • Component/s: Writing
    • Labels:
      None
    • Environment:
      JDK 1.6 / OS irrelevant, tried against 1.3.1 and 1.2.0

      Description

      PDFBox cannot embed Identity-H or Identity-V type TTF fonts in the PDF it creates, making it impossible to create PDFs in any language apart from English and ones supported in WinAnsiEncoding. This behaviour is caused because method PDTrueTypeFont.loadTTF has hardcoded WinAnsiEncoding inside, and there is no Identity-H or Identity-V Encoding classes provided (to set afterwards via PDFont.setFont() )

      This excludes the following languages plus many others:

      • Greek
      • Bulgarian
      • Swedish
      • Baltic languages
      • Malteze

      The PDF created contains garbled characters and/or squares.

      Simple test case:

                      PDDocument doc = null;
      		try {
      			doc = new PDDocument();
      			PDPage page = new PDPage();
      			doc.addPage(page);
      			// extract fonts for fields
      			byte[] arialNorm = extractFont("arial.ttf");
      			//byte[] arialBold = extractFont("arialbd.ttf"); 
      			//PDFont font = PDType1Font.HELVETICA;
      			PDFont font = PDTrueTypeFont.loadTTF(doc, new ByteArrayInputStream(arialNorm));
      			
      			PDPageContentStream contentStream = new PDPageContentStream(doc, page);
      			contentStream.beginText();
      			contentStream.setFont(font, 12);
      			contentStream.moveTextPositionByAmount(100, 700);
      			contentStream.drawString("Hello world from PDFBox ελληνικά"); // text here may appear garbled; insert any text in Greek or Bulgarian or Malteze
      			contentStream.endText();
      			contentStream.close();
      			doc.save("pdfbox.pdf");
      			System.out.println(" created!");
      		} catch (Exception ioe) {
      			ioe.printStackTrace();
      		} finally {
      			if (doc != null) {
      				try { doc.close(); } catch (Exception e) {}
      			}
      		}
      

        Attachments

        1. pdfbox-unicode.diff
          11 kB
          Antti Lankila
        2. pdfbox-unicode2.diff
          14 kB
          Antti Lankila

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                thagg1975 Thanos Agelatos
              • Votes:
                16 Vote for this issue
                Watchers:
                24 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: