使用PHP将HTML表单数据转换为PDF文件 [英] Convert HTML form data into a PDF file using PHP
问题描述
我一直在寻找和测试这个问题已经有几天了,并且想知道是否有人能够指出我的方向。我有一个非常长的工作应用程序HTML表单(jobapp.html)和一个匹配的PDF(jobpdf.pdf),它们在HTML表单和PDF中都具有相同的字段名称。我需要获取表单中输入的用户数据并将其转换为PDF。这是我迄今为止收集到的信息,但不知道我是否有进展:
pdftk是唯一可行的第三方应用程序吗?
使用pdftk我会为用户收集$ _POST数据并生成一个.fdf(user.fdf),然后将.pdf(job.pdf)上的.fdf变平。因此,在每个文档中字段的位置不变,fdf上的信息将通过字段名称填充pdf?
我一直在尝试
http://koivi.com/fill-pdf-form-fields/tutorial.php
我也看过将HTML表单提交为PDF
我已经使用 fpdf 几次创建基于php的pdf文档。以下示例:
require('fpdf.php');
$ pdf = new FPDF();
$ pdf-> AddFont('georgia','','georgia.php');
$ pdf-> AddFont('georgia','B','georgiab.php');
$ pdf-> AddFont('georgia','I','georgiai.php');
#添加UTF-8支持(只添加一个Unicode字体)
$ pdf-> AddFont('freesans','','freesans.php',true);
$ pdf-> SetFont('freesans','',12);
$ pdf-> SetTitle('My title');
$ pdf-> SetAuthor('My author');
$ pdf-> SetDisplayMode('fullpage','single');
$ pdf-> SetLeftMargin(20);
$ pdf-> SetRightMargin(20);
$ pdf-> AddPage();
$ pdf->单元格(40,10,'Hello World!');
$ pdf-> Output();
你可以用这些 b
要求( 'fpdf.php');
$ pdf =新FPDF();
$ pdf-> AddPage();
foreach($ _POST as $ key => $ data)
{
$ pdf-> Write(5,$ key:$ data); //写
$ pdf-> Ln(10); //新行
}
$ pdf->输出($ path_to_file。'file.txt','F'); //保存到文件
查看创建的这些页面与fpdf,真的!
I have been looking and testing this for a couple days now and was wondering if anyone could point me in a different direction. I have a very long job application HTML form (jobapp.html) and a matching PDF (jobpdf.pdf) that have the same field names for all entries in both the HTML form and the PDF. I need to take the user data that is entered in the form and convert it to a PDF. This is what I have gathered so far but don't know if I am on track:
Is pdftk the only viable 3rd party app to accomplish this?
Using pdftk would i take the $_POST data collected for the user and generate a .fdf(user.fdf) then flatten the .fdf on the .pdf(job.pdf). So irreguarless of where the fields are located on each document the information on the fdf would populate the pdf by field names?
I have been trying http://koivi.com/fill-pdf-form-fields/tutorial.php
I have also looked at "Submit HTML form to PDF"
I have used fpdf several times to create php-based pdf documents. An example following:
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddFont('georgia', '', 'georgia.php');
$pdf->AddFont('georgia', 'B', 'georgiab.php');
$pdf->AddFont('georgia', 'I', 'georgiai.php');
# Add UTF-8 support (only add a Unicode font)
$pdf->AddFont('freesans', '', 'freesans.php', true);
$pdf->SetFont('freesans', '', 12);
$pdf->SetTitle('My title');
$pdf->SetAuthor('My author');
$pdf->SetDisplayMode('fullpage', 'single');
$pdf->SetLeftMargin(20);
$pdf->SetRightMargin(20);
$pdf->AddPage();
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
You can learn very fast with these tutorials from the website itself.
EDIT: Example to save form data: (yes, is very easy...)
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
foreach ($_POST as $key =>$data)
{
$pdf->Write(5, "$key: $data"); //write
$pdf->Ln(10); // new line
}
$pdf->Output($path_to_file . 'file.txt','F'); // save to file
Look at these pages created with fpdf, really!
这篇关于使用PHP将HTML表单数据转换为PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!