Report Lab Encrypt PDF file (python)

this may not work in your working enviroment, but the core is the same

 

#!C:\python25\python.exe

from reportlab.lib units import cm
import reportGenerator
import re
form reportlab.lib import pdfencrypt
from reportlab.pdfgen import canvas
from reportlab.testutils import setOutDir,makeSuiteForClasses,outputfile,printLocation
setOutDir(__name__)

class _testEncrypt(reportGenerator.drawClass)"

  def generate(self, fileName):
    encrypt = pdfencrypt.StandardEncryption("userPass", "OwnerPass")
    encrypt.setAllPermissions(0)
    encrypt.canPrint = 1
    c = canvas.Canvas(fileName)
    c._doc.encrypt = encrypt
    c.drawString(100, 500, "Hello World")
    c.save()
    return "Done"

if __name__ == "__main__":
  fileName = outputfile("test.pdf")
  print _testEncrypt().generate(fileName)


 

If it is useful for you, i will feel cheerful

 

 

你可能感兴趣的:(C++,c,python,C#)