LogoDOCS
OverviewAuthenticationRate LimitsErrors
Logo
Sign in →

PHP SDK

The PHP SDK provides a client for integrating PDFGate API endpoints into your PHP applications.

Source code: github.com/pdfgate/pdfgate-sdk-php
Package: packagist.org/packages/pdfgate/pdfgate-sdk-php

Requirements

  • PHP 7.4+

Installation

Install the package with Composer, then initialize the client with your API key.

1composer require pdfgate/pdfgate-sdk-php

Quick start

The example below generates a PDF from a URL and returns a pre-signed file URL.

1<?php23use PdfGate\PdfGateClient;45$client = new PdfGateClient('live_your_api_key');67$generated = $client->generatePdf([8    'url' => 'https://example.com',9    'pageSizeType' => 'a4',10    'preSignedUrlExpiresIn' => 120011]);1213echo $generated->getFileUrl();

Generate from HTML

You can also generate a PDF directly from raw HTML and attach metadata to the resulting document.

1$client->generatePdf([2    'html' => '<h1>Hello</h1>',3    'pageSizeType' => 'a4',4    'metadata' => ['source' => 'sdk'],5]);

Download a file

Use getFile to retrieve the output stream and save it locally.

1$stream = $client->getFile($documentId);2$output = fopen('output.pdf', 'wb');3stream_copy_to_stream($stream, $output);4fclose($output);5fclose($stream);

Core methods

MethodPurpose
generatePdfGenerate a PDF from HTML or a public URL.
uploadFileUpload a PDF file for later transformations.
getFileDownload the PDF stream for a stored document.
getDocumentRetrieve document metadata and file URLs.
flattenPdfFlatten interactive PDF fields into a static document.
compressPdfCompress a PDF and return the resulting document record.
protectPdfEncrypt a PDF and apply access restrictions.
watermarkPdfApply text or image watermarks to a document.
extractPdfFormDataRead form field values from a fillable PDF.

Related documentation

Use the SDK together with the main API documentation for request parameters, endpoint behavior, and workflow guides such as webhooks and PDF form fields.