Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What is the simplest way to print in php?

Posted on 2004-04-13
7
Medium Priority
?
317 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Accepted Solution

by:
Cijori earned 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

688 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