TCPDF interactive pdf - php

Trying to allow outputs in PDF format from a website. One of the PDF's is a document that I have to build using data from a database, and just fill in a template. I'm using TCPDF to create the PDF files from the website.
Rather than having to construct the whole form in HTML and fill that in and convert it to PDF, I was wondering if I could have a pdf stored on the web hosting with the empty fields as interactive form fields, and fill it using TCPDF and the data from the database? Or if not, is there another way of doing this? Or is it just going to be simpler to build the form as an empty HTML shell and fill it in using database data before parsing to pdf?

You cannot fill in a PDF form with TCPDF but you only can create one. You may use FPDI to import the PDF form (without form fields!) and write to the positions of the form fields manually. If you need to fill in a PDF form with PHP you may take a look at the SetaPDF-FormFiller component (not free!). It's that easy:
$document = SetaPDF_Core_Document::loadByFile('pdfForm.pdf');
$formFiller = new SetaPDF_FormFiller($document);
$fields = $formFiller->getFields();
$fields['name']->setValue('Your name');
$fields['age']->setValue('25');
$document->save()->finish();

Related

Fetch Information from editable PDF form using PHP

Using PHP how can I show editable PDF form and then on submit get the information? I have a PDF form which I have converted to editable PDF form using Adobe Acrobat 9 Pro, I now want to show it in the browser so that user can fill. On submit I want to get the information entered in that form and store in the database.
To read and write a pdf you can use some PDF libraries like FPDI or PDFtoHTML.
Follow this link Read pdf files with php
But in your use case I am not sure why you are using a PDF form if your intention is just to save the user inputs into database. I would recommend use a HTML form instead, will be easier for you to manage.

Using PDFTK, input pdf is not an acroform, how to make it an acroform

I am using pdftk in my web app.. first I am merging 3 pdf templates with fillable forms into one pdf template with fillable forms (let's call it 'simple.pdf').
Then, I want to go further and fill in 'simple.pdf's custom fields but I am getting the warning 'input PDF is not an acroform, so its fields were not filled'.. is it possible to preserve the 'acroform' attribute ?
Thanks !

Using Breezing Forms form data to fill a PDF form

I have successfully created 3 Breezing Forms forms on a Joomla site and would like to know the best way to use the form data saved to the database to fill a PDF form, then be emailed to a specific address as a final step when the form is completed by the user. I'm aware that with Breezing Forms you can export form data to PDF, but the my forms are too complex in layout for the format of that type of export. What I need is the form data to populate a formatted PDF form.
Here is an example of one of the forms and the PDF it should fill:
Form: http://www.nutriworkscnc.com/Development/index.php?option=com_breezingforms&view=form&Itemid=640
PDF: http://www.nutriworkscnc.com/Development/images/forms/history.pdf
You essentially have two ways to fill the PDF form: client-side and server-side.
For client-side filling, you would create a FDF file with the /F key pointing to the base PDF (some people would call that the Template file). Then you would send the FDF to the user and a savvy PDF viewer would then load the base PDF and fill it.
If you have to serve dumb PDF viewers, you'd have to rely on server-side filling. For that, there are applications, such as FDFMerge by Appligent, or libraries, such as iText. You then will have to prepare the data in an appropriate way for your server-side filling tool.
If you want to solve this by using PHP you may take a look at the SetaPDF-FormFiller component (not free!). With it you can fill the fields through a very simple interface:
// Create an http writer
$writer = new SetaPDF_Core_Writer_Http("filled.pdf");
// Load document by filename
$document = SetaPDF_Core_Document::loadByFilename("history.pdf", $writer);
// Initiate a form filler instance
$formFiller = new SetaPDF_FormFiller($document);
// Get the fields instance
$fields = $formFiller->getFields();
// fill in the fields
$fields["Client Name"]->setValue("Test Person");
$fields["Address street"]->setValue("Teststreet 1");
$fields["Address city zip"]->setValue(12345);
$fields["diabetes"]->setValue(true);
$fields["diar"]->setValue(true);
// done
$document->save()->finish();

Fill a pdf and save as xfdf

For customised forms , instead of creating html forms and using that to get input from user , how can we use PDF to get input from user and when posting how to store all input in xfdf .
Can any one please help me to solve this issue and v r using php
Instead of creating a HTML form, you create a PDF form and submit the data as XFDF, which can then easily imported into a database, for example.
For creating PDF forms, there are quite a few tutorials around.

Web page - using PDF file template instead of FPDF

I have a small PHP webpage on which people can register for some events. After registration they receive email with confirmation in PDF (template with fill in fields like last name, mail address etc.).
There are so many changes in this PDF template that updating it using FPDF code take too much time.
Is there any option to create PDF templates (e.g. with Adobe Acrobat) with given "fill in fields" and then link it to web page function which fill them in using data from given MySQL table columns? Something like that:
1. Open PDF template (instead of using FPDF code)
2. Fill in first field in template with name from MySQL table column A
3. Fill in second field in template with last name from MySQL table column B
4. ...
5. Save template as xxx.pdf and send it via mail.
Shortly speaking - how replace FPDF code creation by attaching PDF file on which I can fill in given fields using MySQL records?
try with FPDM. You can create a PDF template with Adobe Acrobat, containing various fields. After that you can process the file with PHP and fill the fields with data from your SQL tables.
Take a look here: http://www.fpdf.org/en/script/script93.php

Categories