开发者

How can I print a PDF directly from my rails app without human intervention?

开发者 https://www.devze.com 2023-02-07 06:16 出处:网络
Currently my web app produces a PDF file in the browser and I manually send it to the printer. I now need to send 100+ variations of the PDF file automatically from my rails app to be printed without

Currently my web app produces a PDF file in the browser and I manually send it to the printer.

I now need to send 100+ variations of the PDF file automatically from my rails app to be printed without human intervention.

How can I do that?

My rails app resides on heroku. I do have my own local printer, but not sure开发者_如何学JAVA what my options are. I researched printers that have an email address, that would be ideal, but wanted other ideas.


If you want to print a PDF from the server, you can use a program that prints to PDF from the command line. On Windows, Foxit will do it. They have a Linux version, but I've only done server-side printing on Windows.


I don't know an easy way, some random thoughts...

  • since it's your app, you could temporarily run it on your development machine, if there aren't too many technical or legal snags with copying enough of the database to make it work ($ heroku db:pull) and then you can probably do something with system('...').

  • you could make a single giant pdf that contained each of the variations. This would at least reduce the human intervention to one click.

  • you can probably make an ssh tunnel between your app on heroku and your local machine using net/ssh, although I can't think of an easy way to take advantage of this.

  • I suppose you could make a quick http-based print server that you run locally (perhaps with a magic auth cookie) and then have your app do client http POSTs to it via net/http or curl or something.

  • You could store the pdf's in a table and have a local cron job or something do "heroku db:pull" and then run a script that extracts the pdfs and prints them.

Somehow I don't think any of these are what you want. I think we may need to know more about why human intervention is ruled out in order to focus in on a real solution.


I don't know how to do it in rails, but try PHP::PRINT::IPP

Install the class from http://www.nongnu.org/phpprintipp/

Then, in a simple example:

<?php
require_once(PrintIPP.php);
$ipp = new PrintIPP();
$ipp->setHost("localhost");
$ipp->setPrinterURI("/printers/epson");
$ipp->setData("./filename.pdf"); // Path to file.
$ipp->printJob();
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号