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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

What is the simplest way to print in php?

I would like to have a formatted report print on a user's default printer when prompted.  I don't have any prepared file, it would have to be created from mysql.
Thanks,
Russ
0
RUSS_EMI
Asked:
RUSS_EMI
  • 3
  • 3
1 Solution
 
madwaxCommented:
Easiest is to use some sort of a pdf-generator:

http://www.dynamicpdf.com/Products/default.asp
http://www.planetpdf.com/mainpage.asp?webpageid=3250
http://www.fpdf.org

whereas I have used the fpdf myself with very good results... =o)

//jan
0
 
CijoriCommented:
PHP can't print on it's own, however if you're outputting HTML then you can use JavaScript to bring up the print menu, by replacing the line <body> with <body onload="window.print();">,or, to display a question first: <body onload="if(confirm("Would you like to print this page?"))window.print;">.

Hope that helps.
0
 
RUSS_EMIAuthor Commented:
Is it possible to create a text file (with php) and ask the user if they wish to print it (java script)?  That way they wouldn't get all the extra stuff that may be on the page.
Thanks,
Russ
0
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!

 
CijoriCommented:
No, JavaScript only works on an HTML page. However, if you create a text file and then add:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Your HTML File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body onload="if(confirm("Would you like to print this page?"))window.print;">

to the top of it and:

</body></html>

to the bottom then it will be an HTML file, but the content that they see when they print and on screen will be the same.

0
 
madwaxCommented:
cijori: "PHP can't print on it's own" it isn't really true...

you can take a look on the following page:
http://www.zend.com/manual/ref.printer.php

//jan
0
 
CijoriCommented:
That's printing on a printer connected to the server not the client though. Not really any use until PHP can also pack it up and post it...
0
 
madwaxCommented:
That's true but I don't really agree with you :)

I have used it a couple of times in my intranet php-applications. Then it's pretty useful, but as you say it isn't used very often though... =o)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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