PHP Print code (print into paper) - php

Is there a PHP function to print something from a web page (inside the browser)?
I was searching in Google but the result is the print() function. Or any ideas, or any web programming language that you can share. I need a code to print a list of subjects from my database. Sorry for this stupid question. I don't know if that is possible.

If you are talking about a web application, you can bring up the print dialog box with JavaScript using the window.print() function.
Without using activex or other such trickery, there is no way to automatically send something to the printer.
This is a good thing, imagine a malicious web site printing thousands of pages on your machine without your consent.
If you are running a command line php that will depend on the operating system.

If the intention is a print preview, where the user can click an “Print this” button and the server will print the document you can use CUPS if you use a Linux/Apple/BSD server. http://www.cups.org/articles.php?L545+TNews+Q

try this, you need to add php_printer.dll, then enable that extension (after restarting apache)
http://in2.php.net/manual/en/function.printer-write.php

Related

Dreamweaver shows inactive design button for php file

I am using Dreamweaver cs5 . It works normally for all file types except for php files.
Whenever I create or open a php file,Dreamweaver shows a inactive Design and split button on the menu and tab.Only code button is active...
Is there any solution to enable or activate the design button for php files..
Please help
Php cannot be previewed as simply as html can, unfortunately, since it needs to be interpreted to run. It is possible to set up a testing server which will then link in with Dreamweaver and allow you to see the code you write visually, but this isn't as simple as turning a parameter on.
Check out http://www.adobe.com/devnet/dreamweaver/articles/setup_testing_server.html for information on how to achieve this.
Failing that, you could always rename your files to [filename].html while you're working on them? This would show the php code as plain text in the design view, but if you're happy with that then it's a simpler solution that could work for you.
PHP is a server-side language, it is to be processed at the server-side and a resulting HTML is send to the client(A web-browser, generally), from where the page request originated.
Since Dreamweaver does not have any inbuilt PHP engine, or server capabilities it would be difficult(most probably impossible) to get an active view of your PHP page from Dreamweaver as it is, using only the capabilities of Dreamweaver.
So, to solve this you can set some external server like XAMPP,WAMP, etc... and create a project in Dreamweaver with the server settings specified, by doing this you should be able to get a Design view of your PHP code in Dreamweaver. For the exact steps to do this, please refer:
http://www.adobe.com/devnet/dreamweaver/articles/setup_php.html
Courtesy:http://forums.oscommerce.com/topic/386240-open-the-indexphp-in-design-view-in-dreamweaver-cs5/

Printing contents with PHP

I can't really find a topic on how to print a file with the printer.
First off, I dont't mean print like echo, but a real printer.
I want to have the user click on a button, and than it starts printing the page.
The same as javascript:window.print() does, but than with PHP. Is there such option?
Thanks!
Do you mean printing on server-side or client side?
For client-side you can include a javascript snippet which calls the JS function you mentioned:
<?php
print '<input type="button" value="Print this document" onclick="window.print();" />\n';
?>
For server-side: it is definitely more complicated. You could either find a PHP interface, e.g. to CUPS (the standard UNIX printing system) or call a system program that prints the document. Svish posted a link to a CUPS interface as far as I see an interface to printing in MS Windows (useful only if the server is running under Windows, of course).
Edit: If you expect to find a solution which prints the page PHP outputs rendered by the client browser and but not printed on the client, but on the server -- this should be impossible. I guess you could implement sending the output of PHP the a system program that renders the page itself but it will never look 100% like on the client. Maybe it's acceptable to call a printing program on the server, pass all necessary information to it and it renders some document of its own, e.g. an RTF text file?
PHP works server-side and therefore cannot print anything on the client-side. It can't do anything on the client-side actually, other than via generated HTML, CSS, JavaScript, etc. PHP can talk to a printer though, but it would be a server-side printer as far as I know.
SO, if you want the user to click a button to print a page, on their printer, it would have to be something client-side. For example JavaScript.
As PHP is a server-side scripting language, this wouldn't be possible.
You cannot have the user print a document from his printer using PHP.
If the design of the printed document is undesirable, you can either add a print stylesheet.
Or have a printer friendly page.
For example; passing a get variable called printer will have your php script echo another design of your page.
If you are talking about a server-side printer, you can.

simulate mouse move in php?

