You are here

public function JavaBridgeFillPdfBackend::parse in FillPDF 8.4

Parse a PDF and return a list of its fields.

Parameters

\Drupal\fillpdf\FillPdfFormInterface $fillpdf_form: The PDF whose fields are going to be parsed.

Return value

array An array of associative arrays. Each sub-array contains a 'name' key with the name of the field and a 'type' key with the type. These can be iterated over and saved by the caller.

Overrides FillPdfBackendPluginInterface::parse

File

modules/fillpdf_legacy/src/Plugin/FillPdfBackend/JavaBridgeFillPdfBackend.php, line 66

Class

JavaBridgeFillPdfBackend
Legacy JavaBridge FillPdfBackend plugin.

Namespace

Drupal\fillpdf_legacy\Plugin\FillPdfBackend

Code

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;
}