You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Allison, Timothy B." <ta...@mitre.org> on 2015/02/20 22:12:10 UTC

setting permissions on a new document

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

RE: setting permissions on a new document

Posted by "Allison, Timothy B." <ta...@mitre.org>.
Alright.   After the exorcism, all is working.  I have no idea why it wasn't working before.  Thank you, Tilman!

-----Original Message-----
From: Allison, Timothy B. [mailto:tallison@mitre.org] 
Sent: Friday, February 20, 2015 6:42 PM
To: users@pdfbox.apache.org
Subject: RE: setting permissions on a new document

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:THausherr@t-online.de] 
Sent: Friday, February 20, 2015 5:25 PM
To: users@pdfbox.apache.org
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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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


RE: setting permissions on a new document

Posted by "Allison, Timothy B." <ta...@mitre.org>.
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:THausherr@t-online.de] 
Sent: Friday, February 20, 2015 5:25 PM
To: users@pdfbox.apache.org
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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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


Re: setting permissions on a new document

Posted by Tilman Hausherr <TH...@t-online.de>.
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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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