pdx:protectPDF

Password protects the contents of a PDF document.

Description

Element definition

x
 
1
<pdx:config>
2
    <pdx:crypto>
3
        <pdx:protect pdx:password="" pdx:type="" pdx:src="" pdx:target="" />
4
    </pdx:crypto>
5
</pdx:config>
6

This element allows to password protect a PDF document. One may protect the PDF from being printed, copied, etcetera.

Notice that this element does not encrypt the contents of the PDF document. This element is not secure and can be easily overridden by an experienced user.

You may find a detailed description of this package in the Cryptophpdocx section of the API documentation.

Attributes and sub-elements

src

Path to the PDF document we want to protect.

target

Path to the resulting protected PDF document.

options

The possible keys and values are (required options are shown with yellow background):

key Description
permissionsBlocked
  • print
  • modify
  • copy
  • annot-forms
  • fill-forms
  • extract
  • assemble
  • print-high
passwordOwner String to allow full access to the PDF file.
Code samples
#Example 1

config.xml

10
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:config>
4
        <pdx:output pdx:name="output" pdx:type="pdf" />
5
        <pdx:crypto>
6
            <pdx:protect pdx:password="xmldocx" pdx:src="/var/www/xmldocx/samples/files/Test.pdf" pdx:target="/var/www/xmldocx/samples/Crypto/protectPdf/Protected.pdf" pdx:type="print,annot-forms" />
7
        </pdx:crypto>
8
    </pdx:config>
9
</pdx:document>
10

content.xml

6
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:content>
4
    </pdx:content>
5
</pdx:document>
6

settings.xml

6
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:settings>
4
    </pdx:settings>
5
</pdx:document>
6
10
 
1
import os as os
2
import sys as sys
3
sys.path.append(os.path.abspath("wrappers/python/XmlDocx"))
4
import XmlDocx as XmlDocx
5
document = XmlDocx.XmlDocx("config.xml")
6
document.setDocumentProperties("settings.xml")
7
document.addContent("content.xml")
8
document.setXmlDocxPath("xmldocx path")
9
document.render()
10

The resulting Word document looks like: