@@ -51,14 +51,42 @@ composer require mikehaertl/php-pdftk
51
51
52
52
## Examples
53
53
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
+
54
85
### Operations
55
86
56
87
Please consult the ` pdftk ` man page for each operation to find out how each operation works
57
88
in detail and which options are available.
58
89
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
-
62
90
For all operations you can either save the PDF locally through ` saveAs($name) ` or send it to the
63
91
browser with ` send() ` . If you pass a filename to ` send($name) ` the client browser will open a download
64
92
dialogue whereas without a filename it will usually display the PDF inline.
@@ -132,12 +160,12 @@ if ($result === false) {
132
160
$error = $pdf->getError();
133
161
}
134
162
135
- // Combine pages from several files, demonstrating several ways how to add files
163
+ // Combine pages from several files
136
164
$pdf = new Pdf([
137
165
'A' => '/path/file1.pdf', // A is alias for file1.pdf
138
166
'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
139
168
]);
140
- $pdf->addFile('/path/file3.pdf','C','**secret**pw'); // C is alias file3.pdf
141
169
$result = $pdf->cat(1, 5, 'A') // pages 1-5 from A
142
170
->cat(3, null, 'B') // page 3 from B
143
171
->cat(7, 'end', 'B', null, 'east') // pages 7-end from B, rotated East
0 commit comments