What is the current recommendation for sending output to printers from FXRuby-based applications? I don''t get much out of the documentation for the FX*Print* classes, and gather from my initial review of the foxgui-users archive that the underlying Fox "print" objects don''t actually work, anyway. (?) I notice that the Fox Adie demonstration program doesn''t print on my (Windows) system. Haven''t tested it under Linux yet. I need to print fairly involved reports, multi-page with headers and footers and embedded graphics. I need the solution to work on both Windows and Linux, although the solution doesn''t have to be the same on both platforms, just produce essentially the same output on both. Do people who print from their FXRuby programs settle for plain text sent to a port? Do you just not print at all? (I see no mention of printing in the fxruby-users archives.) I see some mention of it in ruby-talk, but the only solution actually implemented seems to be some variation on "write to a file, launch IE/Mozilla/Word and make it print the file", a solution I''m not thrilled with. Any better ideas? Any code samples? David Peoples -- David Peoples davidp@touringcyclist.com http://www.touringcyclist.com The Touring Cyclist, 11816 St. Charles Rock Road, Bridgeton MO 63044 tel: 314-739-4648 fax: 314-739-4972
David Peoples wrote:> What is the current recommendation for sending output to printers from > FXRuby-based applications? --snip--I didn''t hear back from anyone, so I''m posting the solution I figured out in case anyone else needs to know later. The basic idea is this: 1) Select the printer and configure it using FXPrintDialog. (This is the only part that requires FXRuby. The rest is straight Ruby code. Printer selection here is optional -- Ghostscript can be configured to do it in step 3 if desired.) 2) Generate the output as a PDF file using the ruby_fpdf library. (Ghostscript requires a real seekable file, so this can''t be just a stream sent through a pipe.) 3) Use Ghostscript to process the PDF file and send it to a printer. Run Ghostscript using Kernel.system. 4) Delete the generated temporary PDF file. This was tested using Ruby 1.8.2, FXRuby 1.2.3, Ghostscript 8.50 and Ruby_fpdf 1.53a. Tested on Windows only, other OSs will require a different Ghostscript command line at least. This solution produces printed output only. There isn''t an embedded PDF viewer for FXRuby that I know of for print previews, although Ghostscript or some other external viewer could be launched to do the print preview. Construction of real PDF reports using ruby_fpdf is an exercise left to the reader. <g> #--- Code start ---# require ''fox12'' require ''fpdf'' include Fox class PrintTester < FXMainWindow def initialize(app) super(app, "Dialog Test", nil, nil, DECOR_ALL, 0, 0, 200, 100) contents = FXHorizontalFrame.new(self, LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y|PACK_UNIFORM_WIDTH) modalButton = FXButton.new(contents, "&Printer Dialog", nil, nil, 0, FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_X|LAYOUT_CENTER_Y) modalButton.connect(SEL_COMMAND, method(:onCmdShowDialogModal)) end def onCmdShowDialogModal(sender, sel, ptr) myPrinterDialog = FXPrintDialog.new(self, "Select printer") if myPrinterDialog.execute == 1 pdf=FPDF.new pdf.AddPage pdf.SetFont(''Arial'',''B'',16) pdf.Cell(40,10,''Hello World!'') pdf.Output(''temp.pdf'') # Lots of options available on the ghostscript command # line. Review the ghostscript documentation. systemCommand = ''gswin32c -dBATCH -dNOPAUSE -dQUIET '' + ''-dNoCancel -sDEVICE=mswinpr2 -sOutputFile="%printer%'' + myPrinterDialog.printer.name + ''" temp.pdf'' system(systemCommand) File.delete(''temp.pdf'') end return 1 end def create super show(PLACEMENT_SCREEN) end end def run application = FXApp.new("Dialog", "FoxTest") PrintTester.new(application) application.create application.run end run #--- Code end ---# -- David Peoples davidp@touringcyclist.com The Touring Cyclist http://www.touringcyclist.com 11816 St. Charles Rock Road, Bridgeton, MO 63044 tel: 314-739-4648 fax: 314-739-4972
Hi, David Peoples wrote: ...> > Do people who print from their FXRuby programs settle for plain text > sent to a port? Do you just not print at all? (I see no mention ofIa small app I use shell = Win32API.new( "shell32", "ShellExecute", [ ''L'',''P'',''P'',''P'',''P'',''L'' ], ''L'' ) shell.Call( 0, "print", fname, 0, 0, 0 ) to print plain text. This only works on Windows boxes for obvious reasons. BTW, nowadays I''d use DL. Apparently this (as your workaround) involves creating a temporary file.> printing in the fxruby-users archives.) I see some mention of it in > ruby-talk, but the only solution actually implemented seems to be some > variation on "write to a file, launch IE/Mozilla/Word and make it print > the file", a solution I''m not thrilled with.Neither am I (with the ''solution'' given above). > Any better ideas? Any code samples? From my early programming experience (using Borlands C++Builder) I seem to recall that printing under Windows is cumbersome. But then there are Win apps out there doing a really good job at printing... My opinion is that printing shouldn''t involve additional software like ghostscript and what-not. If (and when) I develop a GUI based program, in many cases it''s something less experienced user use. And these just don''t understand that printing is (or might) be a problem at all: After all any program can issue a print job - OpenOffice, Word, IrfanView... But I must confess that I couldn''t implement this ''feature'' either. Happy rubying Stephan
Stephan K?mper wrote: ...> Ia small app I use > > shell = Win32API.new( "shell32", "ShellExecute", > [ ''L'',''P'',''P'',''P'',''P'',''L'' ], ''L'' ) > > shell.Call( 0, "print", fname, 0, 0, 0 ) > > to print plain text. This only works on Windows boxes for obvious > reasons. BTW, nowadays I''d use DL. > > Apparently this (as your workaround) involves creating a temporary file. >Thanks for the code example. I did eventually find the similar sample code in the "Programming Ruby" book -- don''t know why I missed that when I asked this question.> > My opinion is that printing shouldn''t involve additional software like > ghostscript and what-not. If (and when) I develop a GUI based program, > in many cases it''s something less experienced user use. And these just > don''t understand that printing is (or might) be a problem at all: After > all any program can issue a print job - OpenOffice, Word, IrfanView... > > But I must confess that I couldn''t implement this ''feature'' either. >I agree that requiring a working installation of Ghostscript to be able to print is several steps worse than ideal. The notion of stringing several specialized tools together to get the job done *is* part of the Unix ethic, but non-technical computer users don''t care about the "Unix ethic", they just want the program to work and not break. I can certainly handle installing and configuring Ghostscript on my company''s machines if we roll out Ruby versions of our programs internally. But Ghostscript isn''t the easiest install (requiring manual editing of the PATH, unless I misunderstood) so I''d hate to have to support that if we ever released these programs to the general public. I guess if we ever *did* release the programs, I''d need to find some sort of uber-installer that can include the Ghostscript installer and automate the PATH update. David> > Happy rubying > > Stephan > > _______________________________________________ > fxruby-users mailing list > fxruby-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users-- David Peoples davidp@touringcyclist.com The Touring Cyclist http://www.touringcyclist.com 11816 St. Charles Rock Road, Bridgeton, MO 63044 tel: 314-739-4648 fax: 314-739-4972