6

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.

Community
  • 1
  • 1
Radley Sustaire
  • 3,382
  • 9
  • 37
  • 48
  • 3
    That code you linked to seems more or less a hack. It is simply inserting strings into a binary file. I assume you could do a similar thing with a PDF document. A non-hackish solution, although it would be a lot slower, is to have code that generates a LaTeX document, then compiles it into a PDF. – Jay Sullivan Jun 22 '12 at 21:33
  • http://stackoverflow.com/a/1890835/200445 ? – Vasiliy Faronov Jun 22 '12 at 21:44
  • @VasiliyFaronov looks like pdftk is what I need, i'll give that a try – Radley Sustaire Jun 22 '12 at 22:07
  • 1
    you could also try TCPDF been using this for a long time, a little hard to start with if you're a beginner but it can generate pdf files on the fly – Dany Khalife Jun 24 '12 at 16:21

2 Answers2

2

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.

Community
  • 1
  • 1
Radley Sustaire
  • 3,382
  • 9
  • 37
  • 48
1

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.

Ram
  • 1,131
  • 10
  • 28
  • 52
  • Thanks for the tip. I did end up going with pdftk and got it working with the previous "hacky" FDF generation. Although some characters like apostraphe's and quotes do not seem to go through for some reason, it's functioning well enough. – Radley Sustaire Jun 26 '12 at 05:44
  • its just a little example mainly what you asked if you want to go more studies for itextsharp then visit http://www.4guysfromrolla.com/articles/030911-1.aspx and http://www.c-sharpcorner.com/uploadfile/f2e803/basic-pdf-creation-using-itextsharp-part-i/ – Ram Jun 26 '12 at 05:54