dmikester1 Posted March 13, 2012 Share Posted March 13, 2012 Anyone know how I can print a file (specifically a PDF) that is stored on the server to the clients computer with a button? I don't want them to be able to view it, just print it. I've done some research and understand that there is no way to print directly without popping up the Windows Print dialog. And that is fine. I just want them to print this file, but not no where it is or be able to type in a URL to access it. Thanks Mike Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/ Share on other sites More sharing options...
Psycho Posted March 13, 2012 Share Posted March 13, 2012 I don't believe it is possible via a Web Server/Client methodology. I know there is technology to print via the internet (i.e. while at work I could print something on my home PC). Although, I've never needed to do that so I don't know the specifics. But, I'm pretty sure the client machine has to have access to the file. Generally speaking, the computer that is sending the job to the printer is responsible for determining "how" the file is rendered. Although, you can do some things with PostScript files to send to the printer directly and the printer will do the rendering itself. But, even if you could do something like that, many printers don't have that capability. In the end, it would also seem like a security issue. Just think about some malicious site that would randomly start printing stuff to your printer. If you can do it, so would others. And they definitely would. If you are allowing the user to print the file, what objection do you have to them viewing it. They could just scan the printed page to make their own PDF anyway. Maybe what you really want to do is to secure the PDF, which is definitely doable. Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326842 Share on other sites More sharing options...
litebearer Posted March 13, 2012 Share Posted March 13, 2012 http://stackoverflow.com/questions/2679524/block-direct-access-to-a-file-over-http-but-allow-php-script-access Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326845 Share on other sites More sharing options...
Psycho Posted March 13, 2012 Share Posted March 13, 2012 http://stackoverflow.com/questions/2679524/block-direct-access-to-a-file-over-http-but-allow-php-script-access Putting the file in a non web-accessible location doesn't do what the OP is asking for. He wants the users to be able to print the file without viewing it. They would still have to access the file regardless if it is in a web-accessible location or not is not the issue. Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326852 Share on other sites More sharing options...
dmikester1 Posted March 13, 2012 Author Share Posted March 13, 2012 I already have the folder access denied with a .htaccess file. I was thinking about writing a script that would copy the file to a temp directory, print it, then delete the temp file. I just can't figure out how to print the file in PHP without displaying it. I realize the user can scan it and make copies, but at least we are partially preventing duplicating. Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326857 Share on other sites More sharing options...
litebearer Posted March 13, 2012 Share Posted March 13, 2012 Per OP just want them to print this file, but not no where it is or be able to type in a URL to access it. IMHO that means make it non accessible. Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326858 Share on other sites More sharing options...
litebearer Posted March 13, 2012 Share Posted March 13, 2012 And I agree with Pyscho... In the end, it would also seem like a security issue. Just think about some malicious site that would randomly start printing stuff to your printer. If you can do it, so would others. And they definitely would. Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326863 Share on other sites More sharing options...
Psycho Posted March 13, 2012 Share Posted March 13, 2012 Per OP just want them to print this file, but not no where it is or be able to type in a URL to access it. IMHO that means make it non accessible. True, but the core issue is about being able to print the file without accessing it. I was thinking about writing a script that would copy the file to a temp directory, print it, then delete the temp file. I just can't figure out how to print the file in PHP without displaying it. I realize the user can scan it and make copies, but at least we are partially preventing duplicating. A temp directory where? on the user's machine? You have no control over files that are sent to the user - none. I've seen many sites that try to "secure" content via JavaScript by disabling the view source feature or using transparent images over content. Those are all useless, because 1) the user can typically disable the features that are preventing them and the content is already stored in their browser cache. The web server cannot control what the user's machine does with the files/content it sends them. So, those files are just sitting in the user's cache to do whatever they want with them. You should really look into the protection features available in PDFs. Take a look here: http://www.locklizard.com/pdf_security_features.htm Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326870 Share on other sites More sharing options...
dmikester1 Posted March 13, 2012 Author Share Posted March 13, 2012 The temp directory would be on the server. I have no doubts that anyone determined would be able to bypass the restrictions, but for legal purposes we have to make it look like we at least tried some prevention and security. My co-worker said something he has found is that some people end up converting the pdf to an swf file to get the security they desire. Maybe we'll end up going that route. That locklizard looks nice, but pretty pricey. Thanks for the answers. Mike Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326886 Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2012 Share Posted March 13, 2012 That bottom line here is that PHP can't control anything on the client pc. You might be able to find a java applet that would provide the functionality, like the major coupon sites use for printing coupons. Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326891 Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2012 Share Posted March 13, 2012 That bottom line here is that PHP can't control anything on the client pc. You might be able to find a java applet that would provide the functionality, like the major coupon sites use for printing coupons. Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326892 Share on other sites More sharing options...
dmikester1 Posted March 13, 2012 Author Share Posted March 13, 2012 Found a script that will password protect a pdf and dis-allow printing in the pdf file. This could be helpful: http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326899 Share on other sites More sharing options...
Psycho Posted March 13, 2012 Share Posted March 13, 2012 Found a script that will password protect a pdf and dis-allow printing in the pdf file. This could be helpful: http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php Not to be rude, but have you actually read this thread? He wants the user to print the PDF, but not view it. @dmikester1, there are plenty of other solutions for securing a PDF file, I simply provided a link to one possible resource. There are plenty of PDF security measures available. But, if you have a flash solution, go for it. This all seems hokey to me, but it's your product. Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326912 Share on other sites More sharing options...
dragon_sa Posted March 13, 2012 Share Posted March 13, 2012 I did find this, but not sure if its a valid option for what you want to achieve http://stackoverflow.com/questions/3915500/how-to-enable-direct-printing-capabilities-for-web-based-application Regarding the storing in a htaccess deny from all directory, I just did this with my own version of captcha I made. I have Images in a protected directory, I use php to select a random image in my case, and I copy it to what I call a transfer directory with a new name, the new name is a md5 of time(), a salt and part of the original image name, so no matter which image gets loaded the name is never the same, I delete all images in the directory with every page load so its only valid for the 1 time it is shown, I am guessing a combination of something like that and the hidden iframe solution in the above link may suit your needs. Quote Link to comment https://forums.phpfreaks.com/topic/258834-print-a-pdf-file-from-the-server-to-the-client-without-displaying-file/#findComment-1326994 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.