PHPackages                             pdfy/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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. pdfy/php-sdk

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

pdfy/php-sdk
============

PHP SDK for Pdfy.app PDF Generation API

1.1.0(9mo ago)03MITPHPPHP ^8.4

Since Aug 14Pushed 8mo agoCompare

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

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

Pdfy PHP SDK
============

[](#pdfy-php-sdk)

A modern PHP SDK for the [pdfy.app](https://pdfy.app) PDF Generation API, built with Laravel's HTTP Client.

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

[](#requirements)

- PHP 8.4+
- Laravel 11+ or 12+ (for Laravel integration)

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

[](#installation)

Install the package via Composer:

```
composer require pdfy/php-sdk
```

Features
--------

[](#features)

- ✅ **Modern PHP 8.4+** - Uses latest PHP features (strict types, readonly classes, attributes)
- ✅ **Laravel 12 Ready** - Full Laravel 11+ and 12+ support with auto-discovery
- ✅ **Type Safe** - Comprehensive type hints and strict typing
- ✅ **Async &amp; Sync** - Support for both asynchronous and synchronous workflows
- ✅ **Rich Error Handling** - Detailed exceptions with user-friendly messages
- ✅ **Multiple APIs** - Support for both JSON and HTML headers APIs
- ✅ **Framework Agnostic** - Works with any PHP project
- ✅ **Well Tested** - Comprehensive PHPUnit test suite
- ✅ **PSR Compliant** - Follows PHP standards and best practices

Laravel Integration
-------------------

[](#laravel-integration)

If you're using Laravel, the package will auto-register. Publish the config file:

```
php artisan vendor:publish --tag=pdfy-config
```

Add your API key to your `.env` file:

```
PDFY_API_KEY=your_api_key_here
```

Override the `BASE_URL` if you need:

```
PDFY_BASE_URL=https://pdfy.app/api/v1
```

You can set the timeout for how long the synchronous "create and download" method should wait for the PDF to be generated:

```
PDFY_TIMEOUT=30
```

Usage
-----

[](#usage)

### Standalone Usage (without Laravel)

[](#standalone-usage-without-laravel)

```
use Pdfy\Sdk\PdfyClient;
use Pdfy\Sdk\DataObjects\PdfOptions;

$client = new PdfyClient('your_api_key_here');

// Simple PDF generation
$html = 'Hello WorldThis is a test PDF.';
$job = $client->pdfs()->create($html, 'test.pdf');

echo "Job ID: " . $job->jobId . "\n";
echo "Status: " . $job->status . "\n";

// Wait for completion and download
$pdfContent = $client->pdfs()->createAndDownload($html, 'test.pdf');
file_put_contents('test.pdf', $pdfContent);
```

### Laravel Usage (with Facade)

[](#laravel-usage-with-facade)

```
use Pdfy\Sdk\Facades\Pdfy;
use Pdfy\Sdk\DataObjects\PdfOptions;

// Simple PDF generation
$html = 'Hello WorldThis is a test PDF.';
$job = Pdfy::pdfs()->create($html, 'test.pdf');

// With custom options
$options = PdfOptions::a4Portrait();
$job = Pdfy::pdfs()->create($html, 'report.pdf', $options);

// Generate and download immediately
$pdfContent = Pdfy::pdfs()->createAndDownload($html, 'invoice.pdf');
return response($pdfContent, 200, [
    'Content-Type' => 'application/pdf',
    'Content-Disposition' => 'attachment; filename="invoice.pdf"',
]);
```

### Advanced Usage

[](#advanced-usage)

```
use Pdfy\Sdk\DataObjects\PdfOptions;

// Custom PDF options
$options = new PdfOptions(
    format: 'A4',
    orientation: 'landscape',
    marginTop: 2.0,
    marginRight: 1.5,
    marginBottom: 2.0,
    marginLeft: 1.5,
    marginUnit: 'cm',
    printBackground: true
);

// Create PDF with options
$job = $client->pdfs()->create($html, 'landscape.pdf', $options);

// Check status
$job = $client->pdfs()->status($job->jobId);
if ($job->isCompleted()) {
    $pdfContent = $client->pdfs()->download($job->jobId);
    // Save or return PDF
}

// Wait for completion with custom timeout
$job = $client->pdfs()->waitFor($job->jobId, maxWaitSeconds: 120);
```

### HTML Headers API

[](#html-headers-api)

```
// Using HTML content-type with headers
$html = 'Invoice #12345Amount: $100.00';

$headers = [
    'X-PDF-Filename' => 'invoice-12345.pdf',
    'X-PDF-Format' => 'A4',
    'X-PDF-Orientation' => 'portrait',
    'X-PDF-Margin-Top' => '2.0',
    'X-PDF-Margin-Right' => '1.5',
    'X-PDF-Margin-Bottom' => '2.0',
    'X-PDF-Margin-Left' => '1.5',
    'X-PDF-Margin-Unit' => 'cm',
];

$job = $client->pdfs()->createFromHtml($html, $headers);
```

### Error Handling

[](#error-handling)

```
use Pdfy\Sdk\Exceptions\PdfyException;

try {
    $job = $client->pdfs()->create($html, 'test.pdf');
    $pdfContent = $client->pdfs()->createAndDownload($html);
} catch (PdfyException $e) {
    if ($e->isQuotaExceeded()) {
        echo "Quota exceeded: " . $e->getUserMessage();
    } elseif ($e->isRateLimited()) {
        echo "Rate limited: " . $e->getUserMessage();
    } else {
        echo "Error: " . $e->getMessage();
        echo "Error Code: " . $e->getErrorCode();
        echo "HTTP Status: " . $e->getHttpStatus();
    }
}
```

API Reference
-------------

[](#api-reference)

### PdfyClient

[](#pdfyclient)

- `pdfs()` - Get PDF resource for operations
- `request()` - Get authenticated HTTP client
- `postHtml()` - Send HTML content with headers

### PdfResource

[](#pdfresource)

- `create(string $html, ?string $filename, ?PdfOptions $options)` - Create PDF job
- `createFromHtml(string $html, array $headers)` - Create PDF using HTML headers API
- `status(string $jobId)` - Get job status
- `download(string $jobId)` - Download PDF content
- `waitFor(string $jobId, int $maxWaitSeconds)` - Wait for job completion
- `createAndWait()` - Create and wait for completion
- `createAndDownload()` - Create, wait, and download

### PdfOptions

[](#pdfoptions)

- `PdfOptions::a4Portrait()` - A4 portrait with 1cm margins
- `PdfOptions::a4Landscape()` - A4 landscape with 1cm margins
- `PdfOptions::withMargins()` - Custom margins
- `PdfOptions::noMargins()` - No margins

### PdfJob

[](#pdfjob)

- `isCompleted()` - Check if job is completed
- `isFailed()` - Check if job failed
- `isProcessing()` - Check if job is still processing
- `getStatusLabel()` - Get human-readable status

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
# Run tests
composer test

# Run tests with coverage
composer test-coverage

# Run specific test
vendor/bin/phpunit --filter=client_initialization
```

### Code Style

[](#code-style)

```
# Format code
composer format

# Check code style
composer format-test
```

### Contributing

[](#contributing)

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Run tests (`composer test`)
5. Format code (`composer format`)
6. Commit your changes (`git commit -am 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

License
-------

[](#license)

MIT License

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance58

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

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

Every ~0 days

Total

4

Last Release

275d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2935c4c35a1c5dc96c01742aa712fd2a447ec3d8fbfd040748ee4faf798d296?d=identicon)[NicTorgersen](/maintainers/NicTorgersen)

---

Top Contributors

[![NicTorgersen](https://avatars.githubusercontent.com/u/1327106?v=4)](https://github.com/NicTorgersen "NicTorgersen (9 commits)")

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.3k87.6M278](/packages/barryvdh-laravel-dompdf)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[elibyy/tcpdf-laravel

tcpdf support for Laravel 6, 7, 8, 9, 10, 11

3542.7M5](/packages/elibyy-tcpdf-laravel)[lsnepomuceno/laravel-a1-pdf-sign

Sign PDF files with valid x509 certificates

315101.4k](/packages/lsnepomuceno-laravel-a1-pdf-sign)[ismaelw/laratex

A package for creating PDFs in Laravel using LaTeX

12730.1k](/packages/ismaelw-laratex)

PHPackages © 2026

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