Skip to content

Commit 7a66227

Browse files
committed
Update README
1 parent 4fcaa46 commit 7a66227

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

README.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ use mikehaertl\pdftk\Pdf;
5959

6060
// Fill form with data array
6161
$pdf = new Pdf('/full/path/to/form.pdf');
62-
$pdf->fillForm(array(
62+
$pdf->fillForm([
6363
'name'=>'ÄÜÖ äüö мирано čárka',
6464
'nested.name' => 'valX',
65-
))
65+
])
6666
->needAppearances()
6767
->saveAs('filled.pdf');
6868

@@ -87,6 +87,7 @@ if you have special characters in your data.
8787
This is a bonus feature that is not available from `pdftk`.
8888

8989
```php
90+
use mikehaertl\pdftk\XfdfFile;
9091
use mikehaertl\pdftk\FdfFile;
9192

9293
$xfdf = new XfdfFile(['name'=>'Jürgen мирано']);
@@ -98,23 +99,23 @@ $fdf->saveAs('/path/to/data.fdf');
9899

99100
#### Cat
100101

101-
Assemble a PDF from pages of one or more PDF files.
102+
Assemble a PDF from pages from one or more PDF files.
102103

103104
```php
104105
use mikehaertl\pdftk\Pdf;
105106

106107
// Extract pages 1-5 and 7,4,9 into a new file
107108
$pdf = new Pdf('/path/to/my.pdf');
108109
$pdf->cat(1, 5)
109-
->cat(array(7, 4, 9))
110+
->cat([7, 4, 9])
110111
->saveAs('/path/to/new.pdf');
111112

112113
// Combine pages from several files, demonstrating several ways how to add files
113-
$pdf = new Pdf(array(
114-
'A' => '/path/file1.pdf', // Reference file as 'A'
115-
'B' => ['/path/file2.pdf','pass**word'], // Reference file as 'B'
116-
));
117-
$pdf->addFile('/path/file3.pdf','C','**secret**pw'); // Reference file as 'C'
114+
$pdf = new Pdf([
115+
'A' => '/path/file1.pdf', // A is alias for file1.pdf
116+
'B' => ['/path/file2.pdf','pass**word'], // B is alias for file2.pdf
117+
]);
118+
$pdf->addFile('/path/file3.pdf','C','**secret**pw'); // C is alias file3.pdf
118119
$pdf->cat(1, 5, 'A') // pages 1-5 from A
119120
->cat(3, null, 'B') // page 3 from B
120121
->cat(7, 'end', 'B', null, 'east') // pages 7-end from B, rotated East
@@ -131,10 +132,10 @@ stream at a time.
131132
```php
132133
use mikehaertl\pdftk\Pdf;
133134

134-
$pdf = new Pdf(array(
135-
'A' => '/path/file1.pdf', // Reference file as 'A'
136-
'B' => '/path/file2.pdf', // Reference file as 'B'
137-
));
135+
$pdf = new Pdf([
136+
'A' => '/path/file1.pdf', // A is alias for file1.pdf
137+
'B' => '/path/file2.pdf', // B is alias for file2.pdf
138+
]);
138139

139140
// new.pdf will have pages A1, B3, A2, B4, A3, B5, ...
140141
$pdf->shuffle(1, 5, 'A') // pages 1-5 from A
@@ -215,9 +216,16 @@ $data = $pdf->getData();
215216
// Get form data fields
216217
$pdf = new Pdf('/path/my.pdf');
217218
$data = $pdf->getDataFields();
218-
echo $data; // raw string; also can directly call $data->__toString();
219-
print_r($data); // metadata as array; also can directly call $data->__toArray();
220-
$field1Value = $data[0]['FieldValue']; // array access to a field's value
219+
220+
// Get data as string
221+
echo $data;
222+
$txt = (string) $data;
223+
$txt = $data->__toString();
224+
225+
// Get data as array
226+
$arr = (array) $data;
227+
$arr = $data->__toArray();
228+
$field1 = $data[0]['Field1'];
221229
```
222230

223231
#### How to perform more than one operation on a PDF
@@ -231,11 +239,11 @@ use mikehaertl\pdftk\Pdf;
231239
// Extract pages 1-5 and 7,4,9 into a new file
232240
$pdf = new Pdf('/path/my.pdf');
233241
$pdf->cat(1, 5)
234-
->cat(array(7, 4, 9));
242+
->cat([7, 4, 9]);
235243

236244
// We now use the above PDF as source file for a new PDF
237245
$pdf2 = new Pdf($pdf);
238-
$pdf2->fillForm(array('name'=>'ÄÜÖ äüö мирано čárka'))
246+
$pdf2->fillForm(['name'=>'ÄÜÖ äüö мирано čárka'])
239247
->needAppearances()
240248
->saveAs('/path/filled.pdf');
241249
```
@@ -264,7 +272,7 @@ $pdf->allow('AllFeatures') // Change permissions
264272
// Example: Fill PDF form and merge form data into PDF
265273
// Fill form with data array
266274
$pdf = new Pdf('/path/form.pdf');
267-
$pdf->fillForm(array('name'=>'My Name'))
275+
$pdf->fillForm(['name'=>'My Name'])
268276
->flatten()
269277
->saveAs('/path/filled.pdf');
270278

0 commit comments

Comments
 (0)