定制 pdf-api-io/pdfapi-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pdf-api-io/pdfapi-laravel

最新稳定版本:v1.0.0

Composer 安装命令:

composer require pdf-api-io/pdfapi-laravel

包简介

This is my package pdfapi-laravel

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides a Laravel integration for PDF-API.io. PDF-API.io is a service that allows you to design your PDF templates in a drag-and-drop editor and render them using a simple API.

Installation

You can install the package via composer:

composer require pdf-api-io/pdfapi-laravel

You can publish the config file with:

php artisan vendor:publish --tag="pdfapi-laravel-config"

This is the contents of the published config file:

return [
    'api_key' => env('PDF_API_KEY'),
];

Create an access token if you don't have one yet. You can do this visiting the PDF-API.io API token page. Add the following line to your .env file:

PDF_API_KEY=your-api-key

Usage

You can read the full documentation on the PDF-API.io website.

List available templates

To list all available templates, you can use the getTemplates method on the PdfApi facade.

use Pdfapiio\PdfapiLaravel\Facades\PdfApi;

$templates = PdfApi::getTemplates();

Render a PDF

To render a PDF, you can use the render method.

use Pdfapiio\PdfapiLaravel\Facades\PdfApi;

$pdf = PdfApi::render('your-template-id', [
    'some-variable' => 'some-value',
]);

echo $pdf; // Output: "%PDF-1.7 %���� 6 0 obj << /Type /Page /Parent 1 0 R..."

By default, the render method will return the content of the PDF as a string. If you want to get a JSON response instead, you can use the asJson method. When JSON response is requested, the content of the PDF will be base64 encoded.

use Pdfapiio\PdfapiLaravel\Facades\PdfApi;

$pdf = PdfApi::asJson()->render('your-template-id', [
    'some-variable' => 'some-value',
]);

$content = base64_decode($pdf['data']);

You can control the output by calling the output method:

use Pdfapiio\PdfapiLaravel\Facades\PdfApi;

PdfApi::output(ApiOutputType::PDF)->render('your-template', []); // Returns the PDF as a string
PdfApi::output(ApiOutputType::URL)->render('your-template', []); // Returns the URL to the rendered PDF

Merge templates

If you have multiple templates and you want to merge them into a single PDF, you can use the merge method.

use Pdfapiio\PdfapiLaravel\Facades\PdfApi;

$pdf = PdfApi::merge([
    [
        'id' => 'your-template-id',
        'data' => [
            'some-variable' => '
        ],
    ],
    [
        'id' => 'your-template-id',
        'data' => [
            'some-variable' => '
        ],
    ],
]);

You can also use the asJson and output methods with the merge method.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-21