abcreche/print
Composer 安装命令:
composer require abcreche/print
包简介
Generate Print Ready Document
README 文档
README
Installation
You can install this package via composer using this command:
composer require abcreche/print
The package will automatically register itself
Usage
This package uses "Print Document Template" classes to generate PDF that you can then print via the browser. These classes are filled with data that you position as you like. This is particularly helpful to fill in official document that rely on specific templates.
Make Print Templates
First, make a new print document:
php artisan make:print ReceiptTemplate
The file can be foudn in app/PrintTemplates:
.
├── app
│ ├── PrintTemplates
│ │ ├── ReceiptTemplate.php
│
└── composer.json
In your controller you can generate the PDF for this print template now:
<?php namespace App\Http\Controllers; use App\Receipt; use ABCreche\Printer\Facades\Printer; use App\PrintTemplates\ReceiptTemplate; class ReceiptController extends Controller { public function print(Receipt $receipt) { return Printer::download(new ReceiptTemplate($receipt), 'receipt.pdf'); } }
Configure Print Templates
This is how your Print Template look by default:
<?php namespace App\PrintTemplates; use App\Receipt; use ABCreche\Printer\Printer; class ReceiptTemplate implements PrintTemplate { public function build() { $this->firstPage()->write('Hello There'); } }
Manage pages and content
Every content you will add on your document needs to be associated to a page.
Because we work with printed document, positioning elements in specific pages is very important.
You can add new pages like this:
public function build() { $this->addPage(); }
You will then add content in the last page you add.
public function build() { $this->lastPage()->write('I will appear on the first page'); $this->addPage(); $this->lastPage()->write('I will appear on the second page'); }
Write data
Let's write some data on the document:
public function build() { $this->lastPage() ->write($receipt->number) ->top('10px') ->left('100px'); $this->lastPage() ->write($receipt->total) ->bottom('35px') ->right('50%'); return $this; }
You can also chain methods
public function build() { // Orders of direction is the same as in CSS for padding / margin properties return $this->lastPage() ->write($receipt->number, '10px', null, null, '100px') ->write($receipt->total, null, '35px', '50%', null); }
Orientation
You can choose the orientation of the document by setting the orientation property.
// Default: portrait // Options: 'portrait', 'landscape' protected $orientation = 'portrait';
Page Margins
You can set the page margins.
// Default: 25mm protected $pageMargin = '25mm';
Preview
You can preview any PrintTemplate by simply returning it from the controller
Route::get('printer', function () { $receipt = App\Receipt::find(1); return new App\PrintTemplates\ReceiptTemplate($receipt); });
Then you can use chrome dev tools to render the print version of the page
Image from this stackoverflow post
Then switch the dev tools to device rendering and set the dimension of the page at
- A4 : 595 x 842
Working with a preview like this will help you build your templates. When converting them to pdf, they will be exactly like the preview.
TODO
Support:
abcreche/print 适用场景与选型建议
abcreche/print 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.39k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「document」 「laravel」 「print」 「printer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 abcreche/print 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 abcreche/print 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 abcreche/print 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Invalidity check of documents in the database of Ministry of the Interior of the Czech Republic
非官方云小票机SDK,支持飞鹅云,芯烨云,易联云,快递100,映美云,中午云,佳博云,优声云,365智能云打印等
Document indexation and migration tool for Elasticsearch
Debug2 is a function developed to debug PHP code of form easy, simple, pretty print, fast and safe.
Adds a Document Management System to SilverStripe
Pacote para validar/gerar/formatar RG e CPF
统计信息
- 总下载量: 4.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-22