pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roberto Nibali <rnib...@gmail.com>
Subject Re: Setting PDF Document Restrictions and Security Limitations
Date Mon, 27 Jul 2015 16:14:32 GMT
Hi Tilman

On Mon, Jul 27, 2015 at 5:36 PM, Tilman Hausherr <THausherr@t-online.de>
wrote:

> Am 27.07.2015 um 14:23 schrieb Roberto Nibali:
>
>> Hi
>>
>> I'm trying to replicate the document security settings using PDFBox and
>> can't seem to get it working at all. This is the code I use:
>>
>> private static PDDocument srcDoc;
>> private static PDDocument tplDoc;
>>
>> @Test
>> public static void SimpleTest() throws IOException {
>>      String ownerPassword = "12345";
>>      srcDoc = PDDocument.load(new File("./ccalt.pdf"), ownerPassword);
>>      tplDoc = PDDocument.load(new File("./cctemp.pdf"), ownerPassword);
>>
>
> This is because when opening a document with the owner password, you get
> all permissions. To get restricted permissions, open the document with the
> user password. (usually empty)
>
> Try it... (I haven't tested your files)
>
> Tilman
>
>
And indeed, this worked. The code looks like this now:

public static void SimpleTest() throws IOException {
    srcDoc = PDDocument.load(new File(srcDocName), "");
    tplDoc = PDDocument.load(new File(tplDocName), "");
    tplDoc.setAllSecurityToBeRemoved(true);
    applyDocPermissions(ownerPassword, "");
    srcDoc.close();
    tplDoc.getDocumentCatalog().getAcroForm().setNeedAppearances(true);
    tplDoc.save(outDocName);
    tplDoc.close();
}

Thanks. I will now have a look at Maruan's proposal on top of this.

Cheers
Roberto

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