[ 
https://issues.apache.org/jira/browse/PDFBOX-2292?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

v gangolli updated PDFBOX-2292:
-------------------------------

    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();
                        }
                                        
        }
                        


  was:
I have attached 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();
                        }
                                        
        }
                        



> Saving of decrypted version of password protected document gives an error
> -------------------------------------------------------------------------
>
>                 Key: PDFBOX-2292
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2292
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.0
>         Environment: JDK 1.6
>            Reporter: v gangolli
>
> 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();
>                       }
>                                       
>       }
>                       



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to