feat: add Go, PHP, and Laravel SDKs
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled

- Go SDK: zero deps, functional options pattern, full endpoint coverage
- PHP SDK: PHP 8.1+, curl-based, PdfOptions class, PSR-4 autoloading
- Laravel package: ServiceProvider, Facade, config publishing
- All SDKs document complete PDF options including new v0.4.5 params
This commit is contained in:
DocFast Bot 2026-02-21 13:29:48 +00:00
parent 1545df9a7b
commit bc67c52d3a
13 changed files with 1133 additions and 0 deletions

114
sdk/laravel/README.md Normal file
View file

@ -0,0 +1,114 @@
# DocFast for Laravel
Official Laravel integration for the [DocFast](https://docfast.dev) HTML/Markdown to PDF API.
## Installation
```bash
composer require docfast/laravel
```
Add your API key to `.env`:
```env
DOCFAST_API_KEY=df_pro_your_api_key
```
Publish the config (optional):
```bash
php artisan vendor:publish --tag=docfast-config
```
## Usage
### Via Facade
```php
use DocFast\Laravel\Facades\DocFast;
// HTML to PDF
$pdf = DocFast::html('<h1>Invoice</h1><p>Total: €99.00</p>');
return response($pdf)
->header('Content-Type', 'application/pdf')
->header('Content-Disposition', 'inline; filename="invoice.pdf"');
```
### Via Dependency Injection
```php
use DocFast\Client;
class InvoiceController extends Controller
{
public function download(Client $docfast)
{
$pdf = $docfast->html(view('invoice')->render());
return response($pdf)
->header('Content-Type', 'application/pdf');
}
}
```
### Markdown to PDF
```php
$pdf = DocFast::markdown('# Report\n\nGenerated at ' . now());
```
### URL to PDF
```php
$pdf = DocFast::url('https://example.com');
```
### With PDF Options
```php
use DocFast\PdfOptions;
$options = new PdfOptions();
$options->format = 'Letter';
$options->landscape = true;
$options->margin = ['top' => '20mm', 'bottom' => '20mm'];
$pdf = DocFast::html($html, null, $options);
```
### Headers and Footers
```php
$options = new PdfOptions();
$options->displayHeaderFooter = true;
$options->footerTemplate = '<div style="font-size:9px;text-align:center;width:100%">Page <span class="pageNumber"></span></div>';
$options->margin = ['top' => '10mm', 'bottom' => '20mm'];
$pdf = DocFast::html(view('report')->render(), null, $options);
```
### Templates
```php
$pdf = DocFast::renderTemplate('invoice', [
'company' => 'Acme Corp',
'items' => [['name' => 'Widget', 'price' => 9.99]],
]);
```
## Configuration
```php
// config/docfast.php
return [
'api_key' => env('DOCFAST_API_KEY'),
'base_url' => env('DOCFAST_BASE_URL', 'https://docfast.dev'),
'timeout' => env('DOCFAST_TIMEOUT', 60),
];
```
## Links
- [PHP SDK](../php/) — standalone PHP client
- [Documentation](https://docfast.dev/docs)
- [API Reference](https://docfast.dev/openapi.json)
- [Get an API Key](https://docfast.dev)

34
sdk/laravel/composer.json Normal file
View file

@ -0,0 +1,34 @@
{
"name": "docfast/laravel",
"description": "Laravel integration for the DocFast HTML/Markdown to PDF API",
"type": "library",
"license": "MIT",
"homepage": "https://docfast.dev",
"keywords": ["pdf", "html-to-pdf", "laravel", "docfast"],
"require": {
"php": "^8.1",
"illuminate/support": "^10.0|^11.0|^12.0",
"docfast/docfast-php": "^1.0"
},
"autoload": {
"psr-4": {
"DocFast\\Laravel\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"DocFast\\Laravel\\DocFastServiceProvider"
],
"aliases": {
"DocFast": "DocFast\\Laravel\\Facades\\DocFast"
}
}
},
"authors": [
{
"name": "DocFast",
"homepage": "https://docfast.dev"
}
]
}

View file

@ -0,0 +1,33 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| DocFast API Key
|--------------------------------------------------------------------------
|
| Your DocFast Pro API key. Get one at https://docfast.dev
|
*/
'api_key' => env('DOCFAST_API_KEY'),
/*
|--------------------------------------------------------------------------
| Base URL
|--------------------------------------------------------------------------
|
| The DocFast API base URL. Change for staging or self-hosted instances.
|
*/
'base_url' => env('DOCFAST_BASE_URL', 'https://docfast.dev'),
/*
|--------------------------------------------------------------------------
| Timeout
|--------------------------------------------------------------------------
|
| Request timeout in seconds for PDF generation.
|
*/
'timeout' => env('DOCFAST_TIMEOUT', 60),
];

View file

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace DocFast\Laravel;
use DocFast\Client;
use Illuminate\Support\ServiceProvider;
class DocFastServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->mergeConfigFrom(__DIR__ . '/../config/docfast.php', 'docfast');
$this->app->singleton(Client::class, function ($app) {
$config = $app['config']['docfast'];
return new Client(
$config['api_key'] ?? '',
$config['base_url'] ?? 'https://docfast.dev',
$config['timeout'] ?? 60,
);
});
$this->app->alias(Client::class, 'docfast');
}
public function boot(): void
{
$this->publishes([
__DIR__ . '/../config/docfast.php' => config_path('docfast.php'),
], 'docfast-config');
}
}

View file

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace DocFast\Laravel\Facades;
use DocFast\Client;
use Illuminate\Support\Facades\Facade;
/**
* @method static string html(string $html, ?string $css = null, ?\DocFast\PdfOptions $options = null)
* @method static string markdown(string $markdown, ?string $css = null, ?\DocFast\PdfOptions $options = null)
* @method static string url(string $url, ?\DocFast\PdfOptions $options = null)
* @method static array templates()
* @method static string renderTemplate(string $templateId, array $data = [])
*
* @see \DocFast\Client
*/
class DocFast extends Facade
{
protected static function getFacadeAccessor(): string
{
return Client::class;
}
}