⚠ In this question, PHP is used in an unusual way. It is not used as a server side language ("no browser is open"). It is intended to be run on my own computer, simulating mouse move on my computer.
Is it possible to simulate mouse's move in PHP ? By that I mean to do something like :
$mouse->moveToCoordinate($x,$Y); // will move the screen to to the coordinate $X, $Y of the screen
$mouse->moveVector($x,$Y); // will move from the current point to the (current X + $X, current Y + $Y);
$mouse->click(); // will simulate a mouse click on the screen.
This should be usable, even if no browser is open (so cannot use the classic browser-side javascript solution).
1 - use exec() and : Simulate mouse movement in Ubuntu . Basically, use any other language, compile it if needed, and use the executable with argument throughout command line.
2 - PHP-QT might do the trick
| IT IS POSSIBLE !!! |
People have suggested to use another language (javascript), but for this problem, it's not possible to use a browser. So other languages will do the trick.
Thanks for your message though, and if anybody have other solutions, I'd be interested to know them.
PHP is a server side scripting language and cannot do that. You should do that by Javascript. It's possible to do that from PHP (write needed Javascript in PHP and send to client). The most real-time solution is using AJAX but you still suffering round-trip lags depending on client speed.
Just as an exercise.
It might be possible to write standalone desktop PHP app that has access to user pointer. For that you have to use bindings such as http://gtk.php.net/ (there were Qt bindings some time ago, but project seems to be dead).
And even that it might be hard. PHP-GTK is not well documented at this moment.
+1 To everything that was said before.
I'll add that more details on the goal is needed.
Depending on what you really want (A click to do what ? On what ? etc...), you can still use cURL to reach a page, parsing it and following to the link you want (if that's a link you want to click...), entering a whole form and submiting it, etc...
You can access to the html code and save it in a file on your server (if that's what you need.) etc... etc...
Anyway, as everyone said, PHP is server-side and, even as CLI, you need to have a server on your localhost and that will just execute a PHP script, PHP that don't have access to mouse/mouse movement etc without a client-side language like javascript.
IMHO I think your going about whatever it is your trying to do in the wrong way. There is no way to control the users mouse unless your using some sort of remote desktop app as that would be a security issue. That said I could take a guess as some possible things you could do
set focus on an object using javascript
click something using javascript
3 write and applescript (if on a mac) to click something in the finder or automate a process
hth
EDIT
is should also be noted that if you use applescript stuidio you have access to objective c which would let you write code to change the mouse position. but I don't recommend it the user should control the mouse and nothing else should
It's not so hard. Look example.
You can easily edit it and send AJAX HTTP request for x,y positions and return xstart->x , ystart->y.
Hard part is make object to avoid other objects.

Convert HTML page to an image

I want to change my HTML page as an image. Is there a way in PHP to change or save an HTML page as an image?
This is not easy; as NullUserException says in his comment, you would need to render the HTML page on the server-side, which is not something PHP (or any other server-sided language) has built in.
The approach that comes to mind would be to write a program (probably not in PHP, but rather something like C# or C++) that runs on your server, fires up a web browser, and does a series of screen captures (possibly combined with page scrolls). As this is a very nontrivial and bug-prone process, I would suggest looking into third-party components that are capable of doing this.
You would then execute this program from PHP, and when it's done running, display the results from the file it output.
I would advise you to use an external service with an api. This list might be a good start: http://blogs.sitepoint.com/2008/07/10/9-ways-to-put-site-screenshots-in-your-web-app/
Thumbalizr seems great, they allso provide a php script so you can cache the images locally:
http://www.thumbalizr.com/apitools.php
Try taking a look at browsershots.org - source code is available for it if you want to install it locally. Essentially it uses a browser to take screenshots, and can be controlled via an XML-RPC interface, which you can call from PHP.
As others have said this is not a simple job, and not something you can do directly in PHP, so use an external service.
(I'm not affiliated with browsershots.org in any way)

how do you take a snapshot of your current browser window using php

I've tried searching everywhere but there's seems to be no implementation available other than having the client use a file (batch/exe of some sort).
You just can't do it. PHP is server side scripting language, maybe you can do that using JavaScript, but I'm not even sure about that.
I know someone implemented such service, but actually he had to use Mozilla browser, which opened, a script (I think it was not JS, maybe perl, c/c++) made a screenshot and uploaded it.
I'm assuming you mean "your" in the general sense. If you mean "how does one take a screenshot...", you generally hit the print screen key. If you're trying to capture your users' browser output, I'd say that it's probably not possible. If it were, the best you could get is the output of what you wrote yourself.
Google Gears might be hackable to do something close, if you can simulate the print screen key press with JS and get the file to save somewhere gears can access.
You can't do that in PHP, as PHP is running on the server, and not the client.
To get screenshots of the browser, you can take a look at, for instance, this list.
If you are look for an automated solution to take screenshot of web pages opened in a browser window, you could also look at this question : How to capture x screen using PHP, shell_exe and scrot and it's answers.
And, finally, and without selecting any particular post, you can try a search on SO ; something like screenshot browser, sorted by relevance, seems to get some interesting posts :-)
Good luck !

Categories