Page 1 of 1

printing with php

Posted: Wed Dec 17, 2003 4:47 am
by chadgwee
basically i need to print a document using php print functions. But i juz wonder anyone out there can suggest a better way to do it.

I searched on the web for php printing class (something like pdf class). but i got nothing.

Can anyone tell me if i can juz read a file and print the content in the exact format to the printer.

Posted: Wed Dec 17, 2003 8:33 am
by Stoker
the builtin PHP printer functions only works on windows, there was an article about how to use this in PHP|Architect a couple of months ago, go to their web site and purchase this issue it gives you a good start..

If you are using a sane system (Not windows) you can use pretty much any layout format, like Latex or PDF, and then use some shell commands (like lpr or similar) with some Unix print service, the easiest one to set up is likely CUPS..

Posted: Wed Dec 17, 2003 9:26 am
by aquila125
PHP isn't build for this kind of operations... better take a look at perl or c++ (c)

Posted: Wed Dec 17, 2003 9:32 am
by Draco_03
hehe a "sane" platform..
pfftt
:P

Posted: Wed Dec 17, 2003 9:57 am
by Stoker
aquila125 wrote:PHP isn't build for this kind of operations... better take a look at perl or c++ (c)
Perl is a very good tool for text processing...

"Better have a look at C++" does not make any sense to me, its not something you learn overnight and throw something together the next day, although it may compile and do your stuff its very likely not to be protected in any way (overflows etc) and in my opinion C/C++ is far from a good text and layout processing tool..

PHP can do the job just fine, Perl can do it better

Posted: Thu Dec 18, 2003 12:47 am
by chadgwee
Thanks for all of you guys advice.. but due to the project requirements, php is only considered and it is going to run on win XP with IIS ISAPI...
so anyone out there know there is way or classes available to parse a document in for printing?

Posted: Thu Dec 18, 2003 2:26 am
by m3mn0n
It's pretty simple.

Make a new page that is seperate from your layout, with only the text you would like to print (the php parsing part).

In a regular page you would most likely color, stylize, and format this text but with the print page, avoid doing that. Most people I've seen make this a seperate popup, and use just black/white text and throw in a site logo for good measure.

Then use the [google]javascript print[/google] features to send the Print dialog to the users.

If you want a class or function that can do this for you, try searching around some major open source sites and code libraries. PHPBuilder, HotScripts, etc.

Posted: Thu Dec 18, 2003 2:53 am
by chadgwee
Thanks for advice...i know there is way to use browser with javascript to print out the content..in fact i have done few projects with this kinda printing. but now i'm looking for using php functions to spool the print job to the selected printer instead of using browser printing. Because by using browser printing, it seems to be a bit slow and the page format is control by the browser itself.


Sami wrote:It's pretty simple.

Make a new page that is seperate from your layout, with only the text you would like to print (the php parsing part).

In a regular page you would most likely color, stylize, and format this text but with the print page, avoid doing that. Most people I've seen make this a seperate popup, and use just black/white text and throw in a site logo for good measure.

Then use the [google]javascript print[/google] features to send the Print dialog to the users.

If you want a class or function that can do this for you, try searching around some major open source sites and code libraries. PHPBuilder, HotScripts, etc.

Posted: Thu Dec 18, 2003 4:23 am
by m3mn0n
Well the page formatting is controlled by you, the browser only interprets your instructions. So if you format it in a way that it's acceptable to print, a simply js print() call shall do the trick. And it's the only option since php doesn't really do that. Printing is a clientside thing, PHP works on the serverside.

Posted: Thu Dec 18, 2003 2:35 pm
by Stoker
... as I wrote in my first post; Purchase the issue of PHP|A and it gives you a very good start on how to use PHPs print functions on windows.