Protecting PDFs


Is there a way to protect your PDF in Rhino’s own PDF creator?
I don’t want to send PDF’s on my work to customer knowing that they can share it with competitors.


Is there a specific PDF feature that does this? I’m not exactly sure what you mean by ‘protecting’. Something may be possible, I just need to understand the request a little more.

As always, sorry for the bad questioning,

For example PDFcreator has the possibility to pasword protect the editing of PDF files.
A password protected PDF isn’t possible to open in rhino.

I could paste a snapshot of the options on PDFcreator if you want


Hi @stevebaer, PDF supports password protection for opening the pdf and for content encryption. The latter allows to set authoring rules for viewing, editing and printing. It would be great to control this when the PDF is created with Rhino. Otherwise, it can be done when the document is opened and saved again with Acrobat Pro.


I will have to change our SDK a little bit to make this automatic and have issued a feature request for this in a future Rhino

For now, you can password protect your PDFs with the following python script

import clr
import Xfinium
import rhinoscriptsyntax as rs

def Protect():
    path = rs.OpenFileName("File to protect", filter="PDF (*.pdf)|*.pdf")
    if(path is None): return
    password = rs.StringBox("Password", title="Enter Password")
    if(password is None): return

    #open the PDF
    doc = Xfinium.Pdf.PdfFixedDocument(path)
    aes = Xfinium.Pdf.Core.Security.PdfAesSecurityHandler()
    aes.EnableContentExtractionForAccessibility = False
    aes.EnableDocumentAssembly = False
    aes.EnableDocumentChange = False
    aes.EnableContentExtraction = False
    aes.EnableFormsFill = False
    aes.EnableAnnotationsAndFieldsEdit = False
    aes.EnablePrint = False
    aes.EncryptMetadata = True
    aes.UserPassword = password
    aes.OwnerPassword = password
    aes.KeySize = 256
    aes.UseEnhancedPasswordValidation = True # PDF 2.0
    # Save the document using AES 256 encryption
    savepath = path[:-4] + "_encrypted.pdf"
    doc.Save(savepath, aes);

Thanks for the help!
Works grate!


Hi @stevebaer,

In rhino8 this script no longer work.
It complains about the Xfinium.Pdf.Win.dll.
Is it because python3 ?

Best regards

@sonny.bergenholtz did you give it a try with IronPython2 instead of Py3?

Hi Michael,
I don’t quite understand, is it possible to select what version of python to run in Rhino 8?

I have been using the script above from Steve in rhino 7, but now when trying it in Rhino8 it doesn’t work.

Never mind, I found the solution in an old thread:

1 Like

Hi @sonny.bergenholtz, in the ScriptEditor you can choose the language when you make a new file: