Solved

What is the simplest way to print in php?

Posted on 2004-04-13
7
274 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
Cijori earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mail Not Sent 6 40
PHP question(s) about order of output 9 37
mysql Encryption with PHP 8 44
how to resize preview image 4 27
This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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 …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now