Answer the question
In order to leave comments, you need to log in
How to transfer data from HTML to PDF?
Good afternoon!
Let's say there is some kind of form, you fill in the fields in it, then click submit, your completed fields are sent and generated in PDF for download!?
PDF originally prepared, header, margins, etc. - How can it be implemented?
-------------------------------------------------- ----------------------------------------
Two libraries were proposed:
fPDF
jsPDF - after reading become. on hubbre https://habrahabr.ru/post/278047/ something pushed pdfmake
away - a lot of documentation + saw video tutorials on how to work with it
Questions about them:
Let's say there are 20 fields in the document to fill in, each field has a "label + the field itself" - the user only needs 15 of them and he filled them in, the remaining 5 will not be displayed in the PDF? Let me rephrase, PDF generation on the fly, if I didn’t fill in the field, then the line label + data will not be displayed?
Which library is easier / more convenient to use = which one to study / understand (js + php = superficial knowledge)
Thank you!
Answer the question
In order to leave comments, you need to log in
You need a script on the server side.
For example like this 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");
}
I will offer another option - wkhtmltopdf or wkhtmltox. This is a binary that needs to be run on the server from the command line, or through functions a la exec (). It needs html as input, from which it generates pdf. Since the webkit engine is used, it supports all sorts of css. Well, and to form html on the server according to the incoming data, I think this is a trivial task.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question