fill in PDF form using data in MySQL database - php

I am working on an online time card system to replace the paper time cards. What I have done is create a webpage in PHP that takes the time in and out along with job description and other values the user inputs and stores them in a MySQL database. Everything is working just fine.
What I would like to work on next is to take the information from the database for the specific user and week and have it fill in a PDF template file I have created from scanning the old paper time card and making it into a PDF form. I dont know if this is possible I have been researching it online and all I can come up with is how to generate a new PDF file. I am hoping someone here can point me to a source of information on how to do this.
Here is an example of exactly what I want to do http://try.fillpdf-service.com/

Hi congratulation for you about done the 1st step in time,
You can use very complete pdf generator php class TCPDF
It started in 2002, TCPDF is now one of the world's most active Open Source projects, used daily by millions of users and included in thousands of CMS and Web applications.
http://www.tcpdf.org/ for genarating your pdf what kind your want this class has very useful documnet and simple to use
Cheers,
Farzam

Take a look ath this
http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
It can be invoked as a command line tool and among the other functions let fill form fields, (on an already existing PDF you supply).

Maybe FPDF is quite old, but still good to handle for PDF generation. Just take a Template PDF (create as you like) and put the informations you want on it. You will have to place your data on the specific positions, see the tutorial section for a better understanding.
Another popular solution is to use Zend_PDF from well known Zend Framework, but I think FPDF would be a tick easier to work with if you are not very experienced.

Related

HTML with JScript to read/write XLS file

Very sorry if this is not in the right place etc. I have been researching this for a while but its raised more questions!
I have developed a spreadsheet which I use to set a teams duties for a shift. There are 5 teams, each with staff which can change day to day.
the spreadsheet works fine, but its too complicated for some users. I am therefore trying to develop a straightforward web based form.
All the data is on the spreadsheet, held on a network drive (essentially locally).
I need to be able to have several combo/select boxes which get their values from a range of cells from the XLS. Along with the ability to output the final selections to a XLS sheet.
Finally, it needs to be able to load the previous day values on load.
What is the best way of developing a web page for this? Is Jscript the best option? Can I access a local file with jScript?
Thanks in advance
Adrian
The easiest option for you is to use google web forms. These allow creation of forms that will submit data to a google spreadsheet. Which is essentially an uploaded version of your local spreadsheet and can be downloaded to excel.
In case if you want more control and programming, pure javascript cant play with files, you need server side too. Javascript is not necessary unless you want to make your app do some visually fancy stuff. Since you mentioned php as a tag of this question, it seems you are a bit familiar with php. The task you have mentioned can be done using php programming as below:
Read excel file using an excel plugin
Parse relevant data using a text matching function, may require regular expressions knowledge.
display the form by building up the html and putting in the variables using the data obtained above.
Write a method to save the data submitted by the form to the same excel file using the excel plugin.
As its not convenient to play around with excel files. A better option would be to generate csv file or use a database using a database class . csv files can be parsed easily using text.

Generate PDF automatically and automatically upload to server

I am working on improving a daily tasks which could be sped up if what I need exists. It could save me about 2 hours of work a day if it can be done. My current way of generating reports is long. Here is my current flow.
I click generate report and the report is automatically generated using PHP, CSS, & HTML.
I work on a Mac, so in order to save the report as a PDF, I click on "print". The print window appears and I then click on "Save As PDF".
I save this report to my desktop. I then upload it to my server.
The 3 steps above is my current process. What I would like to be able to do is this:
I click generate report and the report is automatically generated using PHP, CSS, & HTML.
If the report looks good, I click on "save". The save button will automatically generate a PDF and will upload it to my server.
Is this possible? If so, can someone point me in the right direction. I prefer to do this with PHP, but if there's another way I can do this, that is fine as well.
If you'd like to learn how to do this, and well, there are great resources available to you.
In fact, Welling/Thomson's PHP and MySQL Web Development has two chapters that are perfect you. Chapter 19 deals with files and Chapter 32 is entitled "Generating Personalized PDF Documents." I recommend you give it a thorough read.
If you encounter problems along the way, then you should come back here and post them in discrete components.
you could use MPDF, a great tool to generate pdfs.
check: http://www.mpdf1.com/mpdf/ download the pack and check the examples. :D sorry about the english
PHP doesn't have a built-in PDF generator, although there are libraries you can add that will do it. Creating the PDF by outputting the correct formatting is non-trivial.
Instead, you can use an HTML to PDF converter - I've used them on Linux, such as wkhtmltopdf, so they should work okay on a Mac, too. You would just generate the report as normal, but output it to a file rather than the browser. Then run the converter on the HTML and presto, a PDF version.

