Print value to printer in ruby

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dakshayini
    New Member
    • Dec 2007
    • 16

    Print value to printer in ruby

    Hello,
    I want to create a pre-printed sheet report in ruby.How can i pass the ruby values to printer?Where do i get the related source?

    Say for example, i have two labels/fields Name and Address one below the other in the report preprinted,i have to pass values of these fields from my application such that the values should place as my fields(one below the other).How can i do this?Help me to solve this.

    Thanks
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    I found a couple methods to print, but I haven't tried either.
    On Windows, you can use the shell to print:
    Code:
    require 'Win32API'
    fname = 'temp.txt'
    shell = Win32API.new("Shell32", "ShellExecute", ['L', 'P', 'P', 'P','P', 'L'], 'L')
    shell.Call(0, "print", fname, 0,0, 1)
    A second method is to open the printer port:
    Code:
    port = "LPT1:" # Windows printer port
    port = "/dev/lpt" # Linux printer port
    File.open(port, "wb") do |printer| 
       printer.write("text and control sequences") 
       # ... 
       printer.flush 
    end

    Comment

    Working...