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.
Related
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.
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.
We have a high-resolution PDF (for printing) which has some form fields on it. We would like to have an HTML form which submits to the PDF, which is then placed into the respective fields.
I found a solution on google: http://koivi.com/fill-pdf-form-fields/
However, with that solution you only get an FDF file... And the demo does not work for me, opening the FDF file simply downloads another FDF file.
Since this PDF will be available to the public we would like to keep it as simple as possible. If we must open our original PDF and import this FDF file, we need a different solution (which I'm not sure is what the FDF file is for, since it didn't work).
A related post talking about .net framework had the same idea, but there were only paid commercial solutions: From HTML form to PDF
The PHP solutions I have found so far are for creating a new PDF, which is not what I need. Our PDF is created with Adobe Illustrator (or a similar adobe product) and is high-res with embedded fonts, svg and image content.
The form elements are in place, we just need to get the data to there.
Update April 11, 2013:
Since posting this question I have been utilizing FPDF on multiple projects where I needed to accomplish this goal. Although it cannot seem to "merge" template PDFs with the provided data, it can create the PDF from scratch.
One example I have used, I had a high resolution PNG for printing (similar to initial question) which we had to write the customer's name and today's date clearly in the center. I simply made the background of the PDF using FPDF->Image() and write the text afterwards using FPDF->Text().
It was very simple after all, you will need to look up the paper sizes to determine the X,Y,W,H of the image and then base your text fields relative to those numbers.
There was even a Form Filling extension, but I couldn't get it to work.
It seems as though I should answer my own question, although Visions answer may be better (seems to be deleted?). I used Vasiliy Faronov's link which was a comment to my main question: https://stackoverflow.com/a/1890835/200445
Here I found how to install pdftk and run a command to merge (flatten) my FDF and PDF files. I still used the "hacky" way to generate an FDF using Koivi's FDF Generator but it works for the most part.
One caveat is that some characters, like single and double quotes are not inserted correctly. It may be an issue of escaping the fields, but I could not find an answer.
Regardless, my PDF form generator is working, but anyone with a similar issue should look for a better solution.
There are number of tools which are not paid like itextsharp. try the following https://web.archive.org/web/20211020001747/https://www.4guysfromrolla.com/articles/030211-1.aspx Hope this code will help you. I have tried it its worked for me. If you can pay then there are number of paid tools which convert the HtML to PDF like ABCPDF etc.This example is in Asp.net and i am sure if you can convert it in PHP it will work for you too.
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.
I have an already pre-designed PDF, and I would like to fill the PDF with some database information. So I'm curious if I should save the PDF into JPG's and render them out with the data on top of the image and re-create a PDF.
Or is there a way to use the PDF already, and print data into the PDF that is already made?
I am trying to figure out the best solution to generating this type of PDF.
All thoughts would be greatly appreciated!
You can read about PHP's PDF library here: http://php.net/manual/book.pdf.php
PHP also recommends these alternatives:
http://www.fpdf.org/
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
http://php.net/manual/book.haru.php
PDF files support the use of interactive form fields, so the best method for adding information to a PDF from a database, is add form fields to your database and find a library that let's you fill out PDF forms programatically.
Rendering a PDF to an image just to write information on it and then converting it back to a PDF would mean that no text was selectable in the new PDF unless you OCR'd it, which isn't the most optimal way to do it.
After a bit more digging, I was able to use Zend PDF within the framework to update the PDF quite easily. It was my first time using the Zend Framework, and found it quite useful. I suggest anyone trying to manipulate PDF's use Zend.
Just my .02 though. I appreciate your pointers though that were given.