in reply to Protect PDF from printing

http://search.cpan.org/tools/CAM-PDF -> http://search.cpan.org/grep?cpanid=CDOLAN&release=CAM-PDF-1.60&string=print&i=1&n=1&C=0

bin/pdfinfo.pl 31: print "CAM::PDF v$CAM::PDF::VERSION\n"; 68: print "File: $file\n"; 69: print "File Size: $size bytes\n"; 70: print "Pages: $pages\n"; 96: printf "%-13s %s\n", $key.q{:}, $val; 99: print 'Page Size: '.($pagesize[0] ? "$pagesize[0] x $pagesize +[1] pts" : 'variable')."\n"; 100: print 'Optimized: '.($doc->isLinearized()?'yes':'no')."\n"; 101: print "PDF version: $pdfversion\n"; 102: print "Security\n"; 105: print " Passwd: '$prefs[0]', '$prefs[1]'\n"; 109: print " Passwd: none\n"; 111: print ' Print: '.($prefs[2]?'yes':'no')."\n"; 112: print ' Modify: '.($prefs[3]?'yes':'no')."\n"; 113: print ' Copy: '.($prefs[4]?'yes':'no')."\n"; 114: print ' Add: '.($prefs[5]?'yes':'no')."\n"; 117: print "---------------------------------\n"; 128:pdfinfo.pl - Print information about PDF file(s) 135: -v --verbose print diagnostic messages

its  my @prefs = $doc->getPrefs();

so http://search.cpan.org/grep?cpanid=CDOLAN&release=CAM-PDF-1.60&string=prefs&i=1&n=1&C=0

2944:=item $doc->setPrefs($ownerpass, $userpass, $print?, $modify?, $copy?, $add?)

So there you have it, use https://metacpan.org/pod/CAM::PDF#doc-setPrefs-ownerpass-userpass-print-modify-copy-add

Replies are listed 'Best First'.
Re^2: Protect PDF from printing
by Anonymous Monk on Sep 26, 2015 at 00:31 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
Re^2: Protect PDF from printing
by gachunt (Initiate) on Sep 26, 2015 at 23:21 UTC

    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.