owly-digital / pdf-api-client
There is no license information available for the latest version (dev-master) of this package.
Client for owly-digital/pdf-api
dev-master
2023-03-14 01:35 UTC
Requires
- php: >= 7.4
- symfony/http-client: ^5.4
- symfony/mime: ^5.4
This package is auto-updated.
Last update: 2024-05-14 03:59:52 UTC
README
Working with PDF files in PHP should be headache, because you need Imagick extension, Ghostscript interpreter, etc.
So we created own API for basic PDF operations like merging, converting and stacking.
Content
Setup
Install with Composer
composer require owly-digital/pdf-api-client
Retrieve Token
You can retrieve token by contacting us at info@owly.cz
Initialization
use Owly\PdfApiClient\PdfApiClient; $client = new PdfApiClient('token');
Endpoints
List of available endpoints will change over time. You can also suggest new features by creating issue.
Merge
$pdfFiles = [ 'path/to/1.pdf', 'path/to/2.pdf', ]; $mergedPdfFile = $client->mergePdfFiles($pdfFiles); file_put_contents('merged.pdf', $mergedPdfFile);
Convert
Convert PDF files (also with multiple pages) into various formats.
Parameters:
- Formats:
jpg
,png
,webp
(defaultjpg
) - Quality: (detected automatically when omited)
jpg
: 0 - 100 (default85
)png
: 0 - 9 (default9
)webp
: (default80
)
- Resolution (in pixels per inch) (default
600
- suitable for printing)
Example
$pdfFiles = [ 'path/to/1.pdf', 'path/to/2.pdf', ]; // Basic conversion with automatically detected quality and printable resolution $convertedFiles = $client->convertPdfFiles($pdfFiles, 'jpg'); // With custom quality and resolution $convertedFiles = $client->convertPdfFiles($pdfFiles, 'jpg', 50, 300); // Conversion to webp with custom resolution (default quality) $convertedFiles = $client->convertPdfFiles($pdfFiles, 'webp', null, 300); foreach ($convertedFiles as $name => $file) { file_put_contents('/path/' . $name, base64_decode($file)); }
PDF with multiple pages
When PDF with multiple pages passed, to each page is added suffix with page number.
Input:
awesomePdfFile.pdf (3 pages)
Output:
awesomePdfFile_0.jpg
awesomePdfFile_1.jpg
awesomePdfFile_2.jpg
HTML to PDF
Basic conversion
$html = "<html><body><h1>Look At Me, I'm PDF now!</h1></body></html>"; // $pdf can be directly forwarded for download $pdf = $client->convertHtmlToPdf($html); // or with custom filename $pdf = $client->convertHtmlToPdf($html, 'awesomePdfFile.pdf');
Advanced conversion
You can customize conversion with DevTools Protocol Options
// Show footer with page numbers $options = [ 'displayHeaderFooter' => true, 'headerTemplate' => '<div></div>', 'footerTemplate' => '<div>Page: <span class="pageNumber"></span> / <span class="totalPages"></span></div>' ]; $pdf = $client->convertHtmlToPdf($html, null, $options);