Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

How to print....


I am writing a web application that at the end prints out an invoice.  I am using a web browser for
my interface web forms to get the information from the user.  The program is all written using php and
mysql.  I am wondering what is the best way to print out my invoices at the end?  If I print the web
page directly from the web brower then i get the http://address and page number printed on the page and I don't want
that printed out on the invoice.  I tried making it create a rtf file which worked ok but I was thinking
of creating a pdf.  What is the easiest way to do this.  I was thinking of creating a template and maybe
do a search and replace.  Can someone please let me know the best way to create a pdf or if someone
has a better idea let me know that.
I really don't want to use pdflib because it cost $500.00 I am not making much from the program.

Has any ever used http://ros.co.nz/pdf/ I just found it now?

  • 2
  • 2
  • 2
  • +3
1 Solution
a easy way..

Use frames and print only the specific frame...

I have created our own invoices using pdf-lib(downloadable from www.pdflib.com). To create pdf's is much better than plain HTML-files. RTF-files is also an option but pdf is after my opinion better because:

* Easier to put text and boxes at an accurate position
* The content of the pdf-document is not that easy to change as the content of an pdf.

I have never used http://ros.co.nz/pdf/ before, but it doesn't seem to be be any better than the original pdf-commands.

So my recommendation is that you use pdf-lib for this task(all pdf-lib commands are described at php.net, and they all start with pdf_ .......)


onestarAuthor Commented:
The biggest issue I have with pdflib is the price $500.00 is a lot of money.  I wouldn't mind paying some money but not that much. It seems kind of weird that it costs so much when php is free.

http://ros.co.nz/pdf/ is free.  So if you don't think its better do you think it close to being equal.  I would rather learn that simply because its free.

I can't believe that these are my only 2 options.  I think creating pdf's are the best option for the invoices.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

I didn't know the price of pdflib. I was so sure that it was free. I think it was free not long ago.

I have checked out the link you gave, and it seems to be a good alternative. One thing I liked about it was that you was able to print html and get the formatting on the pdf. That's not possible with pdf-lib as far as I know.

Why don't you download both pdflib and the code from ros.co.nz and test them out. They don't take any charge for pdflib if you don't use it for a commercial product.

PDF is no matter what a better choice than rtf. A tip if you want to use rtf is to create the rtf-file in for instance wordpad(DON'T USE WORD - It creates a lot of messy code). Then put in your own tags in the document and let php replace the tags with the data of this invoice. For instance:

<firstname> <lastname>

would be replaced with the first and lastname of the person this invoice should be sent to.

The point is to create a rtf-template with some static text and some own tags(a lot like xml-tags). Then use this template in all your invoices, perform search&replace and store a new copy of the modified rtf as the new invoice.

onestarAuthor Commented:
Actually I tried the rtf thing first and it worked okay but then it screwed up my ms word program.  I kept saying some about the dot template has been changed or something like that.  I did what you said with the search and replace.  I don't really like how word intergrates with the web browser compared to pdfs.

What I have done know is created a template in corel and then created a pdf with my tags <<invoice#>> etc... and then did a search and replace on the pdf.  The problem I had is you must be able to create a pdf with it uncompressed so you can find your tags.  I have tried about 15 different ways to create the pdf and only one worked after I did the search and replace most of the time it says the pdf is corrupt.  But the one program I have that worked has a bug with corel and it took out all the spacing in the pdf.  So that's where I am at manually fix all the spacing or find another way. I also have a new job coming up for a company to redesign how there whole company runs using a database, it has a lot of different excel and word documents that will have to be created.  They won't care if I switch them to pdf's so I like to come up with a good way to create dynamic documents that need to be printed correctly.


it works very well, it converts a HTML file to a PDF file.
and it's FREE!!
you have a php sample into the cgi-bin directory
the easiest way I have found is to use a thingy called HTMLDOC which you will have to check is installed.
Even if this doesn't answer your question it will certainly help a few others!
The url for HTMLDOC is http://www.easysw.com/htmldoc/htmldoc.html

The easiest way to use it is as follows.

Convert an existing HTML document
Existing document on server called existing.htm
PHP file called PDF.php which contains:

passthru("htmldoc -t pdf14 --quiet --jpeg size A4 --webpage 'existing.htm'");

Now put a link to PDF.php using the following syntax:

<a href="PDF.php?/random.pdf">Create PDF</a>

This SHOULD generate your page as a PDF. random.pdf is required as the file name even though it is displaying in the browser.

Convert a Dynamic HTML Document
The above solution wont work for database generated content etc. Therefore the solution I use is to create the dynamic content in PHP and then create a static HTML document. Then redirect to the PDF creation link as above so the code would look like this

dynamically generated HTML


header("Location: PDF.php?/$random.pdf");

I hope Ive covered everything.
Force Accepted

Community Support Moderator @Experts Exchange

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now