koffleart / browsershot
使用无头Chrome将网页转换为图像或PDF
Requires
- php: ^7.1
- spatie/image: ^1.5.3
- spatie/temporary-directory: ^1.1
- symfony/process: ^4.2|^5.0
Requires (Dev)
- phpunit/phpunit: ^6.1|^7.5
- spatie/phpunit-snapshot-assertions: ^1.0
- dev-master
- 3.37.0
- 3.36.0
- 3.35.0
- 3.34.0
- 3.33.1
- 3.33.0
- 3.32.2
- 3.32.1
- 3.32.0
- 3.31.1
- 3.31.0
- 3.30.0
- 3.29.0
- 3.27.0
- 3.26.3
- 3.26.2
- 3.26.1
- 3.26.0
- 3.25.1
- 3.25.0
- 3.24.0
- 3.23.1
- 3.23.0
- 3.22.1
- 3.22.0
- 3.20.1
- 3.20.0
- 3.19.0
- 3.18.0
- 3.17.0
- 3.16.1
- 3.16.0
- 3.15.0
- 3.14.1
- 3.14.0
- 3.13.0
- 3.12.0
- 3.11.1
- 3.11.0
- 3.10.0
- 3.9.0
- 3.8.1
- 3.8.0
- 3.7.0
- 3.6.0
- 3.5.0
- 3.4.0
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- v2.x-dev
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.9.1
- 1.9.0
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-github-actions
This package is auto-updated.
Last update: 2024-09-07 17:29:05 UTC
README
使用无头Chrome将网页转换为图像或PDF
该包可以将网页转换为图像或PDF。转换由Puppeteer在后台完成,它控制Google Chrome的无头版本。
以下是一个快速示例
use Spatie\Browsershot\Browsershot; // an image will be saved Browsershot::url('https://example.com')->save($pathToImage);
如果传递给save方法的路径具有pdf扩展名,则将保存PDF。
// a pdf will be saved Browsershot::url('https://example.com')->save('example.pdf');
您也可以使用任意的HTML输入,只需将url方法替换为html
Browsershot::html('<h1>Hello world!!</h1>')->save('example.pdf');
如果您的HTML输入已经在本地文件中,请使用
Browsershot::htmlFromFilePath('/local/path/to/file.html')->save('example.pdf');
Browsershot还可以在JavaScript执行后获取HTML页面的主体
Browsershot::url('https://example.com')->bodyHtml(); // returns the html of the body
如果您希望检索页面触发的所有请求的数组列表,则可以这样做
$requests = Browsershot::url('https://example.com') ->triggeredRequests(); foreach ($requests as $request) { $url = $request['url']; //https://example.com/ }
要使用Chrome的新无头模式,请传递newHeadless方法
Browsershot::url('https://example.com')->newHeadless()->save($pathToImage);
支持我们
通过观看我们的付费视频课程,了解如何创建此类包
我们在创建一流的开源包上投入了大量资源。您可以通过购买我们的付费产品之一来支持我们。
我们非常感谢您从您的家乡寄来明信片,注明您正在使用我们哪个包。您可以在我们的联系页面上找到我们的地址。我们将在我们的虚拟明信片墙上发布收到的所有明信片。
文档
所有文档都可以在我们的文档网站上找到。
贡献
有关详细信息,请参阅CONTRIBUTING
安全
如果您发现有关安全性的错误,请通过security@spatie.be发送邮件,而不是使用问题跟踪器。
替代方案
如果您无法安装Node和Puppeteer,请查看browsershot的v2版本,它使用Chrome无头CLI进行截图。 v2不再维护,但应该表现良好。
如果您无法使用无头Chrome,请查看此包的v1版本,它使用已废弃的PhantomJS二进制文件。
致谢
特别感谢Caneco为我们提供的标志 ✨
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。
