Convert HTML form data to a PDF using PHP

I watched and tested this for a couple of days, and I was wondering if anyone could point me in the other direction. I have a very long application HTML form of the application (jobapp.html) and the corresponding PDF (jobpdf.pdf), which have the same field names for all entries both in HTML form and in PDF format. I need to take the user data entered into the form and convert it to PDF. This is what I have collected so far, but I don’t know if I am on the go:

Is pdftk the only viable third-party application to accomplish this?

Using pdftk, I would take the $ _POST data collected for the user and generate .fdf (user.fdf), then flatten .fdf to .pdf (job.pdf). So no matter where the fields are located on each document, does the fdf information fill in pdf by field names?

I am trying http://koivi.com/fill-pdf-form-fields/tutorial.php

I also looked at Submit HTML Form to PDF "

+5
source share
3 answers

I used fpdf several times to create php based pdf documents. The following example:

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 these tutorials very quickly on the website itself.


EDIT : example of saving form data: (yes, very simple ...)

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

, fpdf, !

enter image description here

enter image description here

+6

I found PrinceXML very easy to use. It takes your HTML / XML, applies CSS and converts it to PDF. PHP extensions work very well. Unfortunately, this is not free.

+1
source

All Articles