Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit HTML form to PDF

Tags:

html

forms

php

pdf

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.

like image 453
Radley Sustaire Avatar asked Jun 22 '12 21:06

Radley Sustaire


1 Answers

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.

like image 81
Radley Sustaire Avatar answered Oct 22 '22 11:10

Radley Sustaire