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

ClassCastException writing text to a page

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.0
    • Component/s: Writing
    • Labels:
      None
    • Environment:
      Windows x86_64, jdk1.6.0u31

      Description

      I switched from 1.7.1 to 1.8.0-SNAPSHOT. Following code did not work any longer:

      @Test
      public void testGenerateNewDocument() throws IOException, COSVisitorException {
      PDDocument doc = null;
      try

      { doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); PDFont font = PDType1Font.HELVETICA_BOLD; PDJpeg image = new PDJpeg(doc, getLogoInputStream() ); PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true); contentStream.beginText(); contentStream.setFont(font, 12); contentStream.moveTextPositionByAmount(100, 700); contentStream.drawString("Hello World!"); contentStream.endText(); contentStream.drawImage(image, 20, 20); contentStream.close(); doc.save( getWorkDirectory() + File.separator + "pdfbox-testGenerateNewDocument.pdf" ); }

      finally {
      if (doc != null)

      { doc.close(); }

      }
      }

      java.lang.ClassCastException: org.apache.pdfbox.cos.COSName cannot be cast to java.lang.String
      at org.apache.pdfbox.pdmodel.common.COSArrayList.convertStringListToCOSNameCOSArray(COSArrayList.java:364)
      at org.apache.pdfbox.pdmodel.common.PDStream.setFilters(PDStream.java:300)
      at org.apache.pdfbox.pdmodel.edit.PDPageContentStream.<init>(PDPageContentStream.java:258)
      at org.apache.pdfbox.pdmodel.edit.PDPageContentStream.<init>(PDPageContentStream.java:159)
      at tests.evaluation.pdfbox.PdfboxEvaluationTest.testGenerateNewDocument(PdfboxEvaluationTest.java:47)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
      at org.testng.internal.Invoker.invokeMethod(Invoker.java:701)
      at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:893)
      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1218)
      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
      at org.testng.TestRunner.privateRun(TestRunner.java:768)
      at org.testng.TestRunner.run(TestRunner.java:617)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
      at org.testng.SuiteRunner.run(SuiteRunner.java:240)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
      at org.testng.TestNG.run(TestNG.java:1022)
      at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)

        Attachments

          Activity

            People

            • Assignee:
              lehmi Andreas Lehmkühler
              Reporter:
              jenskreidler Thomas Jodes
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: