Skip to content

Add printer settings #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions resources/views/docs/desktop/1/the-basics/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ System::print('<html>...', $printer);

If no `$printer` object is provided, the default printer and settings will be used.

You can also print directly to PDF:

```php
System::printToPDF('<html>...');
```

This returns the PDF data in a `base64_encoded` binary string. So be sure to `base64_decode` it before storing it to
disk:

```php
use Illuminate\Support\Facades\Storage;

$pdf = System::printToPDF('<html>...');

Storage::disk('desktop')->put('My Awesome File.pdf', base64_decode($pdf));
```

### Print Settings

You can change the configuration before sending something to be printed, for example if you want multiple copies:

```php
Expand All @@ -119,23 +138,39 @@ $printer->options['copies'] = 5;
System::print('<html>...', $printer);
```

You can also print directly to PDF:
Additionally, both the `print()` and `printToPDF()` methods accept an optional `$settings` parameter that allows you to customize the print behavior:

```php
System::printToPDF('<html>...');
System::print('<html>...', $printer, $settings);
```

This returns the PDF data in a `base64_encoded` binary string. So be sure to `base64_decode` it before storing it to
disk:
#### Print Settings Examples

You can customize print behavior using the settings array. Here are some common examples:

```php
use Illuminate\Support\Facades\Storage;
// Print with custom page size and orientation
$settings = [
'pageSize' => 'A4',
'landscape' => true,
];

$pdf = System::printToPDF('<html>...');
System::print('<html>...', $printer, $settings);
```

Storage::disk('desktop')->put('My Awesome File.pdf', base64_decode($pdf));
```php
// Print multiple copies with duplex
$settings = [
'copies' => 3,
'duplexMode' => 'longEdge', // 'simplex', 'shortEdge', 'longEdge'
'color' => false, // true for color, false for monochrome
];

System::print('<html>...', $printer, $settings);
```

For a complete list of available print settings, refer to the [Electron webContents.print()](https://www.electronjs.org/docs/latest/api/web-contents#contentsprintoptions-callback) and [webContents.printToPDF()](https://www.electronjs.org/docs/latest/api/web-contents#contentsprinttopdfoptions) documentation.

## Time Zones

PHP and your Laravel application will generally be configured to work with a specific time zone. This could be UTC, for
Expand Down