pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Changing "Content Copying" permission
Date Wed, 20 Jul 2016 21:01:55 GMT
Am 20.07.2016 um 21:37 schrieb Keith R Wood:
> I am trying to change the attributes "Content Copying" and "Content Copying for Accessibility"
on a PDF received from a third party.
>
> I'm not sure if this is possible, but am unable to find anything that says it is not
allowed.
>
> Here is what I can tell you about the PDF.
>
> Both "Content Copying and Content Copying for Accessibility are currently set to "Allowed".
>
> The PDF is NOT read only.
>
> The "Owner Permission" is set to false (which I am thinking may be key).
>
> I set both attributes to false, I then save the document and close the document.
>
> The time stamp of the document gets updated, but the attributes remain unchanged.
>
> Below is sample code and output:
>
> PDDocument doc = PDDocument.load(pdfFile);
>                    canExtract = doc.getCurrentAccessPermission().canExtractContent();
>                    canExtractFA = doc.getCurrentAccessPermission().canExtractForAccessibility();
>                    canExtract_owner = doc.getCurrentAccessPermission().getOwnerAccessPermission().canExtractContent();
>                    canExtractFA_owner = doc.getCurrentAccessPermission().getOwnerAccessPermission().canExtractForAccessibility();
>                    readOnly = doc.getCurrentAccessPermission().isReadOnly();
> ownerPermission = doc.getCurrentAccessPermission().isOwnerPermission();
>
>
>                    doc.getCurrentAccessPermission().setCanExtractForAccessibility(false);
>                    doc.getCurrentAccessPermission().setCanExtractContent(false);
> doc.getCurrentAccessPermission().getOwnerAccessPermission().setCanExtractContent(false);
>                    doc.getCurrentAccessPermission().getOwnerAccessPermission().setCanExtractForAccessibility(false);

if ap is your access permission, then do this before saving:

                         StandardProtectionPolicy spp =
                             new 
StandardProtectionPolicy("secretpassword", "", ap);
                         spp.setEncryptionKeyLength(256); // not really 
needed...
                         document.protect(spp);

You can also leave the default key length... PDF security for 
permissions only (i.e. empty user psw) is not real security anyway.

Tilman



>
>                    doc.save(pdfFile);
>                    doc.close();
>
>
>
> canExtract-true, canExtractFA-
>
> Thank you
> _____________________________________________________
> Keith Wood | Applications Program Lead | United Guaranty Corporation
> 300 N. Greene St. | Greensboro, NC 27401
>
> Phone: 336.334.8547
> woodkr@ugcorp.com<mailto:pamela.davidson@ugcorp.com>
> www.ugcorp.com<http://www.ugcorp.com/>
> ____________________________
>
> ----------------------------------------------------------------------
> --------------------------------------------------------------------------
> United Guaranty is a marketing term for United Guaranty Corporation and its subsidiaries.
This communication from United Guaranty Corporation or its subsidiary is directed to and is
for the use of the individual or entity to which it is addressed. It may contain information
that is confidential and exempt from disclosure under applicable law. If you are not the intended
recipient, you are hereby notified that any distribution, dissemination, or copy of this communication
is strictly prohibited. If you have received this communication in error, please contact the
sender immediately, and then delete or destroy the material in its entirety. United Guaranty
Corporation and its subsidiaries
>   230 North Elm Street
>   Greensboro, NC 27401
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message