Save form results as PDF - php

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.

Related

generate PDF of html form data using php code no other tool

I need some help. I'm searching for almost 2 days but I can't find the perfect answer. so I have a HTML form when I submit the click button it saves data in the database now I need to generate a pdf of my HTML form when data is submitted and automatically mail it to my email address. I need to generate pdf file without using any tool or any other demo like FPDF or anything like that.
I want to generate pdf using PHP code.
can it be done? need your help.
thankyou!!!'
<form action="dbconnection.php" method="post" name="2nd-form" id="form-survey" >
If it's just saving the code why don't you just save it as a .txt file, attach that, and save yourself all the hassle. PDF creation is possible but extremely over complicated for simple task without the use of a library of some kind. Writing to txt file is super simple and much easier to maintain that a ton of PHP code. If you do end up using a library look into mpdf. Is much better than fpdf. It has better documentation too.
No you can't create pdf without any library. another good way or my suggestion is you can create a html body using the form content . Then add this as html-content in your mail .
I think this is the easy way to avoid time consuming to create PDF and attach it to mail and send it all.
Try to use this way or if you want the pdf for some purpose so you should use some library to create it.

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

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.

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.

How to print text to an existing pdf file?

I have created new PDFs many times using Zend and PHP. But Now I have a patient form in PDF format and I have to fill that form using my application. How can I print text on existing PDF file with already have some text. Is it possible ?
Thanks
I haven't done it, but it certainly seems possible. See Zend_Pdf::load(), for example. It seems like you ought to be able to load the PDF, manipulate it, and save then save it somewhere.
Last time I had to do this, Zend_Pdf wasn't around, and I ended up using fpdf/fpdi, which was ugly but worked fine.
Does the PDF contain form fields ? If so you can use FDF type functions.
See Filling PDF Forms with PHP - there should be a solution in there somewhere.

Spinning PDF's by passing a URL and $_GET parameters?

I have spent a lot of time trying to get dompdf (http://www.digitaljunkies.ca/dompdf/) to work but I keep running into problems. I am trying to generate a PDF from a PHP script which generates a fairly complex, filled out web form. The script accepts a $_GET parameter (record number) and fills out the form accordingly with data from the database. I have no problem getting this data into the script as a string or any type of value really. What I am wondering is what the best approach would be for converting this type of data to a PDF?
The flow is as follows: user completes form and is taken to confirmation page which I would like to add a "Save as PDF" button. At this point one of two things could happen, the page that is currently being displayed in the browser could be spun directly to a pdf or a call to itself (scriptname.php?id=xyz) could be made using something like PHP's http_get() function and store the HTML as a string. From there I am having issues with preparing an accurate representation as a PDF.
I have heard some talk about fpdf but their examples don't really lead me to believe you can use dynamic data as the source, but please correct me if I am wrong about this.
Any input would be appreciated.
-- Nicholas
Well, I didn't know dompdf. Strange that it uses either a commercial library (PDFlib) or an outdated (?) one (CPDF, not updated for 3 years). But well, as long as it works (concept is interesting).
I don't understand what you mean by "use dynamic data as the source" (or rather, I see not point in generating static PDF!), but FPDF is used to generate various dynamic documents, like invoices in e-commerce products. I saw people using forks (like TCPDF) to handle Unicode data, though.
You can't transform an HTML page to PDF with FPDF, but you have a quite precise control of layout, using concept of cells with data.
You can see such kind of code there: http://svn.prestashop.com/trunk/classes/PDF.php
In the past when faced with this issue, I have used FPDF for the placement of data on a PDF template. Then, by setting the appropriate HTTP header, force the browser to pop open the Download / Save As box for the user to save said PDF.
In a class that extends FPDF/FPDI appropriately, use something like the following to generate a PDF from a template PDF you've already created (http://www.setasign.de/products/pdf-php-solutions/fpdi/):
$this->setSourceFile('pdf_template.pdf');
$template_page = $this->importPage(1, '/MediaBox');
$this->useTemplate($template_page, 0, 0);
Then, have FPDF generate the PDF for output using:
$this->Output();
You can also extend FPDF to accept (limited) HTML for formatting using the script found here: http://www.fpdf.org/en/script/script41.php

Categories