I'm in the process of building a new pledge management system for one of my clients, a charity foundation. I have already built one for them (it was done using Delphi), but its feature-set is a little limited.

Now, I have decided to move to PHP and use the Laravel framework to manage the database for the new system - its Eloquent ORM allows me to easily implement new features that are needed at present. This is good and well – I know everything that I need to do there. However, I am not sure which direction to take for when it comes to creating, saving, and printing documents that will be hand-delivered to donors.

At the moment, it used Word to process documents - i.e. creating invoices, letters of appreciation, and any other templates that may be selected during a pledge submission. The thing is, I am not extremely happy with the implementation, and don’t believe this is the best route to take. There have been times where the documents did not print correctly, or multiple documents where printed (where only one was needed).

Nonetheless, I could stick to Word, provided that PHP can handle it properly and show me progress as it goes along (i.e. Opening Word -> Opening Invoice Template (companies) -> Replacing Variables -> Saving -> Printing -> Closing -> Opening Food Project Mission Statement -> Replacing Variables - > Saving -> Printing -> Closing … etc.). I guess that progress notifications are not necessary, but I would like to have them there - just in case it freezes, the user would be able to see whatever it may be struggling with.

I would assume that I could do this using a jQuery script (with AJAX) that interfaces with a PHP script, but I honestly have no idea how to do it. (Note: I’d have to use AJAX as Laravel uses buffered output.)

I also know that I could pass the information about a pledge to an EXE which would handle the printing on its own, but I don’t think I want to use this implementation as I have plans to make the system cross-platform.

Question 1: Is there a package for PHP that allows me to create documents, save them, and then print them? If not, is there a suitable package that handles Word without difficulty, and with a large array of features?

If it is the latter, I would need to be able to access the full COM API so that I can prevent dialogs from popping up in the background and pausing the procedure.

Question 2: Is there a package (jQuery, AJAX) available that would allow me to track the progress of the document-creation procedure?


Having reconsidered everything, and weighed the pro's and con's, I would like to put emphasis on printing here. When the user submits a pledge to the database, I need the document to print immediately. I do not necessarily want to focus on a document creation tool only. The reason I asked my question as I did is because I would, ideally, like to find something that can do both the creation and printing of each document. In addition, I do not want to make it too difficult for myself. This is why I originally chose Word - and, it was a lot easier to manage from a Delphi application.

Because of this, I will be leaving the question open (just in case something very interesting is proposed), but will be asking a new question that is a little more specific to the problem that this question originated from.

(To those who have answered so far, thank you for your help and showing me the various options.)


I dont believe PHP alone is well-suited for that task and would suggest looking at LaTex, as long as you can work with PDFs, instead of Word-files.

Latex is primarily used for scientific essay typesetting, but it can do anything related to typesetting and text layout. In science, it commonly replaces word. The .tex-documents are text files that are mostly written by hand, but as its a text file, using php is straightforward.

In your case, the workflow is the following:

  1. Use PHP to load the data you want to print

  2. Have a PHP script to generate a .tex-file

  3. compile the latex file to a pdf.'

  • Thanks, phi. I'll do some research and see if it well-suited to my needs. Mar 31 '13 at 13:11
  • please see my edit. Mar 31 '13 at 13:59

There are a number of choices available to you here.

If Word output is a hard requirement, look into docx - it's basically zipped up XML, so generating it in PHP should be fairly straightforward - collect your data, throw it in an XML format, and convert it to Word XML with XSLT, then zip it up.

If PDF is acceptable, LaTeX is your tool of choice - it produces beautiful output, and its automated typesetting is much, much better than anything Word can ever hope for. Generating TeX source directly from PHP can be a bit daunting, especially if you are not familiar with it, but you can go through an intermediate format. DocBook is one option; there is an excellent docbook-to-latex converter called dblatex. Another option is Pandoc, a tool that can convert from a dozen markup languages (including HTML, markdown, ReStructured Text and Textile) into two dozen or so output formats, including LaTeX. Incidentally, Pandoc can also output .odt and .docx directly, so that might also be an option.

Finally, there are some PDF libraries for PHP that would allow you to output PDF directly, but they are either limited in functionality, or proprietary and expensive, or both. Almost all of them require you to do your own text flowing, and you absolutely don't want that, because, frankly, it is really really hard to get right.

  • Thank you, @tdammers. This focuses more on the actual creation of the document. Please see my edit. Mar 31 '13 at 14:00
  • Ah. I see. I think you'll have to let go of the idea of doing all the printing work on the client side. At best, you'd generate the PDF on the server (which, ideally, should take under a second), send it to the client, and have some javascript magic there to trigger the printing from the web browser. I don't see any other way except having the users install something locally after all - either a browser plugin, or a full desktop application.
    – tdammers
    Mar 31 '13 at 17:18

LaTex will do it, but you could try ASCIIdoc or ReStructuredText instead, both are lightweight formatting systems. Using docUtils, most will produce output in different formats, including .odt which is as good as .doc and can be loaded in Word or LibreOffice if that matters to you more than pdf.

Not the answer you're looking for? Browse other questions tagged or ask your own question.