@@ -10,12 +10,6 @@ php-pdftk
10
10
11
11
A PDF conversion and form utility based on pdftk.
12
12
13
- ** The ` pdftk ` command must be installed and working on your system.**
14
-
15
- > Note: This library is written for pdftk 2.x versions. You should be able to
16
- > use it with pdftk 1.x but not all methods will work there. For details consult
17
- > the man page of pdftk on your system.
18
-
19
13
## Features
20
14
21
15
* php-pdftk* brings the full power of ` pdftk ` to PHP - and more.
@@ -29,6 +23,12 @@ A PDF conversion and form utility based on pdftk.
29
23
* Read out meta data about PDF and form fields
30
24
* Set passwords and permissions
31
25
26
+ ## Requirements
27
+
28
+ * The ` pdftk ` command must be installed and working on your system
29
+ * This library is written for pdftk 2.x versions. You should be able to use it with pdftk 1.x but not all methods will work there.
30
+ For details consult the man page of pdftk on your system.
31
+
32
32
## Installation
33
33
34
34
You should use use [ composer] ( https://getcomposer.org/ ) to install this library.
@@ -44,13 +44,13 @@ composer require mikehaertl/php-pdftk
44
44
Please consult the ` pdftk ` man page for each operation to find out how each operation works
45
45
in detail and which options are available.
46
46
47
- > Note: You can always only perform ** one** of the following operations on a single PDF instance.
48
- > Below you can find a workaround if you need multiple operations.
49
-
50
47
For all operations you can either save the PDF locally through ` saveAs($name) ` or send it to the
51
48
browser with ` send() ` . If you pass a filename to ` send($name) ` the client browser will open a download
52
49
dialogue whereas without a filename it will usually display the PDF inline.
53
50
51
+ ** IMPORTANT:** You can always only perform ** one** of the following operations on a single PDF instance.
52
+ Below you can find a workaround if you need multiple operations.
53
+
54
54
#### Fill Form
55
55
56
56
Fill a PDF form with data from a PHP array or an XFDF/FDF file.
@@ -70,13 +70,14 @@ $pdf->fillForm('data.xfdf')
70
70
->saveAs('filled.pdf');
71
71
```
72
72
73
- > Note: When filling in UTF-8 data, you should always add the needAppearances() option.
74
- > This will make sure, that the PDF reader takes care of using the right fonts for rendering,
75
- > something that pdftk can't do for you.
73
+ ** Note:** When filling in UTF-8 data, you should always add the ` needAppearances() ` option.
74
+ This will make sure, that the PDF reader takes care of using the right fonts for rendering,
75
+ something that pdftk can't do for you. Also note that ` flatten() ` doesn't really work well
76
+ if you have special characters in your data.
76
77
77
78
#### Create a XFDF/FDF file from a PHP array
78
79
79
- > Note: This is a bonus feature that is not available from ` pdftk ` .
80
+ This is a bonus feature that is not available from ` pdftk ` .
80
81
81
82
``` php
82
83
use mikehaertl\pdftk\FdfFile;
@@ -123,11 +124,12 @@ stream at a time.
123
124
``` php
124
125
use mikehaertl\pdftk\Pdf;
125
126
126
- // new.pdf will have pages A1, B3, A2, B4, A3, B5, ...
127
127
$pdf = new Pdf(array(
128
128
'A' => 'file1.pdf', // Reference file as 'A'
129
129
'B' => 'file2.pdf', // Reference file as 'B'
130
130
));
131
+
132
+ // new.pdf will have pages A1, B3, A2, B4, A3, B5, ...
131
133
$pdf->shuffle(1, 5, 'A') // pages 1-5 from A
132
134
->shuffle(3, 8, 'B') // pages 3-8 from B
133
135
->saveAs('new.pdf');
@@ -238,7 +240,7 @@ use mikehaertl\pdftk\Pdf;
238
240
$pdf = new Pdf('my.pdf');
239
241
240
242
$pdf->allow('AllFeatures') // Change permissions
241
- ->flatten() // Merge form data into document
243
+ ->flatten() // Merge form data into document (doesn't work well with UTF-8!)
242
244
->compress($value) // Compress/Uncompress
243
245
->keepId('first') // Keep first/last Id of combined files
244
246
->dropXfa() // Drop newer XFA form from PDF
@@ -262,6 +264,8 @@ $pdf->addPage('my.pdf', null, 'some**password')
262
264
->saveAs('new.pdf');
263
265
```
264
266
267
+ ### Execution
268
+
265
269
The class uses [ php-shellcommand] ( https://github.com/mikehaertl/php-shellcommand ) to execute
266
270
` pdftk ` . You can pass ` $options ` for its ` Command ` class as second argument to the constructor:
267
271
@@ -270,7 +274,7 @@ use mikehaertl\pdftk\Pdf;
270
274
271
275
$pdf = new Pdf('my.pdf', [
272
276
'command' => '/some/other/path/to/pdftk',
273
- 'useExec' => true,
277
+ 'useExec' => true, // May help on Windows systems if execution fails
274
278
]);
275
279
```
276
280
0 commit comments