0

I'm trying to come up with a way of managing documents.

Presently, we're designing our document templates in HTML, then we let our clients fill in a few blanks using CKEditor, and then we use DOMPDF to convert the HTML into a PDF so that they can print the document off.

This works okay, but there are many places it can go wrong. CKEditor messes with the HTML a little bit, and DOMPDF doesn't always convert it perfectly. In particular, we can't do headers and footers properly.

Since our end goal is to produce a PDF, is there a better method of doing all this? For example, we could design the document in either PostScript or LaTeX and then somehow render the PDF directly on our website (no external program!) using JavaScript, with some kind of placeholder textboxes in it so our clients can fill in the needed parts, and then save and export that?

The "fill in" part has to stay on our site because we need to track what they enter for auditing and versioning.

mpen
  • 272,448
  • 266
  • 850
  • 1,236
  • there are fillable pdf forms –  May 01 '13 at 00:06
  • How about if you submit the data from your HTML and assemble the PDF on the server side? – Rafa May 01 '13 at 00:06
  • @YoriKusanagi: Huh? How is that different from what I'm already doing? We create the HTML template ourselves, the HTML is then rendered in a WYSIWYG editor that our clients can edit to their heart's content, and then they click a button that converts it to a PDF (server-side). – mpen May 01 '13 at 01:50
  • @Dagon: I addressed that. That doesn't work for us because we need to track what they enter into the PDF. Once it leaves our site we don't know what they've done with the document. PDF is strictly for printing. – mpen May 01 '13 at 01:50

2 Answers2

1

The best answer to this question will depend on what kind of data your clients are adding to the form.

If they are filling in information in particular fixed-width fields, then the easiest way, as others have also mentioned is to create a fillable PDF, use XFDF to fill it, and PDFTK to flatten it. You can see my answer to another question for a code sample.

However, if your clients are filling in blanks in the middle of lines or paragraphs of text, you won't easily be able to use a fillable PDF. Your suggestion of using PostScript or LaTeX is a good one. If you leave some kind of tokens in the raw file and then replace them on the fly with the data submitted from your web page, you can then call ps2pdf or latex2pdf (or any other conversion program) when the form is submitted to return the completed PDF.

EDIT This isn't what the question meant by "no external program". Your original question asks for "no external program", but many other sources say that there do not appear to be PHP libraries that do this kind of conversion.

Community
  • 1
  • 1
Moshe Katz
  • 15,992
  • 7
  • 69
  • 116
  • What I meant by "no external program" was that I don't want my clients to fill in the document offline. i.e., once it leaves our site, we can't track what they do to that document. We need them enter all the information on our site directly so that we can record all the changes they make to the document. Preferably after they export the PDF it will be "locked" and not easily editable. – mpen May 01 '13 at 01:44
  • Data often is in the middle of a paragraph, but I don't think it's crucial that the text is "tight" around their input. i.e., leaving a fixed-width slot for text is fine. – mpen May 01 '13 at 01:46
0

First you'll need to process your HTML Form data to XFDF format (via createXFDF() function), then you'll want to use code such as:

$pdf_template_path = dirname( __FILE__ ) . '/pdf_form_template.pdf';
$pdftk = '/usr/bin/pdftk';
$pdf_name = substr( $xfdf_file_path, 0, -4 ) . 'pdf';
$result_pdf = $result_directory . '/' . $pdf_name;
$command = "$pdftk $pdf_template_path fill_form $xfdf_file_path output $result_pdf flatten";

which assumes you have a template PDF on your server to write the data to.

> more information here

Dick Faps
  • 135
  • 1
  • 8
  • I also use PDFTK to process XFDF into PDF, but this isn't necessarily the best way. Part of the problem is that this assumes they are filling in predefined locations in the document - the question does not say whether this is the case, or whether they are filling in text inside existing paragraphs or lines of text. – Moshe Katz May 01 '13 at 00:27
  • OP doesn't have an online form.. – Ejaz May 01 '13 at 00:28
  • Ejay's correct. We don't have a bunch of form fields, we have a WYSIWYG editor that lets them fill in parts of the document, or edit it slightly if they need to. – mpen May 01 '13 at 01:52