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

java.lang.ExceptionInInitializerError in PDFBox

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.0.0
    • None
    • None
    • Windows 7 64 bit
      PDFBox 2.0.0-RC3

    Description

      The code below only works in the first time when .pdfbox.cache file does not exist. After the file is created the error below happens. If I delete the .pdfbox.cache file it start working again. So there is an issue with this file probably

      import java.io.IOException;
      
      import org.apache.pdfbox.pdmodel.PDDocument;
      import org.apache.pdfbox.pdmodel.PDPage;
      import org.apache.pdfbox.pdmodel.PDPageContentStream;
      import org.apache.pdfbox.pdmodel.font.PDFont;
      import org.apache.pdfbox.pdmodel.font.PDType1Font;
      
      public class TestPDF {
      
          private void createPDF() throws IOException {
      
              // Create a document and add a page to it
              PDDocument document = new PDDocument();
              PDPage page = new PDPage();
              document.addPage(page);
      
              // Create a new font object selecting one of the PDF base fonts
              PDFont font = PDType1Font.HELVETICA_BOLD;
      
              // 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();
      
          }
      
          public static void main(String[] args) throws Exception {
      
              TestPDF t = new TestPDF();
              t.createPDF();
          }
      
      }
      

      And I don't know I'm getting:

      Exception in thread "main" java.lang.ExceptionInInitializerError
          at org.apache.pdfbox.pdmodel.font.FontMapperImpl.getProvider(FontMapperImpl.java:151)
          at org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFont(FontMapperImpl.java:415)
          at org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFontBoxFont(FontMapperImpl.java:378)
          at org.apache.pdfbox.pdmodel.font.FontMapperImpl.getFontBoxFont(FontMapperImpl.java:352)
          at org.apache.pdfbox.pdmodel.font.PDType1Font.<init>(PDType1Font.java:114)
          at org.apache.pdfbox.pdmodel.font.PDType1Font.<clinit>(PDType1Font.java:76)
          at br.jus.trt4.TestPDF.createPDF(TestPDF.java:21)
          at br.jus.trt4.TestPDF.main(TestPDF.java:45)
      Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
          at org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.loadDiskCache(FileSystemFontProvider.java:387)
          at org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.<init>(FileSystemFontProvider.java:218)
          at org.apache.pdfbox.pdmodel.font.FontMapperImpl$DefaultFontProvider.<clinit>(FontMapperImpl.java:132)
          ... 8 more
      

      Attachments

        1. .pdfbox.cache
          45 kB
          Luiz F Estivalet

        Activity

          People

            tilman Tilman Hausherr
            howlerbr Luiz F Estivalet
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: