如何在php中创建可编辑的Pdf表单

Roh*_*mar 9 php pdf mpdf

我有一个简单的表单,我想使用PHP在pdf中编辑它.但pdf正在创建表单,但我不能编辑和提交它,任何原因或我不能使用PHP编辑PDF?

我的代码是

<?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;
?>
Run Code Online (Sandbox Code Playgroud)

我正在使用mPDF 示例Url表单示例

Roh*_*mar 3

需要给出我自己的答案,因为 @Christian 给出了一个几乎正确且有效的示例 URL,我在Github 上找到了这个活动表单,但是当我用它尝试我的 html 表单时,它给了我类似的错误,

致命错误:调用未定义的方法 mPDF::Error() .... mpdf\classes\mpdfform.php 第 839 行

name经过一番搜索后,我发现表单的文本字段中缺少属性,当我添加该属性时,它运行良好。

<input type="text" id="name" value="name" name="field_name" />
Run Code Online (Sandbox Code Playgroud)

问题并没有就此结束,当我提交表单时,浏览器控制台中没有显示任何内容。然后我在服务器端使用php://input ,它向我显示了一些响应,该响应采用FDF(表单数据格式),需要解析才能获取实际数据。我没有尝试解析它,但发现了一些有用的 URL,我在这里分享,

  1. PHP:从 PDF 中提取 fdf 字段作为数组

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

  3. 用于提取 FDF 数据的 PHP 正则表达式代码

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

    链接如下