You are here

public function TestPdfBackend::mergeStream in FillPDF 5.0.x

Populate a PDF file with field data.

Parameters

string $pdf_content: 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::mergeStream

See also

\Drupal\fillpdf\Plugin\PdfBackendInterface::mergeFile()

1 call to TestPdfBackend::mergeStream()
TestPdfBackend::mergeFile in tests/modules/fillpdf_test/src/Plugin/PdfBackend/TestPdfBackend.php
Populate a PDF file with field data.

File

tests/modules/fillpdf_test/src/Plugin/PdfBackend/TestPdfBackend.php, line 88

Class

TestPdfBackend
Backend used in tests.

Namespace

Drupal\fillpdf_test\Plugin\PdfBackend

Code

public function mergeStream($pdf_content, array $field_mappings, array $context) {

  // Not really populated, but that isn't our job.
  $populated_pdf = file_get_contents(drupal_get_path('module', 'fillpdf_test') . '/files/fillpdf_test_v3.pdf');
  $this->state
    ->set('fillpdf_test.last_populated_metadata', [
    'field_mapping' => $field_mappings,
    'context' => $context,
  ]);
  return $populated_pdf;
}