Signer
in package
Adds signature images, and marks such as ticks and lines, on top of the pages of an existing PDF.
The PDF is revised with an incremental update: its bytes are kept as they are and the signatures are appended, so everything it held survives, including any earlier digital signature as a prior revision.
Signer::open('lease.pdf')
->stamp(SignatureImage::fromFile('signature.png'), page: 3, x: 72, y: 640, width: 160)
->save('lease-signed.pdf');
This places a visible signature. It is not a cryptographic digital signature.
Table of Contents
Properties
- $document : Document
- $stamps : array<int, Mark, 1: int, 2: array{float, float, float, float, float, float}}>
Methods
- fromString() : self
- Opens a PDF from its bytes.
- hasDigitalSignatures() : bool
- Whether the PDF already carries a digital signature. Adding a visible signature keeps it as an earlier revision, but viewers will report that the document changed after it was signed.
- mark() : self
- Draws a mark on a page, such as a tick in a box or a line through a clause.
- markWithMatrix() : self
- Draws a mark where a transformation matrix in the page's user space would draw an image into the unit square. {@see Signer::mark()} works this out from a position on the page.
- open() : self
- Opens a PDF file.
- pageCount() : int
- The number of pages.
- pageSize() : array{float, float}
- A page's width and height as displayed, in points, after its crop box and rotation.
- save() : string
- Writes the signed PDF.
- stamp() : self
- Places a signature on a page.
- stampWithMatrix() : self
- Places a signature with a transformation matrix in the page's user space, which draws the image into the unit square. {@see Signer::stamp()} works this out from a position on the page.
- toString() : string
- The signed PDF: the original bytes followed by an update holding the signatures.
- __construct() : mixed
- addImage() : Reference
- Adds a signature as an image XObject, with a soft mask when it has transparency.
- contents() : array<int, mixed>
- A page's content streams, as a list of references.
- copyDictionary() : Dictionary
- A new dictionary with the entries of a possibly indirect one, or an empty one when there is none.
- freeName() : string
- A resource name not already in use.
- page() : Page
- A page by number.
Properties
$document read-only
private
Document
$document
$stamps
private
array<int, Mark, 1: int, 2: array{float, float, float, float, float, float}}>
$stamps
= []
Methods
fromString()
Opens a PDF from its bytes.
public
static fromString(string $bytes) : self
Parameters
- $bytes : string
-
The PDF.
Tags
Return values
selfhasDigitalSignatures()
Whether the PDF already carries a digital signature. Adding a visible signature keeps it as an earlier revision, but viewers will report that the document changed after it was signed.
public
hasDigitalSignatures() : bool
Return values
boolmark()
Draws a mark on a page, such as a tick in a box or a line through a clause.
public
mark(Mark $mark, int $page, float $x, float $y, float $width, float $height) : self
The mark fills a rectangle on the page as a viewer shows it, in points from its top-left corner. A line runs corner to corner, so a rectangle with no height makes a level one.
Parameters
- $mark : Mark
-
The mark.
- $page : int
-
The page number, from 1.
- $x : float
-
The rectangle's left edge, from the page's left edge.
- $y : float
-
Its top edge, from the page's top edge.
- $width : float
-
Its width.
- $height : float
-
Its height.
Tags
Return values
selfmarkWithMatrix()
Draws a mark where a transformation matrix in the page's user space would draw an image into the unit square. {@see Signer::mark()} works this out from a position on the page.
public
markWithMatrix(Mark $mark, int $page, array{float, float, float, float, float, float} $matrix) : self
Parameters
- $mark : Mark
-
The mark.
- $page : int
-
The page number, from 1.
- $matrix : array{float, float, float, float, float, float}
-
The
cmoperator's a b c d e f.
Tags
Return values
selfopen()
Opens a PDF file.
public
static open(string $path) : self
Parameters
- $path : string
-
The PDF.
Tags
Return values
selfpageCount()
The number of pages.
public
pageCount() : int
Return values
intpageSize()
A page's width and height as displayed, in points, after its crop box and rotation.
public
pageSize(int $page) : array{float, float}
Parameters
- $page : int
-
The page number, from 1.
Tags
Return values
array{float, float}save()
Writes the signed PDF.
public
save(string $path) : string
Parameters
- $path : string
-
Where to write it; an existing file is replaced.
Tags
Return values
string —The path.
stamp()
Places a signature on a page.
public
stamp(SignatureImage $image, int $page, float $x, float $y, float $width[, float|null $height = null ]) : self
The position is on the page as a viewer shows it, in points from its top-left corner; the signature stays upright even on a rotated page.
Parameters
- $image : SignatureImage
-
The signature.
- $page : int
-
The page number, from 1.
- $x : float
-
The signature's left edge, from the page's left edge.
- $y : float
-
Its top edge, from the page's top edge.
- $width : float
-
Its width.
- $height : float|null = null
-
Its height; by default, whatever keeps the image's proportions.
Tags
Return values
selfstampWithMatrix()
Places a signature with a transformation matrix in the page's user space, which draws the image into the unit square. {@see Signer::stamp()} works this out from a position on the page.
public
stampWithMatrix(SignatureImage $image, int $page, array{float, float, float, float, float, float} $matrix) : self
Parameters
- $image : SignatureImage
-
The signature.
- $page : int
-
The page number, from 1.
- $matrix : array{float, float, float, float, float, float}
-
The
cmoperator's a b c d e f.
Tags
Return values
selftoString()
The signed PDF: the original bytes followed by an update holding the signatures.
public
toString() : string
Tags
Return values
string__construct()
private
__construct(Document $document) : mixed
Parameters
- $document : Document
Tags
addImage()
Adds a signature as an image XObject, with a soft mask when it has transparency.
private
addImage(IncrementalUpdate $update, SignatureImage $image) : Reference
Parameters
- $update : IncrementalUpdate
- $image : SignatureImage
Return values
Referencecontents()
A page's content streams, as a list of references.
private
contents(Page $page) : array<int, mixed>
Parameters
- $page : Page
Return values
array<int, mixed>copyDictionary()
A new dictionary with the entries of a possibly indirect one, or an empty one when there is none.
private
copyDictionary(mixed $value) : Dictionary
Parameters
- $value : mixed
-
The dictionary, a reference to one, or null.
Return values
DictionaryfreeName()
A resource name not already in use.
private
freeName(Dictionary $xObjects) : string
Parameters
- $xObjects : Dictionary
-
The page's XObject resources.
Return values
stringpage()
A page by number.
private
page(int $page) : Page
Parameters
- $page : int
-
The page number, from 1.