PDFBox
  1. PDFBox
  2. PDFBOX-914

Using TextToPDF to create a PDF from the empty string produces unreadble PDF file (patch included)

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.1
    • Fix Version/s: 1.4.0
    • Component/s: Utilities
    • Labels:
      None
    • Environment:
      All

      Description

      If you create a PDF document from org.apache.pdfbox.TextToPDF like so:
      TextToPDF pdfCreator = new TextToPDF();
      PDDocument pdfDoc = pdfCreator.createPDFFromText(new StringReader("")); // Note the empty String
      then it does produce a PDF file. But the file cannot be opened as it contains no pages.
      Adobe Reader (I have 9.4.1), and Mac OSX's Preview/Quicklook cannot open the document.

      I have attached (or will do in a minute) a patch that includes a test case that reproduces the problem (no PDPages in a PDF with no text).
      And I've patched TextToPDF so that it inserts a single empty page for an empty string input.

      1. PDFBOX-914.patch
        6 kB
        Neil McErlean

        Activity

        Hide
        Neil McErlean added a comment -

        Here's the patch I referred to.
        New testcase, and fix to TextToPDF class.

        Show
        Neil McErlean added a comment - Here's the patch I referred to. New testcase, and fix to TextToPDF class.
        Hide
        Neil McErlean added a comment -

        Just some context: this may seem like a trivial case. But we have many document transformation scenarios that use PDFBox (or could do) and if a "broken" PDF is produced during a chain, it breaks the whole transformation chain.

        It would be really helpful to us if this was included.

        Thank you!

        Show
        Neil McErlean added a comment - Just some context: this may seem like a trivial case. But we have many document transformation scenarios that use PDFBox (or could do) and if a "broken" PDF is produced during a chain, it breaks the whole transformation chain. It would be really helpful to us if this was included. Thank you!
        Hide
        Andreas Lehmkühler added a comment -

        I added the improvement in 1044686 as proposed by Neil McErlean.

        Thanks for the contribution

        Show
        Andreas Lehmkühler added a comment - I added the improvement in 1044686 as proposed by Neil McErlean. Thanks for the contribution

          People

          • Assignee:
            Andreas Lehmkühler
            Reporter:
            Neil McErlean
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development