Solved

What is the simplest way to print in php?

Posted on 2004-04-13
7
291 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

809 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