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

Saving of decrypted version of password protected document gives an error

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.6, 1.8.7, 2.0.0
    • Fix Version/s: 1.8.7, 2.0.0
    • Component/s: None
    • Labels:
    • Environment:
      JDK 1.6

      Description

      For a sample owner-password-protected pdf that I can decrypt and save to another file in Pdfbox 1.8.5, however, in the 2.0.0 build created using the repository checked out of svn, I get an exception while saving.
      java.io.IOException: Cannot save a document which has been closed
      at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1229)
      at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1215)
      at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1203)

      The code snippet is as follows-

      pd = PDDocument.load(is);
      if (pd.isEncrypted()) {
        try {
      	  pd.decrypt("");
      	  pd.setAllSecurityToBeRemoved(true);
                fNameStr = fName.substring(0, fName.lastIndexOf('.'))
      							+ "_new.pdf";
                System.out.println(pd.getCurrentAccessPermission()
      	   pd.save(fNameStr);  // java.IOException at this line
      	} catch (Exception e) {
      		e.printStackTrace();
      	} finally {
                             pd.close();
      			if (is != null) {
      			  is.close();
      			}
      					
      	}
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                tilman Tilman Hausherr
                Reporter:
                apacheusr v gangolli
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: