Jump to content

Recommended Posts

I have been searching for hours to try and figure out how I could print a remote page using PHP.

 

I know in javascript, you can print the current page with:

<a href="javascript:window.print()">Print Page</a>

 

But what I want to do is "javascript:window.print(http://some-link.com)", but would be nice if I could do it using PHP, if it's even possible.

Link to comment
https://forums.phpfreaks.com/topic/255111-print-remote-page-possible/
Share on other sites

The browser can only print the page if the page has been rendered. A web page has no "display" in a sense since each display device (browser, mobile phone, screen reader, etc. may display the page differently.

 

What you are asking is kinda possible, but it requires special software for you to purchase and install on your server. There are packages that allow you to pass the URL of a page you want to generate a printable file for. Typically the output will be in PDF. But, unless you are willing to spend money and have a dedicated server that you can install the software on, you may be out of luck.

technically if you are on windows, (possibly linux too, but I've actually accomplished this on windows) you can use COM objects for windows internet explorer, in kiosk mode (full screen), then you will want to use the php function imagegrabscreen that will take a screenshot of your entire screen,  you can save this to a file, and queue that file for printing, or stream that to your end user, and allow them to print it, if you intend for PHP to print this page FOR the user, its impossible 100%, but if you want PHP to print this, at the server's location, its like 95% possible, if you execute a printing function/program or something using `` or exec

 

Its not impossible, and you honestly don't need to spend money on it, I'm sure there are way better paid alternatives..

 

now before I end this post, I will point you in a few good directions..

 

http://php.net/manual/en/book.com.php

 

http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx

 

http://us.php.net/manual/en/function.imagegrabscreen.php

 

I hope I helped

 

- Russell Crevatas

imagegrabscreen() grabs a screenshot off the server that is running PHP not the client or some remote page. In order to print a web page, the page has to be rendered. This can either be by loading the file into a browser or another application that can read and interpret HTML/CSS (and possibly JavaScript) in order to determine what the page would look like. You can probably find some way to load the remote page into a browser window on the PHP server and then take a screenshot - but it would be a SS of the entire desktop.

 

There are plenty of options for grabbing an external web page via the URL and converting it into a PDF or other format, which you can then serve to the user. Just do a Google search for "HTML to PDF" - plenty of results worth looking at.

psycho, I know this, I explained that in the post above, thats why I linked him to the COM Object Model of internet explorer, and instructed him to use Kiosk mode (full screen)

 

also loading internet explorer as a com object, basically gives you certain events (the same events the browser's environmental javascript uses) to know when the page is fully loaded, etc..

 

I'm even sure there are functions to know if the scrollbar is present and is scrollable, to actually interact with the browser (via php) and scroll the scrollbars, to take screenshots of the entire page, and you can use PHP to fuse the images together with PHP:GD..

 

I mean, Psycho, I don't want to argue, you're totally right that there are probably better alternatives, but if you want a free, totally capable alternative.. Need look no further :P

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.