Skip to content

Commit

Permalink
Issue #281 Implement replacementFont($font) (requires pdftk-java >=…
Browse files Browse the repository at this point in the history
… 3.3.0)
  • Loading branch information
mikehaertl committed Apr 2, 2022
1 parent 61ba14c commit 528b3a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ This will make sure, that the PDF reader takes care of using the right fonts for
something that pdftk can't do for you. Also note that `flatten()` doesn't really work well
if you have special characters in your data.

If you use `pdftk-java` >= 3.3.0 and the embedded font does not support UTF-8
characters you can also replace it with a local font:

```php
use mikehaertl\pdftk\Pdf;

// Fill form with data array
$pdf = new Pdf('/full/path/to/form.pdf');
$result = $pdf->fillForm($data)
->replacementFont('/usr/share/fonts/dejavu/DejaVuSans.ttf')
->saveAs('filled.pdf');
```

#### Create a XFDF/FDF file from a PHP array

This is a bonus feature that is not available from `pdftk`.
Expand Down
17 changes: 17 additions & 0 deletions src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,23 @@ public function passwordEncryption($strength = 128)
return $this;
}

/**
* Replace embedded font with a local font when filling a form.
*
* This option is only available for pdftk-java >= 3.3.0. It is useful when
* filling a form with non-ASCII text that is not supported by the fonts
* included in the input PDF.
*
* @param string $fontName the path to the font or the name of a font family.
* @return Pdf the pdf instance for method chaining
*/
public function replacementFont($path)
{
$this->getCommand()
->addOption('replacement_font', $path);
return $this;
}

/**
* Execute the operation and save the output file
*
Expand Down

0 comments on commit 528b3a5

Please sign in to comment.