定制 traincase/laravel-pdf-tinker 二次开发

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

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

traincase/laravel-pdf-tinker

Composer 安装命令:

composer require traincase/laravel-pdf-tinker

包简介

Live tinkering with HTML templates for conversion to PDF.

README 文档

README

This package is meant as a tool for local development. Do not include this package in your production build.

Latest Version on Packagist Quality Score

Laravel PDF Tinker gives you a quick interface to debug and fiddle with the creation of HTML templates that will be converted into PDF's.

If you're one of those guys that frequently has to create custom templates for every client (order confirmations, goods deliveries, invoices etc.) this package is for you.

alt text

Installation

Since this package is only meant for during local development install this package as a development dependency.

composer require traincase/laravel-pdf-tinker --dev

The package will automatically register it's service provider, if you opted out of auto-discovery add something along the lines of the following to a registered service provider (for example the AppServiceProvider):

// Put this inside the 'register' method
if ($this->app->isLocal()) {
    $this->register(\Traincase\LaravelPdfTinker\PdfTinkerServiceProvider::class);
}

Don't forget to check the drivers section to see if the driver you're planning to use requires any additional set-up.

Usage

You can find most options straight in the interface of the playground. Chances are high you don't have to edit the configuration. Nevertheless, there are a few things you can configure.

Configuration

Route prefix

The service provider will register a few routes necessary to set up and run the playground. By default the routes are all prefixed with vendor/laravel-pdf-tinker. This means the playground is available at your-app.tld/vendor/laravel-pdf-tinker/playground.

Do you have an unlikely collision with your routes? No worries!

You may publish the configuration file (php artisan vendor:publish) and edit the route_prefix key in config/laravel-pdf-tinker.php to use a different prefix of your liking.

Driver options

If you published the configuration file you can also update the default_driver_options.<your-driver-alias> key to set the default options that will be set in the interface (under Configuration > Options). This will just be used when you enter the playground, you can always update the configuration inside the playground. Any changes will not be persisted once you leave the page, so if you tinker a lot you might want to override the default options.

Drivers

Currently there are two drivers available.

DomPDF

DomPdf is the easiest driver to get started. Everything should already be in place after following the installation instructions.

Happy tinkering!

Wkhtmltopdf

The wkhtmltopdf driver needs the wkhtmltopdf executable to be available in your PATH. This means that if you run wkhtmltopdf --version in a terminal it should output something like the following:

$ wkhtmltopdf --version
wkhtmltopdf 0.12.5 (with patched qt)

If you're using mac&homebrew you can run brew cask install wkhtmltopdf. On any other system download the binaries for your system from the wkhtmltopdf website.

Creating your own drivers

It's possible to create a driver of the HTML2PDF generation library of your choice. Simply create your driver and register it with the PdfTinkerManager.

  1. First things first, this is the time to create your driver. Your driver should extend \Traincase\HtmlToPdfTinker\Drivers\Driver. You can take an example from Traincase\LaravelPdfTinker\DompdfDriver.
  2. Register it with the PdfTinkerManager. Add the following lines to one of your registered service providers in the boot method.
    public function boot()
    {
        if ($this->app->isLocal()) {
            $this->app->resolving(\Traincase\HtmlToPdfTinker\PdfTinkerManager::class, function($manager) {
                $manager->extend('test-driver', function() {
                    // Need to fetch some things from the container? Sure.
                    $dependency = $this->app->make(\SomeFancyClass::class);
      
                    return new \App\Drivers\YourFancyDriver($dependency);
                });
            });
        }
    }
  3. Your driver will automatically show up in the interface in the drivers dropdown, you're free to tinker!

Ready, set...

If you followed all the installation instructions go ahead and tinker away! Open up your browser and navigate to your-app.tld/vendor/laravel-pdf-tinker/playground.

traincase/laravel-pdf-tinker 适用场景与选型建议

traincase/laravel-pdf-tinker 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 44, 最近一次更新时间为 2020 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「pdf」 「html」 「laravel」 「html2pdf」 「preview」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 traincase/laravel-pdf-tinker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 traincase/laravel-pdf-tinker 我们能提供哪些服务?
定制开发 / 二次开发

基于 traincase/laravel-pdf-tinker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 44
  • Watchers: 3
  • Forks: 4
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-26