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

PDFMergerUtility seems to leave source file open

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.12
    • Fix Version/s: 2.0.13, 3.0.0 PDFBox
    • Component/s: Utilities
    • Labels:
      None

      Description

      Hi,

       

      Having migrated from 2.0.11 to 2.0.12. I am facing the following issue:

       

      When merging multiple pdf files into one, I can no longer delete the source files.

       

      Here is a sample code (worked in 2.0.11):

       

      public void mergePDFFiles(List<File> inFiles, File outFile)
          throws InvalidPasswordException, IOException
          {
              try (OutputStream out = new BufferedOutputStream(new FileOutputStream(outFile))) {
                  PDFMergerUtility merger = new PDFMergerUtility();
                  merger.setDestinationStream(out);
                  for(File toMerge : inFiles) {
                      merger.addSource(toMerge);
                  }
                  merger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
              }
          
              for(File f : inFiles) {
                  // IOException thrown
                  FileUtils.forceDelete(f);
              }
          }
      

      Has something changed or do I do something wrong ?

       

      Br,

       

      David Schreck

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                tilman Tilman Hausherr
                Reporter:
                david.schreck David Schreck
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: