9

I have a simple form and I want to make it editable in pdf using php. But the pdf is creating the form but I can't edit and submit it, any reason or I can't edit pdf using php?

My code is

<?php
    define('_MPDF_PATH','/');
    include("mpdf.php");

    $html = '
        <form action="test.php">
          <input type="text" id="name" value="name" />
          <input type="reset" name="reset" value="Reset" />
          <input type="submit" name="submit" value="Submit" /> 
        </form>';

    $mpdf=new mPDF('c'); 

    $mpdf->default_lineheight_correction = 1.2;

    // LOAD a stylesheet
    $stylesheet = file_get_contents('mpdfstyletables.css');
    $mpdf->WriteHTML($stylesheet,1);    // The parameter 1 tells that this is css/style only and no body/html/text
    $mpdf->SetColumns(2,'J');
    $mpdf->WriteHTML($html);
    $mpdf->Output('test.pdf','D');//
    exit;
?>

I'm using mPDF Example Url and Form Example

Rohan Kumar
  • 38,998
  • 11
  • 69
  • 99
  • Can you provide more information? Does that PDF submit anything? Does anything happen at all when pressing that submit button? Is your test.php called? (Im not sure PDF can do this at all, but there is allways a first...) – ToBe Jul 15 '13 at 09:47
  • No there is no `change` on clicking the `submit button`, even no `input box or drop down changes`. `Elements` are not behaving like `html elements`. – Rohan Kumar Jul 15 '13 at 10:01
  • So, why do you think PDF can submit data to a webservice at all? Is there any reference? – ToBe Jul 15 '13 at 12:39
  • @RohanKumar the 2 links at the bottom of your question are broken. – reformed Mar 08 '18 at 16:07
  • @reformed I have updated the broken links. – Rohan Kumar Mar 09 '18 at 04:34

4 Answers4

4

You can also use TCPDF. TCPDF is a free and open source software PHP class for generating PDF documents. TCPDF is the only PHP-based library that includes complete support for UTF-8 Unicode and right-to-left languages, including the bidirectional algorithm.

visit that link for more information. http://www.tcpdf.org/

Rahul Seth
  • 385
  • 1
  • 3
  • 13
2

To make the fields editable, you need to add this line:

$mpdf->useActiveForms = true;

This should work for mPDF 5.3 and higher.

Funk Forty Niner
  • 73,764
  • 15
  • 63
  • 131
Christian
  • 787
  • 8
  • 16
1

What you are doing is just to print a form onto a PDF, but not to provide editable features. Your form is still non-editable. You have to use Acrobat SDK to make editable forms.

Raptor
  • 48,613
  • 43
  • 209
  • 344
  • Have you any idea of using `Acrobat API`? How can use it in `php`? – Rohan Kumar Jul 16 '13 at 05:01
  • You can use Acrobat JavaScript SDK .http://www.adobe.com/devnet/acrobat/overview.html , especially reading the section: Choosing the correct Acrobat SDK Technology – Raptor Jul 16 '13 at 05:57
1

Need to give my own answer, as @Christian gave almost correct and working URL of an example and I found this on Github for active forms but when I tried my html form with it, then it gives me error something like,

Fatal error: Call to undefined method mPDF::Error() .... mpdf\classes\mpdfform.php on line 839

After some searching I found that there is missing name attribute in the form's text field and when I added the attribute it worked well.

<input type="text" id="name" value="name" name="field_name" />

The problem not ends with this, when I submit the form then there is nothing shown in browser's console. Then I used php://input at server side and it has shown me some response, which is in FDF(forms data format) and needs to be parse to get the actual data. I din't give a try to parse it but found some useful URLS which I am sharing here,

  1. PHP: Extract fdf fields as an array from a PDF

  2. https://answers.acrobatusers.com/Parse-FDF-response-q72665.aspx

  3. PHP regex code to extract FDF data

  4. http://php.net/manual/en/ref.fdf.php

    links below

Community
  • 1
  • 1
Rohan Kumar
  • 38,998
  • 11
  • 69
  • 99