class JavaBridgeFillPdfBackend in FillPDF 8.4
Legacy JavaBridge FillPdfBackend plugin.
Plugin annotation
@Plugin(
id = "local"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\fillpdf_legacy\Plugin\FillPdfBackend\JavaBridgeFillPdfBackend implements ContainerFactoryPluginInterface, FillPdfBackendPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of JavaBridgeFillPdfBackend
Deprecated
in fillpdf:8.x-4.9 and is removed from fillpdf:8.x-5.0. Use FillPDF LocalServer with the new LocalServerPdfBackend plugin instead.
See also
https://www.drupal.org/node/3059476
\Drupal\fillpdf\Plugin\PdfBackend\LocalServerPdfBackend
File
- modules/
fillpdf_legacy/ src/ Plugin/ FillPdfBackend/ JavaBridgeFillPdfBackend.php, line 25
Namespace
Drupal\fillpdf_legacy\Plugin\FillPdfBackendView source
class JavaBridgeFillPdfBackend extends PluginBase implements FillPdfBackendPluginInterface, ContainerFactoryPluginInterface {
/**
* The file system.
*
* @var \Drupal\Core\File\FileSystem
*/
protected $fileSystem;
/**
* Constructs a LocalFillPdfBackend plugin object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\File\FileSystem $file_system
* The file system.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, FileSystem $file_system) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->fileSystem = $file_system;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('file_system'));
}
/**
* {@inheritdoc}
*/
public function parse(FillPdfFormInterface $fillpdf_form) {
/** @var \Drupal\file\FileInterface $file */
$file = File::load($fillpdf_form->file->target_id);
$content = file_get_contents($file
->getFileUri());
$require = drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc';
require_once DRUPAL_ROOT . '/' . $require;
try {
$fillpdf = new \java('com.ocdevel.FillpdfService', base64_encode($content), 'bytes');
$fields = java_values($fillpdf
->parse());
} catch (\JavaException $e) {
$this
->messenger()
->addError(java_truncate((string) $e));
}
return $fields;
}
/**
* {@inheritdoc}
*/
public function populateWithFieldData(FillPdfFormInterface $fillpdf_form, array $field_mapping, array $context) {
/** @var \Drupal\file\FileInterface $original_file */
$original_file = File::load($fillpdf_form->file->target_id);
$pdf_data = file_get_contents($original_file
->getFileUri());
$fields = $field_mapping['fields'];
$require = drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc';
require_once DRUPAL_ROOT . '/' . $require;
try {
$fillpdf = new \java('com.ocdevel.FillpdfService', base64_encode($pdf_data), 'bytes');
foreach ($fields as $key => $field) {
if (substr($field, 0, 7) == '{image}') {
// Remove {image} marker.
$image_filepath = substr($field, 7);
$image_realpath = $this->fileSystem
->realpath($image_filepath);
$fillpdf
->image($key, $image_realpath, 'file');
}
else {
$fillpdf
->text($key, $field);
}
}
} catch (\JavaException $e) {
$this
->messenger()
->addError(java_truncate((string) $e));
return NULL;
}
try {
if ($context['flatten']) {
$populated_pdf = java_values(base64_decode($fillpdf
->toByteArray()));
}
else {
$populated_pdf = java_values(base64_decode($fillpdf
->toByteArrayUnflattened()));
}
} catch (\JavaException $e) {
$this
->messenger()
->addError(java_truncate((string) $e));
return NULL;
}
return $populated_pdf;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
JavaBridgeFillPdfBackend:: |
protected | property | The file system. | |
JavaBridgeFillPdfBackend:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
JavaBridgeFillPdfBackend:: |
public | function |
Parse a PDF and return a list of its fields. Overrides FillPdfBackendPluginInterface:: |
|
JavaBridgeFillPdfBackend:: |
public | function |
Populate a FillPDF form with field data. Overrides FillPdfBackendPluginInterface:: |
|
JavaBridgeFillPdfBackend:: |
public | function |
Constructs a LocalFillPdfBackend plugin object. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |