Thank you, Tilman.
Ha! Sorry, I was just giving the minimal code. The actual code was:
public static void main(String[] args) throws Exception {
File f = new File("C:/temp/testPDF_protected.pdf");
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDFont font = HELVETICA_BOLD;
PDPageContentStream contentStream = new PDPageContentStream(document,
page);
contentStream.beginText();
contentStream.setFont( font, 12 );
contentStream.moveTextPositionByAmount( 100, 700 );
contentStream.drawString( "Hello World" );
contentStream.endText();
contentStream.close();
AccessPermission ap = new AccessPermission();
ap.setReadOnly();
StandardProtectionPolicy spp = new StandardProtectionPolicy("owner",
"user", ap);
document.protect(spp);
document.save(f);
document.close();
}
The error is "There was a problem reading this document (57)". I can move the
AccessPermissions line before and after creating the page, and I get the same
error. If I don't create/add a page, I get the same error.
If I comment out the AccessPermission -> protect lines, Adobe Reader is able to
open the file.
I generated the document on Windows with PDFBox 2.0 SNAPSHOT and Java 1.8.0_31.
For the record, I'm still sure I'm doing something wrong! :)
Best,
Tim
-----Original Message-----
From: Tilman Hausherr [mailto:[email protected]]
Sent: Friday, February 20, 2015 5:25 PM
To: [email protected]
Subject: Re: setting permissions on a new document
Hi Tim,
add a page to the document.
PDPage page = new PDPage();
document.addPage(page);
Tilman
Am 20.02.2015 um 22:12 schrieb Allison, Timothy B.:
> All,
> I'm trying to create a test doc for permission checking over on Tika,
> when I try the most basic program:
>
> public static void main(String[] args) throws Exception {
> File f = new File("C:/temp/testPDF_protected.pdf");
> PDDocument document = new PDDocument();
> AccessPermission ap = new AccessPermission();
> ap.setReadOnly();
> StandardProtectionPolicy spp = new StandardProtectionPolicy("owner",
> "user", ap);
> document.protect(spp);
> document.save(f);
> document.close();
> }
>
> AdobeReader isn't able to open the file. I'm sure that this is user
> error...what am I doing wrong?
>
> Thank you.
>
> Best,
>
> Tim
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]