Generating FPDF code from existing PDF document, is it possible?

I'm currently doing a task where I'm taking forms from a local government body, and converting them so that they are able to have a PDF generated dynamically via FPDF based on passed parameters. Currently the only copies of these documents are in read-only pdf files. What I'm wondering is if there is a way to have these files read somehow to where these documents could be converted into FPDF format somehow? Normally I'd just create them manually, but with 50 files to convert, and with some being multiple page forms, it'll probably take months, and hence looking for a quicker way.
The short answer is you're stuck. As far as I and my many hours of research know there's no such process. I would love to be proven wrong.
I recently went through a similar situation with insurance forms. I used the free trial of Adobe Live Cycle Designer to build out the forms. It basically turns the old pdf into a flat background image you can draw form fields over. Then I used PDF Toolkit and PDFTK-PHP to populate the fields.
The process wasn't ideal but it worked out well enough. I setup 20 forms consisting of about 50 pages with filling code and some other operations in a week.

Modify PDF Forms from a PHP site

We currently use PDForm to grab a blank pdf file (no values, just form fields and text) and list the form fields. We then query our database for the values which match those field names and create a pdf file with the newly populated data which the user can download from our site. The thing is PDForm is about $5,000 per machine and we are migrating servers. We want an alternative which is actively supported and recommended by the community.
I know Zend is working on a PDF manipulation extension, but we need something quick. I have done testing with PDFtk but the last update for that project was in 2006 and it now seems dead. It would be fine as it is open source, however it seems to be causing errors with certain files that seem to be generated with PDFPenPro (our pdf form creator).
Another solution I thought up was why not just use iText and write a java wrapper which accepts command line input, so that PHP can call it with passthru() or exec(). There are other applications that will work should we completely rewrite our code but we do not want to do that.
What we need.
The ability for PHP to receive the PDF form field names.
PHP to then either create and FDF file (then merge it with the PDF) or send a string to a command line application which will populate the fields with values from our database.
The user can then download the newly created PDF file with the populated form fields.
Am I moving in the write direction by creating a java command line application that will use iText to parse and create the PDF files specified by PHP or does anyone know of any cost effective alternatives?
TCPDF seems to have the most robust feature set that I have seen so far.
Thanks, d2burke, for the tip on TCPDF. I'm not trying to do quite as much as the OP, but the software packages available to accomplish any kind of pdf generation are in the $2k to $3k range. TCPDF is php based, open source and the guy developing it is very supportive.
Always donate to these guys! Where in the world would web development be without it?
So since none of the above solutions would work since TCPDF doesn't work with forms the way we are wanting and since PDFlib converts the form fields to blocks we decided to create a command line wrapper for iText which will grab the form field names from the PDF and then populate them based on the database values.
I don't know if another product whose license costs range from $1k -> $3k could be considered "cost effective", but PDFlib work quite nicely. And if you don't need the PPS functionality, it does get cheaper.

Insert data into PDF, filled in an online form, on submit action

First of all my apologies to all the people who think this question is a repeated one or they find a similar question to this.
I am working on a project in which I have an online form and some PDFs stored on the server.
Functionality
On the submit action I have to get the data from the form, fill it to the copy of PDF and finally download it.
Approach
I followed these steps to achieve this functionality:
Converted the pdfs to html with this http://www.pdfdownload.org/free-pdf-to-html.aspx online tool.
Embedded the html with form variables and regenerated the PDFs with this library / dompdf library.
Problem
The approach is a brute force one as the html generated are far away from the real ones. So lot of effort is wasted in adjusting the html.
The process is so slow and not reliable as most of the time I get memory error or some other issues.
I need to to automate this process. What I have found through searching is I should create an FDF file that contains my variable and pass it to the PDF using some library and then download it.
I am able to create the FDF file but missing any library in PHP (I found one in JAVA) that I can use to create the PDF and download it. One library that I found is pdf tool kit but that is a command line tool and I am not able to use it on the server at run time and download the PDF file.
Anybody having done this before please help.
(Sorry for this long post)
Thanks,
Madhup
Check out FPDI. It allows you to load some existing PDF, draw on it programatically, and output a new PDF. Which, if I read your question right, is what you're trying to do.
There's some example code here.

Categories