owly-digital / pdf-api-client
此包的最新版本(1.0.0)没有可用的许可证信息。
owly-digital/pdf-api 客户端
1.0.0
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-09-04 21:34:05 UTC
README
PDF API 客户端
在PHP中处理PDF文件可能是一个重大挑战。它不仅需要集成多种技术,还需要配置服务器。为了解决这个问题,我们开发了我们的PDF服务器,它可以无缝地处理最重要的操作。
内容
设置
使用Composer安装
composer require owly-digital/pdf-api-client
获取令牌
您可以通过发送邮件到info@owly.digital来获取令牌
初始化
use Owly\PdfApiClient\PdfApiClient; $client = new PdfApiClient('token');
端点
可用端点的列表将随着时间的推移而变化。您也可以通过创建问题来建议新功能。
合并
$pdfFiles = [ 'path/to/1.pdf', 'path/to/2.pdf', ]; $mergedPdfFile = $client->mergePdfFiles($pdfFiles); file_put_contents('merged.pdf', $mergedPdfFile);
转换
将PDF文件(包括多页)转换为各种格式。
参数
- 格式:
jpg
、png
、webp
(默认jpg
) - 质量:(省略时自动检测)
jpg
:0 - 100(默认85
)png
:0 - 9(默认9
)webp
:(默认80
)
- 分辨率(每英寸像素数)(默认
600
- 适用于打印)
示例
$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
当传递包含多页的PDF时,为每一页添加带有页码的后缀。
Input:
awesomePdfFile.pdf (3 pages)
Output:
awesomePdfFile_0.jpg
awesomePdfFile_1.jpg
awesomePdfFile_2.jpg
HTML到PDF
基本转换
$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');
高级转换
您可以使用DevTools协议选项来自定义转换。
// 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);