# print Print Remote Document From Within PHP



## snorkytheweasel (May 3, 2006)

Using PHP, I want to enable the user to print a (remote) PDF document. I know how to enable the user to print the current page in PHP (using javascript). How do I enable the user to print a document that is not the current page ?


----------



## 00trav (Sep 6, 2007)

I don't know if this is an answer, but...
you could create a php function that calls a special php page that is designed to print to pdf the remote information you need. 
here is an example.
http://www.devarticles.com/c/a/PHP/Use-PHP-to-Create-Dynamic-pdf-Files/
my suggestion is to make a specific print_function_module with pdf print template.

here is more info on the php pdf functions
http://us.php.net/pdf


----------



## snorkytheweasel (May 3, 2006)

I guess I didn't explain very well.

On the web server I have many types of documents: html, pdf, gif/jpg/png, and so on. The file I mentioned is a pdf, but don't get hung up on the term "pdf".

What I want to do is to print a document - any type of document - from the web server to a hardware device (a printer) available to the client computer.

Since PHP operates on the server side, and a printer is on the client side, I suspect that I need to do this with javascript - which operates on the client side - within my PHP code.

For example, this will print the current page to a local printer (hardware):
PRINT

How do enable the user to print - to a local printer (hardware) - a document that is not the current page?


----------



## 00trav (Sep 6, 2007)

Sorry for my confusion. 
As to your real question: I am not a javascript expert so I don't have a clean answer to you.
but, I have accomplished something similar to what you want with a script that opens another window with the desired document and has the print command and then closes the window. The only problem with this method is that pop up blockers will block it. Although it would be possible to get around this using the href target attribute. You might be able to have a simple javascript function that changes the href link dynamically as you see fit.


----------



## MMJ (Oct 15, 2006)

snorkytheweasel said:


> How do enable the user to print - to a local printer (hardware) - a document that is not the current page?


Hmm... this seems a bit simple.

Change the current page to what you want then print.


----------



## snorkytheweasel (May 3, 2006)

I'm hoping that you're kidding. If it were simple, dozens of people would have jumped in with an answer.

The problem:

for the user it has to be as simple as "push this button."
for me it has to be universal, as in using javascript; for the handful of troglodytes who block all javascript I can code - using HTML - an option to "download that remote document."


----------



## MMJ (Oct 15, 2006)

Can you write some pseudo-code to better explain what you want?

I'm not following you.


----------



## snorkytheweasel (May 3, 2006)

$x = remote_document_url /* e.g., "http://www.mydomain.com/forms/official_document.pdf" */
echo "'Click here to print to official form"
button value="Print"
onClick=write $x to client's printer


----------



## MMJ (Oct 15, 2006)

> What I want to do is to print a document - any type of document - from the web server to a hardware device (a printer) available to the client computer.


You might be able to do this with normal html documents and maybe images but not pdf files as they are either saved or opened with adobe reader.

Just put what you want to print in an iframe and print it.


----------

