You are here

public function Test::merge in FillPDF 8.4

Populate a PDF file with field data.

Parameters

string $pdf_content: The PDF into which to merge the field values specified in the mapping.

\Drupal\fillpdf\FieldMapping[] $field_mappings: An array of FieldMapping-derived objects mapping PDF field keys to the values with which they should be replaced. Strings are also acceptable and converted to TextFieldMapping objects. Example array:

[
  '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 FillPdfLinkManipulatorInterface::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 BackendServiceInterface::merge

See also

\Drupal\fillpdf\FieldMapping

\Drupal\fillpdf\FieldMapping\TextFieldMapping

\Drupal\fillpdf\FieldMapping\ImageFieldMapping

\Drupal\fillpdf\FillPdfLinkManipulatorInterface::parseLink()

File

tests/modules/fillpdf_test/src/Plugin/BackendService/Test.php, line 68

Class

Test
Backend used in tests.

Namespace

Drupal\fillpdf_test\Plugin\BackendService

Code

public function merge($pdf_content, array $field_mappings, array $options) {
  $this->state
    ->set('fillpdf_test.last_populated_metadata', [
    'field_mapping' => $field_mappings,
    'options' => $options,
  ]);
  return file_get_contents(drupal_get_path('module', 'fillpdf_test') . '/files/fillpdf_test_v3.pdf');
}