Just use a command line tool like pdftk or the PDFbox java library to postprocess the pdf.
Here's an example to encrypt the file
1.pdf using pdftk, allowing the user to print the file (from the pdftk Server examples):
pdftk 1.pdf output 1.128.pdf owner_pw foo user_pw baz allow printing
The Apache PDFBox library comes with some command line tools. Here's an example how to encrypt a file using PDFBox on the command line:
java -jar pdfbox-app-x.y.z.jar Encrypt [OPTIONS] <password> <inputfile>
where OPTIONS may be:
-O The owner password to the PDF, ignored if -certFile is specified.
-U The user password to the PDF, ignored if -certFile is specified.
-certFile Path to X.509 cert file.
-canAssemble true Set the assemble permission.
-canExtractContent true Set the extraction permission.
-canExtractForAccessibility true Set the extraction permission.
-canFillInForm true Set the fill in form permission.
-canModify true Set the modify permission.
-canModifyAnnotations true Set the modify annots permission.
-canPrint true Set the print permission.
-canPrintDegraded true Set the print degraded permission.
-keyLength 40 The number of bits for the encryption key.
inputfile The PDF file to encrypt.
outputfile The file to save the encrypted document to. If left blank then it will be the same as the input file.
NB: a key lenght of 40 bits would IMHO be too short - using a longer key is recommendable.