PHP: Pre-fill a PDF file' fields and save them as default - php

I created a PDF file with some fields. I need users to fill out a HTML form and use these data to populate the fields in this file.
Right now, users have the link to that PDF file. They fill out the form, but they can't save it nor email it. I need the file to keep the values users type (perhaps save those values as the file' default) and allow them to save that copy in their devices, to latter email the file.
I was reading that PHP-PDF is limited and that there's other solutions out there. I am not sure if the default PHP-PDF functions are enough or if I'll need to look for an external PDF solution?

This appears like a simple server-side form filling task.
An industrial-strength solution would be using FDFMerge by Appligent, where you could, for example have already a PDF for gathering the primary information, submit as FDF, and feed this FDF into the "big" Template PDF. Or, if you have to add more data server-side, you might also submit as HTML POST, create the FDF on the fly (pretty easy, because FDF is a structured text format), and feed that into FDFMerge.
If you prefer developing a server-side solution using PDF creating/modifying libraries, you dan do so, using iText, or pdflib or others allowing server-side filling.
It essentially comes to which way would be the most cost and time efficient way to solve the problem.

Related

How can I replace content in a PDF file using PHP?

I have one issue about PDF file.
I generate dynamic PDF template (Like Certificate). The file content some fields like Firstname, Lastname, Course type, etc.
I want to write dynamic content into PDF as firstname, lastname etc.
I have tried MPDF, FPDF etc tools, but they are not working. I also used PDF to HTML conversation but after converting HTML regenerates not possible from html into proper format.
Please let me know if anyone have other idea to direct replace content into Existing pdf using PHP.
I have sample pdf files.
I want to replace content into given attachment. This is a demo file I have many files with different templates.
Okay, get away from your thoughts one could easiely change anything in a pdf from PHP.
The one way to do such thing like generating a certificate for anyone is to generate a "blank" pdf and then put in the names with names with a php libarary (like Zend_Pdf or anything else).
To make it short: There is no (easy, free) way to manipulate data in a PDF.
To make it complicated: Yes, there is a way. One have to open the file, read it's content, understand where to search for the variables, manipulate the data and regenerate the pdf with a pdf generator. And yes, i know, it is very complicated, so stay at the short and easy way: Generate a blanko and put in the variables as needed ;)

Fill pdf form and insert image, without Pdftk

is there any possible way to not lose any content, when inserting an image into a filled pdf, i am using the fpdm.php script from here and works prettty good i might add. the pdfs i am using i pass them trough pdftk, as in pdftk.exe insert.pdf output output.pdf so they can be filled via php with out throwing errors
so my problem is this, i have a pdf template, which i use to fill it with an array passed from php, and output it to browser or server, and works ok, but when i try to insert an image into it, it inserts it, but loses all filled data, i need to retain that data. i cant use pdftk because im on a godaddy shared hosting plan, also setasign scripts works i know, but i am trying to find a way without buying anything yet.
i found this stamper which stamps ok but loses pdf data, all boxes get blanked, and also this one that places the image and loses all data too. setasign is doing some magic stuff right there
All mentioned scripts are using FPDI in the background which simply doesn't modifes the original document but will allow you to recreate a completely new PDF document by importing another one page by page into reuseable structures (XObjects). Because form fields or other dynamic content like links or any other annotation type are not part of a pages content stream they will get lost.
The mentioned "magic" of the SetaPDF products is, that they modify the original document. Because of this all content will retain.

How to Import data from already make PDF Forms in php?

I have a PDF form and i want to import this PDF Form in PHP and then populate all fields from database then create new PDF.
is that possible?
If yes then please guide me how can i inert data in already make PDF forms.
Here is the PDF form file which i want to Import.
Download PDF
If you do take into account your working time etc. you might actually consider commercial server-side form filling tool, such as FDFMerge by Appligent (for simple filling, the Lite version would be sufficient). In this case, you won't need to noodle around the PDF, trying to interpret it, and attempting to write something back.
In this scenario, you would export an FDF from the database, which is rather easy to accomplish, as FDF is a simple text file. How it has to look can be found with ease as well, by taking the form, filling it out, and exporting the data as FDF. And then, the rest is "filling out the blanks".
For using libraries to do server-side filling, links have already been provided. Just a note: make sure that you will get a good and functional PDF, by relying on well-reputated libraries.

Approach to generate generate pdf file from html page?

I studied wkhtmltopdf, tcpdf mechanism to generate pdf files. wkhtmltopdf where you directly pass a .html file and it gives you the pdf where in tcpdf you need to code entire pdf.
my case is I'm having a pdf form template Which I've converted into html so user can fill that form and after i fill that template with user entered values then I'll give an option to user to download the html (user filled) file as PDF document, so template will have user entered data next to that labels.
so first
PDF template >> convert to .HTML page >> process with php echoing >> convert it back with user input to a PDF file.
I'm confused here which approach I should use.
Install wkhtmltopdf on server and use it to pass .html page
problem: Everytime I need to save .html page on server and pass again it to wkhtmltopdf.
using TCPDF I need to write lots of code to create pdf exactly same as template PDF docs I'm having
and then using php echoing those user enterted values.
Which approach should i use If I'm expecting 1000+ users will be saving page as pdf at same time, approach which will be more easier and scalable in future.
First of all - I think you should go with the HTML form to PDF approach, so that's either wkhtmltopdf or a tool that already does this for you like PDFmyFORM.
In case you're expecting to go to 1000 saves concurrently then you definitely want to roll your own solution instead of going with an external service though.
There are patches in the wkhtmltopdf issue list that suggest caching (see this one) and you may also want to think about whether all these forms have to be generated as PDF again. You could use APC cache to somehow cache PDFs based on the same values being filled in. That could save you a bunch of time.
Other solutions you may want to look into are for example PhantomJS, which is a headless webkit browser too, but then based on JS - so that may reduce your server load alltogether...

Save form results as PDF

Tricky question.
I have a very long form where the user writes down a lot of data. I need to save the form for future reading (pdf, html, or even a jpg will do), but I need to save it with the data that the user wrote down. This has to be done on submitting the form.
I know it's going to be impossible with only PHP, but would it be possible with a little help from javascript-ajax?
I can't prompt the user to print the page, and I need to save the view without any other input from the user (beside the submit).
Any ideas?
EDIT:
in a nutshell,
is it possible to generate a pdf from that page without submitting the data ? is there a way fpdf (or others) could "read" and save what's currently on the screen, just like a "print" function ?
imagine a long, looong form, with a button "save as pdf" who saves the current page (with the data inputted from the user) WITHOUT submitting the form....
Take a look at the thread: Which is the best PDF library for PHP?
Highested listed solutions include:
TCPDF
FPDF
Another possible solution would be converting HTML to PDF in PHP: HTML to PDF in PHP
You can have a look at: http://php.net/manual/en/book.pdf.php and this http://www.tcpdf.org/
Hope this helps you.. Thanks
If you want to go from form data to PDF then one of the methods you could try is to take the submitted data, create a HTML document, and convert that document to PDF. You wouldn't necessarily need to send the HTML to the user (though you could) because you'd be using the HTML merely for formatting purposes. Push the HTML into a variable and then parse it through one of the many HTML to PDF converters.

Categories