问题描述
我需要帮助使用 Ruby on Ruby on Rails 将格式化文本发送到打印机,或者从 Ruby 程序将 pdf 文件发送到打印机.我可以编写代码从 Rails 应用程序创建 pdf 文件,但不知道如何将该 pdf 文件打印到默认打印机.我正在尝试使用 Ruby on Rails 编写一个小型票务应用程序.
I need help with sending a formatted text to a printer using Ruby on Ruby on Rails OR sending a pdf file to a printer from Ruby program. I can write the code to create a pdf file from Rails app but don't know how to print that pdf file to a default printer. I am trying to write a small ticketing application with Ruby on Rails.
推荐答案
这是 Windows 环境下的解决方案:Foxit!http://www.foxitsoftware.com/pdf/reader/
Here is a solution in Windows environement : Foxit !http://www.foxitsoftware.com/pdf/reader/
您可以调用foxit.exe(独立可执行文件)在后台静默打印PDF.
You can call foxit.exe (standalone executable) to silently print a PDF in background.
语法:foxit.exe/t "your file.pdf" "打印机名称"
Syntax : foxit.exe /t "your file.pdf" "The Printer Name"
shell = WIN32OLE.new('Shell.Application')
shell.ShellExecute("foxit.exe","/t "#{filename}" "#{printer}"")
这篇关于在 Ruby 中将文件打印到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!