Download the PHP package eduardoribeirodev/browsershot without Composer
On this page you can find all versions of the php package eduardoribeirodev/browsershot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eduardoribeirodev/browsershot
More information about eduardoribeirodev/browsershot
Files in eduardoribeirodev/browsershot
Package browsershot
Short Description This is my package browsershot
License MIT
Homepage https://github.com/eduardoribeirodev/browsershot
Informations about the package browsershot
Laravel Browsershot Service
A fluent Laravel wrapper for Spatie's Browsershot package that simplifies generating screenshots and PDFs from HTML content or Blade views.
Features
- 🎨 Generate PDFs and screenshots from Blade views, HTML strings, or URLs
- 📐 Flexible sizing with unit support (px, mm, cm, in) and aspect ratio helpers
- 📄 Named paper format shortcuts (A0–A6, Letter, Legal, Tabloid, Ledger)
- 🔧 Fluent, chainable API
- 💾 Multiple output options (download, save to storage, base64)
- 🚀 Automatic HTML structure wrapping
- ⚡ High-resolution output with device scale factor support
Installation
Prerequisites
This package requires Puppeteer/Chromium to be installed. Follow Spatie's Browsershot installation guide for your environment.
Configuration
Add the Chrome path to your config/services.php:
Set the path in your .env file:
Basic Usage
Generate PDF from Blade View
Generate Screenshot from HTML
Download PDF in a Controller
API Reference
Initialization
make(View|string $content, array $data = []): self
Creates a new instance. Accepts a Blade View object, a view name string, a URL, or a raw HTML string.
Size & Viewport
size(int $width, int $height, string $unit = 'px'): self
Sets the viewport/paper dimensions. Supported units: px, mm, cm, in.
center(int $x, int $y): self
Sets the clip origin. Must be combined with size().
clip(int $x, int $y, int $width, int $height): self
Shorthand for setting both center and size at once.
scale(float $scale): self
Sets the device scale factor for high-resolution output.
aspectRatio(string|float $ratio): self
Adjusts the current size to match a given aspect ratio. Must call size() first.
Paper Format Shortcuts
These methods set the viewport to a standard paper size (in mm). An optional $scale multiplier can be passed to format().
format(string $format, float $scale = 1): self
Named shortcuts (equivalent to calling format() with the matching name):
| Method | Dimensions (mm) |
|---|---|
a0() |
841 × 1189 |
a1() |
594 × 841 |
a2() |
420 × 594 |
a3() |
297 × 420 |
a4() |
210 × 297 |
a5() |
148 × 210 |
a6() |
105 × 148 |
letter() |
216 × 279 |
legal() |
216 × 356 |
tabloid() |
279 × 432 |
ledger() |
432 × 279 |
Orientation
landscape(bool $landscape = true): self
portrait(): self
Margins
margin(int $size, string $unit = 'mm'): self
Applies a uniform margin to all four sides.
margins(int $top, int $right, int $bottom, int $left, string $unit = 'mm'): self
Sets each margin individually in one call.
marginTop / marginRight / marginBottom / marginLeft
Fluent per-side setters.
Output Format
pdf(): self
png(): self
jpeg(): self
webp(): self
extension(string $extension): self
Sets the output file format. The named helpers are shorthands for extension().
PDF-Specific Options
pages(...$pages): self
Selects specific pages (or page ranges) to include in the PDF output.
Sandbox
noSandbox(bool $noSandbox = true): self
Disables Chrome's sandbox — required in most Docker/CI environments.
Advanced Customization
modifyBrowsershotUsing(Closure $callback): self
Provides direct access to the underlying Spatie\Browsershot\Browsershot instance for options not exposed by this wrapper.
Output Methods
generate(): string
Returns the raw binary content.
download(?string $fileName = null): StreamedResponse
Streams the file as a browser download. The correct extension is appended automatically if missing.
save(string $path, ?string $disk = null): bool
Saves to Laravel's filesystem. Uses the default disk when $disk is omitted.
toBase64(): string
Returns the content as a base64-encoded string.
HTML Structure Handling
The service automatically wraps partial HTML in a complete document structure:
| Input | Output |
|---|---|
<h1>Title</h1> (fragment) |
Full document: DOCTYPE + <html> + <head> + <body> |
<head>…</head><body>…</body> |
Wraps with DOCTYPE + <html> |
<body>…</body> |
Adds DOCTYPE, <html>, and <head> |
<!DOCTYPE html><html>…</html> |
Used as-is |
Advanced Examples
A4 Invoice PDF
High-Resolution Social Media Image
Certificate with Clip Region
Thumbnail as Base64
Batch Report Generation
Custom Browsershot Options
Testing
Troubleshooting
Chrome/Chromium Not Found
Permission Issues in Docker
Memory Issues with Large PDFs
Performance Tips
- Cache generated content when possible
- Use queues for batch generation
- Optimize Blade views — minimize CSS/JS complexity
- Set appropriate sizes — don't generate larger than needed
- Choose the right format — JPEG is smaller than PNG for photographic content
License
This package is open-sourced software licensed under the MIT license.
Credits
- Built on top of Spatie Browsershot
- Developed by Eduardo Ribeiro
Support
For issues, questions, or contributions, please visit the GitHub repository.