signPDF

sign (for PDF files)

PREMIUM TRIAL / 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: 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
Default as 2.
info array Signature information:
  • Name
  • Location
  • Reason
  • ContactInfo

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). Default as false.
useFixedAnnotationPositions bool Force annotation page link IDs. Useful when using PDF readers that don't detect all PDF contents automatically. Default as false.
Exceptions

The file does not exist.

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. 0 as default.
y float Ordinate of the upper-left corner. 0 as default.
w float Width of the signature area. x option + image width as default.
h float Height of the signature area. y option + image height as default.
page int Page number.
info array Signature information:
  • Name
  • Location
  • Reason
  • ContactInfo

optionsImage

The possible keys and values are:

key Type Description
src string Image file path.
Code samples

Example #1

Example #2

Release notes
  • phpdocx 15.5:
    • info option.
    • cast to int object stream content indexes.
    • improved annotations support.
  • phpdocx 14.0:
    • useFixedAnnotationPositions option.
  • phpdocx 13.0:
    • improved working with indirect objects.
  • phpdocx 12.0:
    • SignPDFPlus class.
    • improved annotations support.
  • phpdocx 10.0:
    • annotations and page options.
  • phpdocx 7.0:
    • supported PDF 1.5, 1.6 and 1.7 versions.