Hi guys (and girls),
I'm a compleet newbie (this is my first post). I have been looking for a possibility to print to my printer from my localhost website.

How? I want a button with PHP code behind it that prints a piece of tekst with info from a mysql database. Getting the info from the database is not the problem but then........

Nico

    well php is server side script, so you cant tell it to output to a printer anywhere since the computer that's running the script could (conceivably) be in a different continent.

    I think there's a javascript function that will print a page, but it will do no more than can be achieved by clicking on the file menu, and then going to "Print". If you want to print to a printer other than your default one, then you have to select it from the list in the printer dialogue that will appear.

    There's no way of automatically making something print by clicking on a button, and thank god - popup windows are bad enough. Can you imagine going to a website and your printer jerks into action as it prints off spam direct to your printer without you even asking it to? ohhh it makes the skin crawl...

      jpmoriarty is very correct, and btw the function he is talking about with javascript is window.print()

        oke, jpmoriarty, I understand. Your post is clear. But, I make a piece of work that only works in an intranet and if it has to print it has to do that on the printer that's attached to the server.

        So I am looking for a solution to a problem: how to print stuff that is produced by an application that is running on an intranet. Maybe writing documents to disk with PHP and print this file with an office suit? Is there an easy format for writting documents to disk? I mean, can php make and write StarOffice or MsOffice documents?

        Nico

          well i guess it depends what type of information it is. If it's text, then theres no reason why you couldnt just format it nicely using a style sheet and then print it from internet explorer, netscape, whatever.

          If it's a big table from a database or somehting, then you could try outputting it as a CSV file, and then import it into excel or something. hell if you really got into it i think you can even create an excel / word document straight from php.

          What is it you're looking to output and why? Knowing that might help us to help you, as it were.

            Yes, a good idea. I want to print nice looking documents as a bill. Until now Publisher (Ms) is used for that (highly graphical), but then, it looks good.

            I think is will be a problem to produce publicer files but I am willing to accept other formats that look good to, i am thinking of RTF or someting.

            Nico

              Here is something that could help

              1 - the PHP script writes a .HTM that is formated correctly, the time/date being the name

              2 - A program on the server sees that there is a new file and prints the RESULT of the code (not the actule HTML code).

              3 - Some paper-pushing gimp picks it up and fears the sound of the printer as his/her desk fills up with what is left of the amazon.

                90nz0 sounds about right to me. Alternatively, you could create PDF's dynamically, rather than HTML (since i always find that IE likes to print one line of text at the top of an otherwise blank page - no matter how big or small the page i'm trying to print, there's always one line on the last page. ba$tards...)

                you could then do something like have an "admin" page, that would look in a directory (which is the directory your pdf files will be created into), and your student/ monkey could go in there and select which files he wants to print off. Then when he selects them, they will be dynamically moved to a different folder (shall we call it archive? i think we shall), and he can collect the prints off the printer.

                Or something along those lines...

                  So, if I understand this correctly, I must let PHP make a pdf file (can php make one? I didn't know that) and place that in a folder. I'm using linux on my server, so starting an program on the server that I give the right filename and printername that print out the pdf?

                  That's how it works then?

                  Nico

                  This has an other advance: I keep backups in this folder of all my printouts!

                    Cheers jpmoriarty.

                    BTW - stupid question - what's the data stored on? If it's stored on some kind of ACCESS / SQL type thing. And on a win server. It would be quite easy to make a VB program that is constantly connected to the DB and updates when the DB changes.

                    When the OnChange is true (say, capture ID as $smeg, and when $NuSmeg , you could set it to open up a PHP page that accepts an ID like "KillTheAmazon.php?id=123".

                    "KillTheAmazon.php" would actualy result a PDF file (Click here for a good PDF script), and then the VB program can process it'n'print.

                      No, I'm not using windows. I use Linux so VB is out of the question. I have found on the net pdfprint (for linux) and a plug in for php to produce pdf files. So I think (have to figure out how) that I can make a pdf file, call pdfprint from php and print the file on a printer attached to my server.

                      Ready. Or not? Am I missing someting?

                      Nico

                        Yes indeed it is. I think maybe system, maybe exec, I have to look in to that. But one of these two will be the command to use.

                        Thank's 90Nz0. I think I will figure this one out now.

                        Greeting's and thank's, Nico Berg

                          Coolios

                          When you work it out, please do post the correct code, i'ld be interested to see how it works.

                            Write a Reply...