Skip to content

Commit a8d7158

Browse files
committed
Issue #225 Improve docs on how to add files with password
1 parent 84720d0 commit a8d7158

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

README.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,42 @@ composer require mikehaertl/php-pdftk
5151

5252
## Examples
5353

54+
### Create instance for PDF files
55+
56+
There are several ways to tell the `Pdf` instance which file(s) it should use.
57+
Some files may also require a password or need an alias to be used as a handle
58+
in some operations (e.g. cat or shuffle).
59+
60+
> **Note:** In version 2.x of pdftk a handle can be one or more upper case letters.
61+
62+
```php
63+
// Create an instance for a single file
64+
$pdf = new Pdf('/path/to/form.pdf');
65+
66+
// Alternatively add files later. Handles are autogenerated in this case.
67+
$pdf = new Pdf();
68+
$pdf->addFile('/path/to/file1.pdf');
69+
$pdf->addFile('/path/to/file2.pdf');
70+
71+
// Add files with own handle
72+
$pdf = new Pdf();
73+
$pdf->addFile('/path/to/file1.pdf', 'A');
74+
$pdf->addFile('/path/to/file2.pdf', 'B');
75+
// Add file with handle and password
76+
$pdf->addFile('/path/to/file3.pdf', 'C', 'secret*password');
77+
78+
// Shortcut to pass all files to the constructor
79+
$pdf = new Pdf([
80+
'A' => ['/path/to/file1.pdf', 'secret*password1'],
81+
'B' => ['/path/to/file2.pdf', 'secret*password2'],
82+
]);
83+
```
84+
5485
### Operations
5586

5687
Please consult the `pdftk` man page for each operation to find out how each operation works
5788
in detail and which options are available.
5889

59-
> **Note:** Some commands allow to alias your files with a handle (see examples below).
60-
> In version 2.x of pdftk a handle can be one or more upper case letters.
61-
6290
For all operations you can either save the PDF locally through `saveAs($name)` or send it to the
6391
browser with `send()`. If you pass a filename to `send($name)` the client browser will open a download
6492
dialogue whereas without a filename it will usually display the PDF inline.
@@ -132,12 +160,12 @@ if ($result === false) {
132160
$error = $pdf->getError();
133161
}
134162

135-
// Combine pages from several files, demonstrating several ways how to add files
163+
// Combine pages from several files
136164
$pdf = new Pdf([
137165
'A' => '/path/file1.pdf', // A is alias for file1.pdf
138166
'B' => ['/path/file2.pdf','pass**word'], // B is alias for file2.pdf
167+
'C' => ['/path/file3.pdf','secret**pw'], // C is alias for file3.pdf
139168
]);
140-
$pdf->addFile('/path/file3.pdf','C','**secret**pw'); // C is alias file3.pdf
141169
$result = $pdf->cat(1, 5, 'A') // pages 1-5 from A
142170
->cat(3, null, 'B') // page 3 from B
143171
->cat(7, 'end', 'B', null, 'east') // pages 7-end from B, rotated East

0 commit comments

Comments
 (0)