printing with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chadgwee
Forum Newbie
Posts: 3
Joined: Wed Dec 17, 2003 4:47 am
Contact:

printing with php

Post 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.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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..
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post by aquila125 »

PHP isn't build for this kind of operations... better take a look at perl or c++ (c)
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

hehe a "sane" platform..
pfftt
:P
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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
chadgwee
Forum Newbie
Posts: 3
Joined: Wed Dec 17, 2003 4:47 am
Contact:

Post 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?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
chadgwee
Forum Newbie
Posts: 3
Joined: Wed Dec 17, 2003 4:47 am
Contact:

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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.
Post Reply