如何在PHP中创建可编辑的Pdf表单 [英] How to create editable Pdf form in php
问题描述
我有一个简单的表格,我想使用php在pdf中进行编辑.但是pdf正在创建表单,但是由于某种原因我无法编辑和提交它,或者我无法使用php编辑pdf?
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?
我的代码是
<?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;
?>
推荐答案
需要给出我自己的答案,因为@Christian提供了几乎正确且有效的示例网址,而我在
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,
严重错误:调用未定义的方法mPDF :: Error().... 第839行的mpdf \ classes \ mpdfform.php
Fatal error: Call to undefined method mPDF::Error() .... mpdf\classes\mpdfform.php on line 839
经过一些搜索,我发现表单的文本字段中缺少name
属性,当我添加该属性时,效果很好.
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" />
问题还不止于此,当我提交表单时,浏览器的控制台中没有任何显示.然后,我使用了 php://input ,它向我显示了一些响应,该响应位于 FDF中(表单数据格式),并且需要进行解析以获取实际数据.我没有尝试解析它,但是找到了一些我在这里共享的有用的URL,
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,
- PHP:从中提取fdf字段作为数组PDF
- https://answers.acrobatusers.com/Parse-FDF-response -q72665.aspx
- PHP regex代码以提取FDF数据
- PHP: Extract fdf fields as an array from a PDF
- https://answers.acrobatusers.com/Parse-FDF-response-q72665.aspx
- PHP regex code to extract FDF data
http://php.net/manual/en/ref.fdf.php
下面的链接
这篇关于如何在PHP中创建可编辑的Pdf表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!