You are here

function fillpdf_parse_pdf in FillPDF 7.2

Same name and namespace in other branches
  1. 6 fillpdf.module \fillpdf_parse_pdf()
  2. 7 fillpdf.module \fillpdf_parse_pdf()

This function generates the form fields from the specified PDF. It does so using the PDF Forms API.

1 call to fillpdf_parse_pdf()
_fillpdf_save_upload in ./fillpdf.admin.inc

File

./fillpdf.module, line 867
Allows mappings of PDFs to site content

Code

function fillpdf_parse_pdf($fid) {
  $filename = db_query("SELECT url FROM {fillpdf_forms} WHERE fid = :fid", array(
    ':fid' => $fid,
  ))
    ->fetchField();

  // Delete any existing fields (in case the PDF has been parsed before)
  db_delete('fillpdf_fields')
    ->condition('fid', $fid)
    ->execute();
  $fields = pdf_forms_parse($filename);

  //create fields
  foreach ((array) $fields as $key => $arr) {

    // Don't store "container" fields
    if ($arr['type']) {

      // pdftk sometimes inserts random � markers - strip these out. NOTE:
      // This may break forms that actually DO contain this pattern, but
      // 99%-of-the-time functionality is better than merge failing due to
      // improper parsing.
      $arr['name'] = str_replace('�', '', $arr['name']);
      $field = new stdClass();
      $field->fid = $fid;
      $field->pdf_key = $arr['name'];
      $field->label = NULL;
      $field->value = '';
      drupal_write_record('fillpdf_fields', $field);
    }
  }
}