Usage Guide

Generate PDF

$client->generatePdf([
    'html' => '<h1>Hello</h1>',
    'pageSizeType' => 'a4',
    'printBackground' => true,
    'metadata' => ['source' => 'sdk'],
]);

Upload File

If both file and url are passed, uploadFile() prioritizes file and sends multipart form data.

$client->uploadFile([
    'file' => new \CURLFile('/absolute/path/source.pdf', 'application/pdf', 'source.pdf'),
    'preSignedUrlExpiresIn' => 1200,
]);
$client->uploadFile([
    'url' => 'https://example.com/source.pdf',
    'preSignedUrlExpiresIn' => 1200,
]);

Create Envelope

createEnvelope() sends JSON with nested envelope documents and recipients. Optional fields like metadata and recipient role are omitted automatically when set to null. Each recipient is given either as email and name or as the recipientId of a stored recipient (see Create Recipient). Recipients marked embedded receive no email and get their signing links via createEmbedLink() after sending. Optional signingOrder (given for every recipient of a document or for none) makes recipients sign one after another: each recipient is activated — and emailed their signing link — once everyone with a lower value has signed, and the envelope.recipient.activated webhook event fires at that moment. Optional autoSign applies the stored signature of the referenced recipient on their behalf when their turn to sign comes, with no signing session or email; it requires recipientId pointing to a recipient with an active stored signature (see Request Recipient Signature) and cannot be combined with embedded. Optional sendSignedCopy controls whether the recipient is emailed the signed document when the document completes; it defaults to true for recipients who sign through the emailed signing link and false for embedded and automatic signing recipients.

$envelope = $client->createEnvelope([
    'requesterName' => 'John Doe',
    'documents' => [
        [
            'sourceDocumentId' => '6642381c5c61',
            'name' => 'Employment Agreement',
            'recipients' => [
                [
                    'email' => 'anna@example.com',
                    'name' => 'Anna Smith',
                    'signingOrder' => 1,
                ],
                [
                    'email' => 'bob@example.com',
                    'name' => 'Bob Jones',
                    'signingOrder' => 2,
                ],
            ],
        ],
    ],
    'metadata' => ['customerId' => 'cus_123'],
]);

Send Envelope

