verumconsilium/laravel-browsershot
Composer 安装命令:
composer require verumconsilium/laravel-browsershot
包简介
Browsershot Laravel wrapper to generate PDF files and Screenshots using Headless Chrome
README 文档
README
This package takes advantage of Google Chrome's Headless mode to take screenshots and generate PDFs from websites, views and raw html
Requirements
- Node 7.6.0 or higher
- Google Chrome
- Puppeteer Node library.
You can install Puppeteer in your project via NPM:
npm install puppeteer
Or you could opt to just install it globally
npm install puppeteer --global
On a Forge provisioned Ubuntu 16.04 server you can install the latest stable version of Chrome like this:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
sudo npm install --global --unsafe-perm puppeteer
sudo chmod -R o+rx /usr/lib/node_modules/puppeteer/.local-chromium
Installation
Install the package through composer
composer require verumconsilium/laravel-browsershot
After the package is installed the service provider will be automatically discovered and two new Facades PDF and Screenshot will be available
Usage
The recommended way to use this package is through its Facades
Generating a PDF from a view and returning it inline
use VerumConsilium\Browsershot\Facades\PDF; ... return PDF::loadView('view.name', $data) ->inline();
You can chain all the methods available in the browsershot master library
Returning the PDF as a download
use VerumConsilium\Browsershot\Facades\PDF; ... return PDF::loadView('view.name', $data) ->margins(20, 0, 0, 20) ->download();
You can pass the custom file name and additional headers the response will have to the inline and download methods like
PDF::loadHtml('<h1>Awesome PDF</h1>') ->download('myawesomepdf.pdf', [ 'Authorization' => 'token' ]);
Persisting PDF to disk
If you would like to save the generated pdf file to your storage disk you can call the store or storeAs method
$pdfStoredPath = PDF::loadUrl('https://google.com') ->store('pdfs/')
This will use the default storage driver to store the pdf in the pdfs/ folder giving it a unique name. If you would like to specify the name you can call de storeAs method
$pdfStoredPath = PDF::loadUrl('https://google.com') ->storeAs('pdfs/', 'google.pdf')
Screenshots
Screenshots are created the same way as PDFs just change the facade to Screenshot
Generating screenshots as JPG/JPEG
By default screenshots will be taken as PNG format if you would like to use JPG instead call the useJPG() method
use VerumConsilium\Browsershot\Facades\Screenshot; Screenshot::loadView('view.name', $data) ->useJPG() ->margins(20, 0, 0, 20) ->download();
verumconsilium/laravel-browsershot 适用场景与选型建议
verumconsilium/laravel-browsershot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 479.92k 次下载、GitHub Stars 达 109, 最近一次更新时间为 2018 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 verumconsilium/laravel-browsershot 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 verumconsilium/laravel-browsershot 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 479.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 112
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-04