Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Protect PDF from printing

by gachunt (Initiate)
on Sep 26, 2015 at 00:00 UTC ( [id://1143050]=perlquestion: print w/replies, xml ) Need Help??

gachunt has asked for the wisdom of the Perl Monks concerning the following question:

... Concerns about PDF protection aside, that it's not very good, easily broken, etc ... I know it's not great, but I still have to do it.

I'm writing a script that watches a folder where documents are scanned into PDF format.

The script creates a thumbnail of the scanned PDF's first page using Imagemagick.

Next, it needs to protect the document from printing, but still allow opening WITHOUT being prompted for a password. That's where I'm stuck.

Using CAM::PDF, I have:

$pdf->setPrefs('password','password');

But, that is protecting the PDF from opening as well.

When I try to use only one argument (and variations of) such as:

$pdf->setPrefs('password');<BR> $pdf->setPrefs('password','');<BR> $pdf->setPrefs('','password');

Then the PDF still prompts for a password when opening, or opens with blank white pages and the scanned text is gone.

Any suggestions? or alternates to CAM::PDF?

Using ActiveState, Windows 2012 Server

Replies are listed 'Best First'.
Re: Protect PDF from printing
by Anonymous Monk on Sep 26, 2015 at 00:28 UTC
      $ rewritepdf --prefs 0 0 0 0 goner-labels01.pdf goner-labels01000.pdf $ pdfinfo goner-labels01.pdf goner-labels01000.pdf File: goner-labels01.pdf File Size: 2069 bytes Pages: 1 Author: PDF Labelmaker Producer: PDF::Create version 1.10 Title: My Labels Type: Info Page Size: variable Optimized: no PDF version: 1.2 Security Passwd: none Print: yes Modify: yes Copy: yes Add: yes --------------------------------- File: goner-labels01000.pdf File Size: 2325 bytes Pages: 1 Author: PDF Labelmaker Producer: PDF::Create version 1.10 Title: My Labels Type: Info Page Size: variable Optimized: no PDF version: 1.2 Security Passwd: none Print: no Modify: no Copy: no Add: no

      No luck - Here's what happens

      This attempt protects from printing, but there's no password assigned, so printing can easily be turned on:

      rewritepdf.pl --prefs 0 0 0 0 file.pdf file1.pdf

      This attempt password protects printing -- but also requires a password to open the pdf:

      rewritepdf.pl -p password password --prefs 0 0 0 0 file.pdf file1.pdf

      This attempt password protects printing -- but the pdf only displays blank pages -- it erases the content:

      rewritepdf.pl -p password --prefs 0 0 0 0 file.pdf file1.pdf

      I've tried different PDF documents/pdf versions, but all documents end up blank

        I went with using ghostscript instead

        For those who want to do something similar, execute this from your script:

        "C:\Program Files\gs\gs9.16\bin\gswin64c" -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOwnerPassword=password -dPermissions=-64 -sOutputFile=\BICRwatch\protected.pdf \BICRwatch\file.pdf

        Here's the command explained:

        -dNOPAUSE stops ghostscript from asking questions during the process

        -dBATCH quits ghostscript after protection is applied

        dPermissions=-64 sets permissions to not allow any printing, editing, copying

        The rest should be self-explantory to edit.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1143050]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-16 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found