signPDF

sign (for PDF files)

PREMIUM BASIC / ADVANCED

Digitally signs a PDF document.

Description

SignPDF

public sign (string $target, [array $optionsSignature, array $optionsImage, array $options])

SignPDFPlus

public sign (string $target, [array $optionsSignature, array $optionsImage])

These methods allow you to digitally sign a PDF document.

phpdocx includes two classes to sign PDF documents:

  • SignPDF: allows to sign a PDF using one signature.
  • SignPDFPlus: available since phpdocx 12, allows to sign a PDF using one or more signatures. This class requires well-formed PDF documents. The conversion plugin based on LibreOffice generates well-formed PDF documents when transforming DOCX documents, but other tools such as MS Word may generate not well-formed PDF documents. A not well-formed PDF can be fixed easily, on Repair PDF documents is available more information about this task.
Parameters (SignPDF)

target

Path to save the PDF output.

optionsSignature

The possible keys and values are:

key Type Description
x float Abscissa of the upper-left corner. 180 as default.
y float Ordinate of the upper-left corner. 60 as default
w float Width of the signature area. 15 as default.
h float Height of the signature area. 15 as default
page int Page number (if < 0 the last page is used). -1 as default
accessPermission int Access permissions granted for this document. 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing;; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification. 2 as default.

optionsImage

The possible keys and values are:

key Type Description
src string Image file path.
x float Abscissa of the upper-left corner (LTR) or upper-right corner (RTL). 180 as default.
y float Ordinate of the upper-left corner (LTR) or upper-right corner (RTL). 60 as default.
w float Width of the image in the page. If not set, it's automatically calculated. 15 as default.
h float Height of the image in the page. If not set, it's automatically calculated. 15 as default.
page int Page number (if < 0 the last page is used). -1 as default
link string URL. Empty as default.

options

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

key Type Description
annotations bool Import annotations (links, comments and others). False as default.
Parameters (SignPDFPlus)

target

Path to save the PDF output.

optionsSignature

The possible keys and values are:

key Type Description
x float Abscissa of the upper-left corner. 180 as default.
y float Ordinate of the upper-left corner. 60 as default
w float Width of the signature area. 15 as default.
h float Height of the signature area. 15 as default
page int Page number.

optionsImage

The possible keys and values are:

key Type Description
src string Image file path.
Code samples

Example #1

Example #2