How to pass data from HTML to PDF?

Good day!

For example there may be a form you fill in it fields then press submit, your completed field travel and are generated in PDF for download!?

PDF originally prepared, hat, field, etc. - how do you realize!?

------------------------------------------------------------------------------------------

Suggested two libraries:
fPDF
jsPDF - reading become. on Habre https://habrahabr.ru/post/278047/ something tolknul
pdfmake - lots of documentation + saw video tutorials how to work with it

Questions on them:
For example, the document 20 fields to fill in, each field is "label + field itself" - the user need only 15 he has filled, the remaining 5 in the PDF will not display? Reformulate, generate PDF on the fly, if not populated, then there will appear a line label + data?

Which library is easier/more convenient to use = what to explore/to understand (js + php = superficial knowledge)

Thank you!
June 14th 19 at 20:30
4 answers
June 14th 19 at 20:32
Added question, please take a look! - Santina_Graham commented on June 14th 19 at 20:35
Similarly, the author of another answer, I have not worked with jsPDF. - caleb_Stehr commented on June 14th 19 at 20:38
the conditions for the withdrawal or not withdrawal can be done at the level of php, don't see the problem. - caleb_Stehr commented on June 14th 19 at 20:41
June 14th 19 at 20:34
need a script on the server side.
For example in PHP:
require_once('fpdf.php');
require_once('fpdi.php');

$pdf =& new FPDI();
$pages_count = $pdf->setSourceFile('your_file.pdf'); 

for($i = 1; $i <= $pages_count; $i++)
{
 $pdf->AddPage(); 

 $tplIdx = $pdf->importPage($i);

 $pdf->useTemplate($tplIdx, 0, 0); 


 $pdf->SetFont('Arial'); 
 $pdf->SetTextColor(255,0,0); 
 $pdf->SetXY(25, 25); 
 $pdf->Write(0, "This is just a simple text"); 
}

on each page adds the text at the point [25,25]
parse retrieving data from a form I think is unnecessary.

You will need to sit there and meticulously count the positions from the data, where to insert.
Generally depends on what you want in the output. If you want "beautiful" - then definitely use the template as a script to generate art objects will not be easy. If you want propolice "PDF page with the text" it can be no template.
jsPDF does not know how to take an existing, but works on the client side.
fPDF with the fpdi plugin can take an existing file, but need a server with PHP. - Santina_Graham commented on June 14th 19 at 20:37
June 14th 19 at 20:36
Added question, please take a look! - Santina_Graham commented on June 14th 19 at 20:39
fields can be assigned certain classes, for example for empty js-disabled, and specify jsPDF to take only empty fields. Then anything extra in your PDF will not.

UPD: about FPDF can not say anything, because it still didn't work. - caleb_Stehr commented on June 14th 19 at 20:42
June 14th 19 at 20:38
Will offer another option - wkhtmltopdf or wkhtmltox. It's a binary which should run on server from the command line, well, or through functions Ala exec(). At the entrance he needed the html from which it generates a pdf. Because it uses webkit engine - supports all the css. Oh and to generate html on the server came, I think, this task is trivial.

Find more questions by tags PDFHTML