PHPackages                             generatepdfs/php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. generatepdfs/php-sdk

ActiveLibrary[API Development](/categories/api)

generatepdfs/php-sdk
====================

PHP SDK for GeneratePDFs.com API

1.0.0(5mo ago)1101MITPHPPHP ^8.1CI passing

Since Dec 8Pushed 5mo agoCompare

[ Source](https://github.com/GeneratePDFs/php-sdk)[ Packagist](https://packagist.org/packages/generatepdfs/php-sdk)[ RSS](/packages/generatepdfs-php-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (1)

GeneratePDFs PHP SDK
====================

[](#generatepdfs-php-sdk)

PHP SDK for the [GeneratePDFs.com](https://generatepdfs.com) API, your go-to place for HTML to PDF.

Upload your HTML files, along with any CSS files and images to generate a PDF. Alternatively provide a URL to generate a PDF from it's contents.

Installation
------------

[](#installation)

```
composer require generatepdfs/php-sdk
```

Get your API Token
------------------

[](#get-your-api-token)

Sign up for an account on [GeneratePDFs.com](https://generatepdfs.com) and head to the API Tokens section and create a new token.

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

```
use GeneratePDFs\GeneratePDFs;

$client = GeneratePDFs::connect('YOUR_API_TOKEN');
```

### Generate PDF from HTML File

[](#generate-pdf-from-html-file)

```
use GeneratePDFs\GeneratePDFs;
use GeneratePDFs\Pdf;

// Simple HTML file
$pdf = $client->generateFromHtml('/path/to/file.html');

// HTML file with CSS
$pdf = $client->generateFromHtml(
    '/path/to/file.html',
    '/path/to/file.css'
);

// HTML file with CSS and images
$pdf = $client->generateFromHtml(
    '/path/to/file.html',
    '/path/to/file.css',
    [
        [
            'name' => 'logo.png',
            'path' => '/path/to/logo.png',
            'mime_type' => 'image/png' // Optional, will be auto-detected
        ],
        [
            'name' => 'photo.jpg',
            'path' => '/path/to/photo.jpg'
        ]
    ]
);
```

### Generate PDF from URL

[](#generate-pdf-from-url)

```
$pdf = $client->generateFromUrl('https://example.com');
```

### Get PDF by ID

[](#get-pdf-by-id)

```
// Retrieve a PDF by its ID
$pdf = $client->getPdf(123);
```

### Working with PDF Objects

[](#working-with-pdf-objects)

The SDK returns `Pdf` objects that provide easy access to PDF information and downloading:

```
// Access PDF properties
$pdfId = $pdf->getId();
$pdfName = $pdf->getName();
$status = $pdf->getStatus();
$downloadUrl = $pdf->getDownloadUrl();
$createdAt = $pdf->getCreatedAt();

// Check if PDF is ready
if ($pdf->isReady()) {
    // Download PDF content as string
    $pdfContent = $pdf->download();

    // Or save directly to file
    $pdf->downloadToFile('/path/to/save/output.pdf');
}

// Refresh PDF data from the API (useful for checking status updates)
$refreshedPdf = $pdf->refresh();
if ($refreshedPdf->isReady()) {
    $pdfContent = $refreshedPdf->download();
}
```

### Client Methods

[](#client-methods)

- `generateFromHtml(string $htmlPath, ?string $cssPath = null, array $images = []): Pdf` - Generate a PDF from HTML file(s)
- `generateFromUrl(string $url): Pdf` - Generate a PDF from a URL
- `getPdf(int $id): Pdf` - Retrieve a PDF by its ID
- `downloadPdf(string $downloadUrl): string` - Download PDF binary content from a download URL

### PDF Object Methods

[](#pdf-object-methods)

- `getId(): int` - Get the PDF ID
- `getName(): string` - Get the PDF filename
- `getStatus(): string` - Get the current status (pending, processing, completed, failed)
- `getDownloadUrl(): string` - Get the download URL
- `getCreatedAt(): DateTimeImmutable` - Get the creation date
- `isReady(): bool` - Check if the PDF is ready for download
- `download(): string` - Download and return PDF binary content
- `downloadToFile(string $filePath): bool` - Download and save PDF to a file
- `refresh(): Pdf` - Refresh PDF data from the API and return a new Pdf instance with updated information

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Guzzle HTTP Client 7.0 or higher

Testing
-------

[](#testing)

To run the test suite and code style checker, execute:

```
composer test
```

This will run both PHP CodeSniffer (PSR-2 standard) and Pest tests.

Contributing
------------

[](#contributing)

Contributions and suggestions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [GitHub](https://github.com/GeneratePDFs/php-sdk).

### Pull Requests

[](#pull-requests)

- **[PSR-12 Extended Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer/).
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the README / CHANGELOG and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow semver. Randomly breaking public APIs is not an option.
- **Create topic branches** - Don't ask us to pull from your master branch.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for a history of changes.

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance71

Regular maintenance activity

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

161d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/43972359?v=4)[snsmurf](/maintainers/snsmurf)[@snsmurf](https://github.com/snsmurf)

---

Top Contributors

[![mikebarlow](https://avatars.githubusercontent.com/u/293049?v=4)](https://github.com/mikebarlow "mikebarlow (7 commits)")

---

Tags

apipdfsdkgenerate

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/generatepdfs-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/generatepdfs-php-sdk/health.svg)](https://phpackages.com/packages/generatepdfs-php-sdk)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[hubspot/api-client

Hubspot API client

23914.2M16](/packages/hubspot-api-client)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[resend/resend-php

Resend PHP library.

564.7M21](/packages/resend-resend-php)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

553.3M7](/packages/checkout-checkout-sdk-php)[mozex/anthropic-laravel

Anthropic PHP for Laravel is a supercharged PHP API client that allows you to interact with the Anthropic API

71226.4k1](/packages/mozex-anthropic-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
