public function LocalServerPdfBackend::mergeFile in FillPDF 8.4
Same name and namespace in other branches
- 5.0.x src/Plugin/PdfBackend/LocalServerPdfBackend.php \Drupal\fillpdf\Plugin\PdfBackend\LocalServerPdfBackend::mergeFile()
Populate a PDF file with field data.
Parameters
\Drupal\file\FileInterface $template_file: The PDF template the field values specified in the mapping should be merged into.
\Drupal\fillpdf\FieldMapping[] $field_mappings: An array of FieldMapping objects mapping PDF field keys to the values they should be replaced with. Example:
[
'Foo' => new TextFieldMapping('bar'),
'Foo2' => new TextFieldMapping('bar2'),
'Image1' => new ImageFieldMapping(base64_encode(file_get_contents($image)), 'jpg'),
];
array $context: The request context as returned by FillPdfLinkManipulator::parseLink().
Return value
string|null The raw file contents of the new PDF, or NULL if merging failed. The caller has to handle saving or serving the file accordingly.
Overrides PdfBackendInterface::mergeFile
See also
\Drupal\fillpdf\Plugin\PdfBackendInterface::mergeStream()
1 call to LocalServerPdfBackend::mergeFile()
- LocalServerPdfBackend::populateWithFieldData in src/
Plugin/ PdfBackend/ LocalServerPdfBackend.php
File
- src/
Plugin/ PdfBackend/ LocalServerPdfBackend.php, line 145
Class
- LocalServerPdfBackend
- LocalServer PdfBackend plugin.
Namespace
Drupal\fillpdf\Plugin\PdfBackendCode
public function mergeFile(FileInterface $template_file, array $field_mappings, array $context) {
$pdf_content = file_get_contents($template_file
->getFileUri());
return $this
->mergeStream($pdf_content, $field_mappings, $context);
}