Solved

What is the simplest way to print in php?

Posted on 2004-04-13
7
314 Views
Last Modified: 2006-11-17
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
Comment
Question by:RUSS_EMI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:madwax
ID: 10820501
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
 

Expert Comment

by:Cijori
ID: 10825577
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
 

Author Comment

by:RUSS_EMI
ID: 10825809
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Accepted Solution

by:
Cijori earned 50 total points
ID: 10825867
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
 
LVL 7

Expert Comment

by:madwax
ID: 10826049
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
 

Expert Comment

by:Cijori
ID: 10826189
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
 
LVL 7

Expert Comment

by:madwax
ID: 10826463
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question