Protecting PDFs

unhandled

#1

Hi,

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.

Cheers


Crashing Rhino while printing layout to pdf through acrobat pdf printer
(Steve Baer) #2

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.


#3

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

Cheers


#4

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.

_
c.


(Steve Baer) #5

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
https://mcneel.myjetbrains.com/youtrack/issue/RH-44689

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

import clr
clr.AddReference("Xfinium.Pdf.Win.dll")
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);
    
Protect()

#6

Thanks for the help!
Works grate!

Cheers