From b1db41c52fad59b6a1747b06a97956069099a1fc Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Wed, 9 Jul 2025 16:17:33 +0200 Subject: [PATCH 1/3] add printer settings to docs --- .../views/docs/desktop/1/the-basics/system.md | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/resources/views/docs/desktop/1/the-basics/system.md b/resources/views/docs/desktop/1/the-basics/system.md index 38674211..61c044e7 100644 --- a/resources/views/docs/desktop/1/the-basics/system.md +++ b/resources/views/docs/desktop/1/the-basics/system.md @@ -111,6 +111,14 @@ System::print('...', $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('...'); +``` + +### Print Settings + You can change the configuration before sending something to be printed, for example if you want multiple copies: ```php @@ -119,12 +127,40 @@ $printer->options['copies'] = 5; System::print('...', $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('...'); +System::print('...', $printer, $settings); ``` +#### Print Settings Examples + +You can customize print behavior using the settings array. Here are some common examples: + +```php +// Print with custom page size and orientation +$settings = [ + 'pageSize' => 'A4', + 'landscape' => true, + 'marginsType' => 1, // 0: default, 1: none, 2: minimum +]; + +System::print('...', $printer, $settings); +``` + +```php +// Print multiple copies with duplex +$settings = [ + 'copies' => 3, + 'duplex' => 'long', // 'simplex', 'short', 'long' + 'color' => false, // true for color, false for monochrome +]; + +System::print('...', $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. + This returns the PDF data in a `base64_encoded` binary string. So be sure to `base64_decode` it before storing it to disk: From dc1eb4e04973a7b9af28fcd3648de8f07087004f Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Wed, 9 Jul 2025 16:22:44 +0200 Subject: [PATCH 2/3] fix examples --- resources/views/docs/desktop/1/the-basics/system.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/resources/views/docs/desktop/1/the-basics/system.md b/resources/views/docs/desktop/1/the-basics/system.md index 61c044e7..9097ec9f 100644 --- a/resources/views/docs/desktop/1/the-basics/system.md +++ b/resources/views/docs/desktop/1/the-basics/system.md @@ -142,7 +142,6 @@ You can customize print behavior using the settings array. Here are some common $settings = [ 'pageSize' => 'A4', 'landscape' => true, - 'marginsType' => 1, // 0: default, 1: none, 2: minimum ]; System::print('...', $printer, $settings); @@ -152,7 +151,7 @@ System::print('...', $printer, $settings); // Print multiple copies with duplex $settings = [ 'copies' => 3, - 'duplex' => 'long', // 'simplex', 'short', 'long' + 'duplexMode' => 'longEdge', // 'simplex', 'shortEdge', 'longEdge' 'color' => false, // true for color, false for monochrome ]; From 1be63adb2b741d494e5ee460660b3657257d2c24 Mon Sep 17 00:00:00 2001 From: gwleuverink Date: Wed, 9 Jul 2025 16:25:37 +0200 Subject: [PATCH 3/3] wip - reorder --- .../views/docs/desktop/1/the-basics/system.md | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/resources/views/docs/desktop/1/the-basics/system.md b/resources/views/docs/desktop/1/the-basics/system.md index 9097ec9f..2717146c 100644 --- a/resources/views/docs/desktop/1/the-basics/system.md +++ b/resources/views/docs/desktop/1/the-basics/system.md @@ -117,6 +117,17 @@ You can also print directly to PDF: System::printToPDF('...'); ``` +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('...'); + +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: @@ -160,17 +171,6 @@ System::print('...', $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. -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('...'); - -Storage::disk('desktop')->put('My Awesome File.pdf', base64_decode($pdf)); -``` - ## Time Zones PHP and your Laravel application will generally be configured to work with a specific time zone. This could be UTC, for