public function __toString() { try { return $this->__client->invokeMethod(0, "ObjectToString", array($this)); } catch (Exception\JavaException $ex) { trigger_error("Exception in Java::__toString(): " . java_truncate((string) $ex), E_USER_WARNING); return ""; } }
/** * @inheritdoc */ public function populateWithFieldData(FillPdfFormInterface $pdf_form, array $field_mapping, array $context) { /** @var FileInterface $original_file */ $original_file = File::load($pdf_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) { drupal_set_message(java_truncate((string) $e), 'error'); 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) { drupal_set_message(java_truncate((string) $e), 'error'); return NULL; } return $populated_pdf; }