quartzapi / yii2-quartzapi
Yii2 extension: generate PDFs via QuartzAPI (template + JSON → PDF)
Package info
github.com/quartzapi/yii2-quartzapi
Type:yii2-extension
pkg:composer/quartzapi/yii2-quartzapi
dev-main
2026-08-18 11:00 UTC
Requires
- php: >=7.4.0
- yiisoft/yii2: ~2.0.45
- yiisoft/yii2-httpclient: ~2.0.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-18 11:19:38 UTC
README
Yii2 extension to generate PDFs with QuartzAPI: visual template + JSON → PDF over REST.
Requirements
- PHP 7.4+
- Yii2
~2.0.45 yiisoft/yii2-httpclient- A QuartzAPI account, API key, and an active template code (e.g.
INVOICE_V1)
Installation
Local path (monorepo / development)
In your Yii2 project's composer.json:
{
"repositories": [
{
"type": "path",
"url": "extensions/yii2-quartzapi"
}
],
"require": {
"quartzapi/yii2-quartzapi": "@dev"
}
}
Then:
composer update quartzapi/yii2-quartzapi
Packagist (once published)
composer require quartzapi/yii2-quartzapi
Configuration
In common/config/main-local.php (or equivalent):
'components' => [ 'quartzApi' => [ 'class' => \quartzapi\yii2\QuartzApiClient::class, 'apiKey' => $params['quartzApiKey'], // or getenv('QUARTZAPI_KEY') 'baseUrl' => 'https://backend.quartzapi.com', // 'timeout' => 120, ], ],
Quick start
use quartzapi\yii2\Exception\QuartzApiException; $data = [ 'master' => [ 'invoice_number' => 'INV-2026-0042', 'grand_total' => 1329.80, 'items' => [ /* … */ ], ], ]; // Generate + download + HTTP response (inline / attachment) return Yii::$app->quartzApi->sendPdfResponse('INVOICE_V1', $data, [ 'externalId' => 'INV-2026-0042', 'fileName' => 'Invoice.pdf', 'inline' => true, ]);
Generate only (metadata, no download)
$result = Yii::$app->quartzApi->generateDocument('INVOICE_V1', $data, [ 'externalId' => 'INV-2026-0042', // 'folderId' => 'fld_…', ]); // $result->documentId, downloadUrl, fileName, jobId, …
Generate and get PDF bytes
$bundle = Yii::$app->quartzApi->generateAndDownload('INVOICE_V1', $data); $pdfBinary = $bundle['content']; $meta = $bundle['result'];
Download only
$pdf = Yii::$app->quartzApi->downloadPdf($result->documentId); // or: downloadPdf($result->downloadUrl);
API endpoints used
| Operation | Method | Route |
|---|---|---|
| Generate PDF | POST |
api/v1-jobs/generate-document |
| Download | GET |
api/v1-documents/download&uid=… |
Auth: Authorization: Bearer <apiKey> header.
Minimal generate body:
{
"templateCode": "INVOICE_V1",
"outputFormat": "pdf",
"externalId": "optional-unique-id",
"data": { "master": { } }
}
Exceptions
quartzapi\yii2\Exception\QuartzApiException— generic errors / empty body / invalid JSONquartzapi\yii2\Exception\QuartzApiHttpException— non-2xx HTTP (getStatusCode(),getResponseBody())
Examples
See the examples/ folder:
config-snippet.php— Yii component configInvoiceController.php— PDF download action
License
MIT