Skip to content

Commit d491237

Browse files
authored
Add printer settings (#180)
* add printer settings to docs * fix examples * wip - reorder
1 parent bd2e321 commit d491237

File tree

1 file changed

+42
-7
lines changed
  • resources/views/docs/desktop/1/the-basics

1 file changed

+42
-7
lines changed

resources/views/docs/desktop/1/the-basics/system.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ System::print('<html>...', $printer);
111111

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

114+
You can also print directly to PDF:
115+
116+
```php
117+
System::printToPDF('<html>...');
118+
```
119+
120+
This returns the PDF data in a `base64_encoded` binary string. So be sure to `base64_decode` it before storing it to
121+
disk:
122+
123+
```php
124+
use Illuminate\Support\Facades\Storage;
125+
126+
$pdf = System::printToPDF('<html>...');
127+
128+
Storage::disk('desktop')->put('My Awesome File.pdf', base64_decode($pdf));
129+
```
130+
131+
### Print Settings
132+
114133
You can change the configuration before sending something to be printed, for example if you want multiple copies:
115134

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

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

124143
```php
125-
System::printToPDF('<html>...');
144+
System::print('<html>...', $printer, $settings);
126145
```
127146

128-
This returns the PDF data in a `base64_encoded` binary string. So be sure to `base64_decode` it before storing it to
129-
disk:
147+
#### Print Settings Examples
148+
149+
You can customize print behavior using the settings array. Here are some common examples:
130150

131151
```php
132-
use Illuminate\Support\Facades\Storage;
152+
// Print with custom page size and orientation
153+
$settings = [
154+
'pageSize' => 'A4',
155+
'landscape' => true,
156+
];
133157

134-
$pdf = System::printToPDF('<html>...');
158+
System::print('<html>...', $printer, $settings);
159+
```
135160

136-
Storage::disk('desktop')->put('My Awesome File.pdf', base64_decode($pdf));
161+
```php
162+
// Print multiple copies with duplex
163+
$settings = [
164+
'copies' => 3,
165+
'duplexMode' => 'longEdge', // 'simplex', 'shortEdge', 'longEdge'
166+
'color' => false, // true for color, false for monochrome
167+
];
168+
169+
System::print('<html>...', $printer, $settings);
137170
```
138171

172+
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.
173+
139174
## Time Zones
140175

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

0 commit comments

Comments
 (0)