title: PDF form population with FPDM
body: <p>what I'm trying to accomplish is population of PDF form with PHP.<br>
  I tried many ways, I found that FPDM (FPDF) is working well when I create a new form, or use the form from source file they provided.<br>
  My problem is when I'm using already created PDF form, the form has restrictions such as Owner password, document is signed and certified. I used the app to remove those restrictions, some of them are left. In picture below you can see how my current PDF looks like.</p>
  
  <p><img src="https://i.stack.imgur.com/2aQJ0.png" alt="enter image description here"></p>
  
  <p>That PDF also was compressed, and because FPDM was throwing the error that 'Object Stream' is not supported I decompressed it through PDFTK, so file went from 1.48 Mb to 6.78 Mb.</p>
  
  <p>To get all form field names I used also PDFTK, so I have them in txt file.</p>
  
  <p>There are two ways I can do by the instructions of FPDM:</p>
  
  <p>First way is only to send an array field_name => value along with PDF I want to change and that's it. So when I use PDF described above I get error:</p>
  
  <p>'FPDF-Merge Error: field form1[0].#subform[0].Line1_GivenName[0] not found'</p>
  
  <p>Just to remind that I have all names and this name exists.</p>
  
  <pre><code>&lt;?php
  require('fpdm.php');
  
  $fields = array(
          'form1[0].#subform[0].Line1_GivenName[0]' =&gt; 'my name'
      );
  $pdf = new FPDM('test.pdf');
  $pdf-&gt;Load($fields, false); // second parameter: false if field values are in ISO-8859-     1, true if UTF-8
  $pdf-&gt;Merge();
  $pdf-&gt;Output('new_pdf.pdf', 'F');
  ?&gt;
  </code></pre>
  
  <p>The other way is that I create FDF file with createXFDF function and then use FPDM to merge FDF to PDF. This solution creates 'new_file.pdf' like I want but empty :)</p>
  
  <pre><code>function createXFDF($file, $info, $enc = 'UTF-8') {
  $data = '&lt;?xml version="1.0" encoding="'.$enc.'"?&gt;' . "\n" .
      '&lt;xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"&gt;' . "\n" .
      '&lt;fields&gt;' . "\n";
  foreach($info as $field =&gt; $val) {
      $data .= '&lt;field name="' . $field . '"&gt;' . "\n";
      if(is_array($val)) {
          foreach( $val as $opt )
              $data .= '&lt;value&gt;' .
                  htmlentities( $opt, ENT_COMPAT, $enc ) .
                  '&lt;/value&gt;' . "\n";
      } else {
          $data .= '&lt;value&gt;' .
              htmlentities( $val, ENT_COMPAT, $enc ) .
              '&lt;/value&gt;' . "\n";
      }
      $data .= '&lt;/field&gt;' . "\n";
  }
  $data .= '&lt;/fields&gt;' . "\n" .
      '&lt;ids original="' . md5( $file ) . '" modified="' .
          time() . '" /&gt;' . "\n" .
      '&lt;f href="' . $file . '" /&gt;' . "\n" .
      '&lt;/xfdf&gt;' . "\n";
  
  return $data;
  }
  
  
  require('fpdm.php');
  
  $pdf = new FPDM('test.pdf', 'posted-0.fdf');
  $pdf-&gt;Merge();
  $pdf-&gt;Output('new_file.pdf', 'F');
  </code></pre>
  
  <p>One more thing, if I try to open FDF file in Acrobat I get a message </p>
  
  <p>'The file you are attempting to open contains comments or form data that are supposed to be placed on test.pdf. This document cannot be found. It may have been moved, or deleted. Would you like to browse to attempt to locate this document?'</p>
  
  <p>but the file is there, not moved or deleted. When I find it manually the form populates.</p>
  
  <p>If anyone has experience with this, any help or advice would help a lot.</p>
  
  <p>Thank you in advance,  Vukasin</p>
  
  <p>EDIT:
  More info about the PDF file
  <img src="https://i.stack.imgur.com/kwXyv.png" alt="enter image description here"></p>