Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Convert HTML to an image, PDF or string

License

NotificationsYou must be signed in to change notification settings

spatie/browsershot

Repository files navigation

Social Card of Spatie's Browsershot

Convert a webpage to an image or pdf using headless Chrome

Latest VersionMIT Licensedrun-testsTotal Downloads

The package can convert a webpage to an image or pdf. The conversion is done behind the scenes byPuppeteer which controls a headless version of Google Chrome.

Here's a quick example:

useSpatie\Browsershot\Browsershot;// an image will be savedBrowsershot::url('https://example.com')->save($pathToImage);

It will save a pdf if the path passed to thesave method has apdf extension.

// a pdf will be savedBrowsershot::url('https://example.com')->save('example.pdf');

You can also use an arbitrary html input, simply replace theurl method withhtml:

Browsershot::html('<h1>Hello world!!</h1>')->save('example.pdf');

If your HTML input is already in a file locally use the :

Browsershot::htmlFromFilePath('/local/path/to/file.html')->save('example.pdf');

Browsershot also can get the body of an html page after JavaScript has been executed:

Browsershot::url('https://example.com')->bodyHtml();// returns the html of the body

If you wish to retrieve an array list with all of the requests that the page triggered you can do so:

$requests = Browsershot::url('https://example.com')    ->triggeredRequests();foreach ($requestsas$request) {$url =$request['url'];//https://example.com/}

To use Chrome's newheadless mode pass thenewHeadless method:

Browsershot::url('https://example.com')->newHeadless()->save($pathToImage);

Support us

Learn how to create a package like this one, by watching our premium video course:

Laravel Package training

We invest a lot of resources into creatingbest in class open source packages. You can support us bybuying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address onour contact page. We publish all received postcards onour virtual postcard wall.

Documentation

All documentation is availableon our documentation site.

Testing

For running the testsuite, you'll need to have Puppeteer installed. Pleaser refer to the Browsershot requirementshere. Usuallynpm -g i puppeteer will do the trick.

Additionally, you'll need thepdftotext CLI which is part of the poppler-utils package. More info can be found in in thespatie/pdf-to-text readme. Usuallybrew install poppler-utils will suffice.

Finally run the tests with:

composertest

Contributing

Please seeCONTRIBUTING for details.

Security

If you've found a bug regarding security please mailsecurity@spatie.be instead of using the issue tracker.

Alternatives

If you're not able to install Node and Puppeteer, take a look atv2 of browsershot, which uses Chrome headless CLI to take a screenshot.v2 is not maintained anymore, but should work pretty well.

If using headless Chrome does not work for you take a look at atv1 of this package which uses the abandonedPhantomJS binary.

Credits

And a special thanks toCaneco for the logo ✨

License

The MIT License (MIT). Please seeLicense File for more information.


[8]ページ先頭

©2009-2025 Movatter.jp