Jump to content
xisto Community
.hack//GU

Question: Anybody Know How To Make Print Command?

Recommended Posts

I want my site (with PHP) to enable PRINT command. The usual print, with printer as output I mean. So, how can I do it? I've seen my college site use ASP and they can give me a PRINT xommand box, when I click it the printer will print the page.

Share this post


Link to post
Share on other sites

Take a look at the Printer Functions reference. These apparently only work on certain versions of Windows, and require additional PECL extensions (I have not tested any of these functions, and therefore cannot really comment).

There's an example on the print() function listing for sending output to a printer (note that the print() function simply displays output), apparently taken from Tufat.com. This example is also on Windows, and at a glance, appears to utilize Acrobat Reader, Microsoft Word or Microsoft Excel to do the actual printing.

Edited by Spectre (see edit history)

Share this post


Link to post
Share on other sites

isnt is easier to have it in javascript? (you can always escape it into a PHP echo if you really insist)..

<a href="java script:window.print()">Print</a>

nothing wrong with simple stuff :)

Share this post


Link to post
Share on other sites

Yes, doing that in javascript would be a lot easier considering you can add javascript above or below your <?php tag. That's the great thing about php. You could also make it print with a button, not just a link.

Share this post


Link to post
Share on other sites

The example in the print() command reference calls a COM event to trigger the printing, which is similar to how JavaScript operates - however, PHP is server-side, JavaScript is not. I don't think .hack//GU simply wants to print the current page rendered by the browser.

Share this post


Link to post
Share on other sites

The example in the print() command reference calls a COM event to trigger the printing, which is similar to how JavaScript operates - however, PHP is server-side, JavaScript is not. I don't think .hack//GU simply wants to print the current page rendered by the browser.


That is why I mentioned escaping into PHP... as in

<?phpecho "<a href=\"java script:window.print()\">Print</a>;?>

or what ever way of returning you happen to want to use...

Share this post


Link to post
Share on other sites

Ok, now let's review what that does: causes the script to output a simple JavaScript statement in plaintext which the visitor's browser will then interpret as it will, which is exactly the same as adding it in the HTML. It isn't going to execute anything at the server's end, and solves little.

 

I think one (or more?) of us is misunderstanding .hack//GU's problem here. I'm assuming he wants to send output to the printer at the server, not the client. JavaScript has no control over the server whatsoever. All the window.print() function will do is cause the browser the visitor is using (assuming it supports JavaScript) to print the current webpage, with nothing happening at the server's end whatsoever. I don't know why you would want to use PHP to print anything in the first place, but as .hack//GU posted it in the PHP programming forum, I'm assuming that is what he is after.

Share this post


Link to post
Share on other sites

The usual print, with printer as output I mean.

 


I take that as wanting the user to be able to print - with a printer - the page he is viewing. Perhaps .hack//GU would like to correct me?

 

The reason I would do it in PHP is that then you can have it inside a logic syntax, which is rather handy... but then I am probably just too noobish to understand your advanced methods of thinking, arn't I?

 

Also about escaping in PHP - dont use heredoc syntax, even if it is easier...

Share this post


Link to post
Share on other sites

With all due respect - and I do mean that - do you actually know what you're talking about?

 

This:

<?phpecho '<a href="java script:window.print()">Print</a>';?>

Will produce the exact same result as simply placing:

<a href="java script:window.print()">Print</a>

Somewhere in the HTML. All your code is doing is outputting the text. It doesn't use PHP to print at all. Just JavaScript. No PHP. JavaScript only. PHP is not being used. JavaScript is. PHP does nothing here. JavaScript does everything. Outputing code as text does not cause it to be executed in any form; you cannot combine JavaScript and PHP to operate together at a server-level as JavaScript is client-side, and only operates from within the user's browser (if it supports JavaScript, of course).

 

Just to re-iterate: what you are suggesting does not use PHP at all.

 

[edit] For some reason (security?), the IPB code parser is insisting that 'javascript' become 'java script'. There should not be a space in the link.

Edited by Spectre (see edit history)

Share this post


Link to post
Share on other sites

I know very well that PHP would not print the page, lol.

I was only saying that the reaon I would put it in PHP is that you can thereby use it in a logic operation or whatever. Obviously PHP wont print to the user's printer. The only way I know of doing that with PHP is via echoing a javascript command to have the page printed when it makes it to the user's browser. Again, it would not be php creating the print request, but javascript. That would be in the body onLoad event, and would look like

<html><head><title></title></head><body onload="java script:window.print()">and so on...

but that would not be all that user friendly, would it...

I do not want to seem rude, but it would be nice if you could read and understand posts before trying to prove them wrong. I never said PHP would assign the actual printing - PHP was just meant to write the html/javascript and have that fix things for us. There was no real point in putting it in PHP, other that that .hack//GU specified PHP, so I reckoned that this was because he had it in a logic construct in PHP.

//elrohir ar-feiniel

Share this post


Link to post
Share on other sites

I respect your opinion, but I think you're on the wrong track entirely. There is absolutely no point in outputting a JavaScript statement when trying to print via PHP. What you're saying isn't wrong, per se - it is simply out of context and solves little. If .hack//GU wanted to use JavaScript, I'm sure he would have specified it, but instead he has asked how to use PHP to print. Not use PHP to send JavaScript to a client which can then be dealt with. I'd rather not argue about this until further clarification from .hack//GU.

Share this post


Link to post
Share on other sites

Hmm... anyway, thanks for everything. So, you say I need to use JavaScript if I want to print the page... well, I'm still learning beginning JAvaScript, so I barely just knew. Btw, if the computer of the client cannot use JAvaScript, then what I have to do?

Share this post


Link to post
Share on other sites

Btw, if the computer of the client cannot use JAvaScript, then what I have to do?

assume they are smart enough to go file >> print, or if you have a slow audience perhapse a little "To print this page select print from the File menu" thing.
Regarding why wou'd want to print from PHP... Perhapse you have a list of data stored in a table regarding your users and you figured it would be easy to tell the server to do that rather then have your page do it. It would still be easier to have a special page (perhapse inder a password) which generates a list of data you wanted printed and then use javascript on it. But hey just a thought.

Share this post


Link to post
Share on other sites

I respect your opinion, but I think you're on the wrong track entirely. There is absolutely no point in outputting a JavaScript statement when trying to print via PHP. What you're saying isn't wrong, per se - it is simply out of context and solves little. If .hack//GU wanted to use JavaScript, I'm sure he would have specified it, but instead he has asked how to use PHP to print. Not use PHP to send JavaScript to a client which can then be dealt with. I'd rather not argue about this until further clarification from .hack//GU.


sorry, but i think YOU are on the wrong track if you re read his post that i just got done reading(original poster). all he said was he has a php site. probably just a site with a php extenstion that encorporates php code within in somewhere and just wants make it easy for visitors to print a page that doesn't have to be server side.

i think the javascript will do him well, i think he posted in the wrong place, but didn't know any better since his site is php

hack just wanted anything that would work for his site

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.