pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cheffers, Paul" <Paul.Cheff...@humanservices.gov.au>
Subject unable to apply permissions to a pdf without permissions [SEC=UNOFFICIAL]
Date Mon, 05 May 2014 03:36:32 GMT
I'm unable to apply permissions to a pdf that has no security.

The code I am using is in other posts (see below).  I get an exception while using the protect
member

            try {
                document.protect(spp);
            } catch (BadSecurityHandlerException e) {
                e.printStackTrace();

I call the below routine with these arguments:

creatingEncriptation("d:\\Data\\pdfstuff\\bitcoin.pdf", "d:\\Data\\pdfstuff\\bitcoin2.pdf",
                    "dogs");

   private static void creatingEncriptation(String Infile, String Outfile,
            String ownerPassword) {

        AccessPermission ap = new AccessPermission();
        String userPassword = "";
     //   ownerPassword = "XXXXXX";

        int keyLength = 40;
        PDDocument document = null;
        ap.setCanAssembleDocument(true);
        ap.setCanExtractContent(true);
        ap.setCanExtractForAccessibility(true);
        ap.setCanFillInForm(true);
        ap.setCanModify(true);
        ap.setCanModifyAnnotations(true);
        ap.setCanPrint(true);
        ap.setCanPrintDegraded(true);

        if (Outfile == null) {
            Outfile = Infile;
        }
        try {


            document = PDDocument.load(Infile);

       //     document.setAllSecurityToBeRemoved(true);

        } catch (IOException e) {
            e.printStackTrace();

        }

        if (!document.isEncrypted()) {
            StandardProtectionPolicy spp = new StandardProtectionPolicy(
                    ownerPassword, userPassword, ap);
            spp.setEncryptionKeyLength(keyLength);
            try {
                document.protect(spp);
            } catch (BadSecurityHandlerException e) {
                e.printStackTrace();

            }
            try {
                document.save(Outfile);
            } catch (COSVisitorException e) {
                e.printStackTrace();

            } catch (IOException e) {
                e.printStackTrace();

            }
        } else {

            return;
        }

        try {
            document.close();
            document=null;
        } catch (IOException e) {

            e.printStackTrace();
        }


    }

Any ideas would be appreciated.

Paul

********************************************************************** IMPORTANT: This e-mail
is for the use of the intended recipient only and may contain information that is confidential,
commercially valuable and/or subject to legal or parliamentary privilege. If you are not the
intended recipient you are notified that any review, re-transmission, disclosure, dissemination
or other use of, or taking of any action in reliance upon, this information is prohibited
and may result in severe penalties. If you have received this e-mail in error please notify
the sender immediately and delete all electronic and hard copies of this transmission together
with any attachments. Please consider the environment before printing this e-mail **********************************************************************


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message