sendEnvelope() emails each recipient a secure signing link. Links stay valid until the envelope expires (30 days after creation by default, configurable with expiresInDays or the account's signing settings) and recipients must complete OTP verification before entering the signing flow. Embedded recipients receive no email; create their signing links with createEmbedLink() after sending.

$sentEnvelope = $client->sendEnvelope('69c0fa44f83ca6a7015f1c8c');

Get Envelope

getEnvelope() retrieves the current envelope state so you can inspect overall status, document progress, and recipient status details.

$envelope = $client->getEnvelope('69c0fa44f83ca6a7015f1c8c');

Void Envelope

voidEnvelope() cancels an envelope in created or in_progress status. Recipients who have not signed are notified by email and their signing links stop working; documents already signed by all recipients are not affected. The optional reason is visible to recipients.

$voided = $client->voidEnvelope('69c0fa44f83ca6a7015f1c8c', 'Contract terms changed');

Delete Envelope

deleteEnvelope() permanently deletes an envelope and the files it produced (signed documents and audit logs). Recipient data is anonymized and recipients lose access; source documents are not deleted. Only envelopes in draft, completed, expired, or voided status can be deleted — void an active envelope first.

$client->deleteEnvelope('69c0fa44f83ca6a7015f1c8c');

Create Embed Link

createEmbedLink() creates a short-lived signing link for an embedded recipient; render the returned URL in an iframe inside your application. The envelope must be in in_progress status and the link expires after 10 minutes, so create it when the signer is ready (one link per signing session). When the session ends the iframe redirects to returnUrl with event (signing_complete, voided, expired or not_found), envelopeId, documentId and recipientId appended as query parameters; existing returnUrl query parameters are preserved.

$embedLink = $client->createEmbedLink('69c0fa44f83ca6a7015f1c8c', [
    'documentId' => '6642381c5c61',
    'recipientId' => 'rcp_1a2b3c4d5e6f',
    'returnUrl' => 'https://example.com/signed',
]);

echo $embedLink->getUrl();

Create Recipient

createRecipient() stores a recipient so envelopes can reference them by recipientId. The email is stored lowercased and cannot be changed later. Emails are not unique; every call creates a new recipient, so list existing recipients first when reuse is intended.

$recipient = $client->createRecipient([
    'email' => 'anna@example.com',
    'name' => 'Anna Smith',
    'metadata' => ['customerId' => 'cus_123'],
]);

List Recipients

listRecipients() returns the stored recipients with the given email (case-insensitive), oldest first.

$recipients = $client->listRecipients('anna@example.com');

Get Recipient

getRecipient() retrieves a stored recipient by ID.

$recipient = $client->getRecipient('rcp_1a2b3c4d5e6f');

Update Recipient

updateRecipient() updates a stored recipient's name or metadata. The email cannot be changed. Existing envelopes are not affected; they keep the recipient name they were created with.

$updated = $client->updateRecipient('rcp_1a2b3c4d5e6f', [
    'name' => 'Anna Jones',
]);

Delete Recipient

deleteRecipient() deletes a stored recipient. The record is kept with its personal data removed, so later reads return 404 and a new envelope to the same address creates a fresh recipient. Envelopes already sent are not affected. A recipient with an active stored signature or a pending enrolment cannot be deleted: call removeRecipientSignature() first.

$client->deleteRecipient('rcp_1a2b3c4d5e6f');

Request Recipient Signature

requestRecipientSignature() starts automatic signing for a recipient: PDFGate emails them a link to store a reusable signature. The recipient verifies their email with a one-time code, accepts the authorization text and types, draws or uploads their signature. The link is valid for 7 days; calling this again replaces a pending request. Once the enrolment is complete the recipient.signature.enrolled webhook event fires and envelopes can set autoSign on this recipient. Rejected when the recipient has no email or already has an active stored signature.

$pending = $client->requestRecipientSignature('rcp_1a2b3c4d5e6f');

echo $pending->getSignature()->getStatus(); // "pending"

The RecipientStoredSignature object returned by getSignature() carries getStatus() (pending, active or revoked, see StoredSignatureStatus), getRequestedAt(), getAdoptionMethod() (see SignatureAdoptionMethod), getEnrolledAt(), getRevokedAt(), getLastUsedAt() and getUseCount(). getImage() (a PNG data URL) is set by getRecipient() only while the signature is active. getSignature() is null until an enrolment was requested.

Remove Recipient Signature

removeRecipientSignature() removes the stored signature of a recipient, or cancels a pending enrolment so its link stops working. Envelopes already waiting on an automatic signature fall back to a signing link emailed to the recipient. Removing an active signature fires the recipient.signature.revoked webhook event. Idempotent: a recipient without a stored signature is returned unchanged.

$recipient = $client->removeRecipientSignature('rcp_1a2b3c4d5e6f');

Flatten PDF

$client->flattenPdf([
    'documentId' => $id,
    'preSignedUrlExpiresIn' => 1200,
]);

Compress PDF

$client->compressPdf([
    'documentId' => $id,
    'linearize' => true,
]);

Protect PDF

$client->protectPdf([
    'documentId' => $id,
    'algorithm' => 'AES256',
    'ownerPassword' => 'ownerPassword',
    'userPassword' => 'userPassword',
    'disablePrint' => true,
    'disableCopy' => true,
]);

Watermark PDF

watermarkPdf() always sends multipart form data and forces jsonResponse=true.

$client->watermarkPdf([
    'documentId' => $id,
    'type' => 'text',
    'text' => 'Confidential',
    'fontColor' => 'rgb(156, 50, 168)',
    'rotate' => 30,
    'opacity' => 0.2,
]);
$client->watermarkPdf([
    'documentId' => $id,
    'type' => 'image',
    'watermark' => new \CURLFile('/absolute/path/watermark.png'),
    'imageWidth' => 120,
    'imageHeight' => 120,
]);

Extract PDF Form Data

$formData = $client->extractPdfFormData([
    'documentId' => $id,
]);

Get Document Metadata

$document = $client->getDocument($id, [
    'preSignedUrlExpiresIn' => 1200,
]);

Get File Stream

$stream = $client->getFile($id);
$output = fopen('output.pdf', 'wb');
stream_copy_to_stream($stream, $output);
fclose($output);
fclose($stream);

To download generated files, enable Save files for one month in PDFGate Dashboard settings.