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

Hello World using a TrueType font ArrayIndexOutOfBoundsException


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.2
    • Fix Version/s: 1.8.3, 2.0.0
    • Component/s: None
    • Labels:
    • Environment:
      Windows 7 SP1 32-bit, pdfbox 1.8.2., NetBeans IDE 6.9.1


      The small example “Hello World using a TrueType font” on the pdfbox website does not work when selecting the Windows font “cour.ttf” (Courier New). It works with the non-fixed width fonts that I have tried (Arial, Albertus, Bookman Old Style, Garamond, Palatino, Segoe UI) and it works with Lucida Console, a fixed width font, but not Courier New.

      This is the error:

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
      at org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadDescriptorDictionary(PDTrueTypeFont.java:418)
      at org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:201)
      at org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:177)
      at org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:158)
      at org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:145)
      at org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:132)
      at pdfbox_ttf_test.Main.main(Main.java:31)

      To me this is the same error as PDFBOX-1335, except maybe it is still not fixed for all fonts.

      I am using Windows 7 SP1 32-bit, pdfbox 1.8.2., NetBeans IDE 6.9.1

      This is my source:
      ----------------------- <snip> -------------------------

      • To change this template, choose Tools | Templates
      • and open the template in the editor.

      package pdfbox_ttf_test;
      import org.apache.pdfbox.pdmodel.PDDocument;
      import org.apache.pdfbox.pdmodel.PDPage;
      import org.apache.pdfbox.pdmodel.font.PDFont;
      import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
      import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
      import org.apache.pdfbox.exceptions.COSVisitorException;
      import java.io.IOException;


      • @author Duncan
        public class Main {


      • @param args the command line arguments
        public static void main(String[] args) throws IOException, COSVisitorException { // TODO code application logic here PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage( page ); // Create a new font object by loading a TrueType font into the document PDFont font = PDTrueTypeFont.loadTTF(document, "C:\\Windows\\Fonts\\cour.ttf"); // Start a new content stream which will "hold" the to be created content PDPageContentStream contentStream = new PDPageContentStream(document, page); // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World" contentStream.beginText(); contentStream.setFont( font, 12 ); contentStream.moveTextPositionByAmount( 100, 700 ); contentStream.drawString( "Hello World" ); contentStream.endText(); // Make sure that the content stream is closed: contentStream.close(); // Save the results and ensure that the document is properly closed: document.save( "Hello World.pdf"); document.close(); }

      -------------------------- <end snip> -----------------------------




            • Assignee:
              lehmi Andreas Lehmkühler
              duncanhorrocks Duncan Horrocks
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: