iupemai92/laravel-google-cloud-print
Composer 安装命令:
composer require iupemai92/laravel-google-cloud-print
包简介
Google Cloud Print Service Provider for Laravel 5
README 文档
README
Install
Via composer :
composer require bnbwebexpertise/laravel-google-cloud-print
Then add the service provider class to your Laravel config/app.php :
'providers' => [
// ...
Bnb\GoogleCloudPrint\LaravelServiceProvider::class,
// ...
],
Also add the Facade alias if you intend to use it :
'aliases' => [
// ...
'GoogleCloudPrint' => Bnb\GoogleCloudPrint\Facades\GoogleCloudPrint::class,
// ...
],
Configuration
Set the env parameter GCP_CREDENTIALS_PATH to the absolute path
(or relative to the laravel application root) of the servie account
JSON file downloaded from Google Console.
Google service setup
Create a service account key (IAM) with a ***@re-speedy-diagnostic.iam.gserviceaccount.com
and download the JSON key file at https://console.developers.google.com/apis/credentials.
Copy the file into the project at the configured env path.
You also need to allow print access to the generated email address on all the desired printers via the Google Cloud Print console at https://www.google.com/cloudprint/#printers.
This library will attempt to accept the invite if the Google API rejects the credentials. Indeed Google service accounts do not get the invitation email with the accept link and therefore need to use the API to complete the process.
Usage
Create a print task
Either use the Facade or the shortcut with one of the three provided content type to get a print task object :
$task = GoogleCloudPrint::asText()
$task = GoogleCloudPrint::asHtml()
$task = GoogleCloudPrint::asPdf()
// or
$task = app('google.print')->asText()
$task = app('google.print')->asHtml()
$task = app('google.print')->asPdf()
Configure and send the print task
Calling ->printer($printerId) is required. The $printerId is the
printer's UUID you get on the printer details page at Google Cloud Print
console (or in the printer URL).
The content can be provided in three way :
- raw via
->content('A raw content'). - local file via
->file('/path/to/my/file'). An exception is thrown if the file is not accessible - url via
->url('http://acme.foo/bar'). The content is downloaded locally before sending the print job. An exception is thrown if the URL does not begin withhttp(s)://
You can set any other Cloud Job Ticket option via the ->ticket($key, $value) method.
Some helpers are provided :
- range helper via
->range($start, $end)(start and end pages are included). - margins helpers via the
->marginsInMillimeters($top, $right, $bottom, $left)and->marginsInCentimeters($top, $right, $bottom, $left).
If the job is rejected an exception is thrown.
Examples
$printerId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
// Printing HTML from an URL
GoogleCloudPrint::asHtml()
->url('https://opensource.org/licenses/MIT')
->printer($printerId)
->send();
// Printing page 3 to 10 of a PDF from a local file
GoogleCloudPrint::asPdf()
->file('storage/document.pdf')
->range(3, 10)
->printer($printerId)
->send();
// Printing plain text with a 1cm margin on each sides using
GoogleCloudPrint::asText()
->content('This is a test')
->printer($printerId)
->marginsInCentimeters(1, 1, 1, 1)
->send();
iupemai92/laravel-google-cloud-print 适用场景与选型建议
iupemai92/laravel-google-cloud-print 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 235 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 iupemai92/laravel-google-cloud-print 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iupemai92/laravel-google-cloud-print 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 235
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-06