On Sunday 18 July 2010 09:20:11 am Jeff Johnson wrote: > On 07/18/2010 08:32 AM, Paul McNett wrote: > > On Jul 18, 2010, at 8:19, Jeff Johnson<[email protected]> wrote: > >> Paul: You mentioned the other day that you have a Print and Preview > >> button on your reports. I have only seen things "previewed" because > >> they are sent to a pdf. Would you be willing to share your technique > >> for printing directly to the printer? > > > > While I have preview and print buttons, they do the same thing. I > > simply haven't gotten around to printing directly to the printer yet. > > Sorry for the misinformation! > > > > Paul > > Thanks Paul.
How to print Directly from Dabo Dabo uses ReportLab to generate PDF's (please review the report designer screen cast on the dabo website) from a dataset. But an immeditate question is rasied “How do you print the report directly to the printer”. Below is one way to print PDF's using free products. On windows two app's are required: 1.Ghostscript (http://pages.cs.wisc.edu/~ghost/) 2.Python Win32 Extensions (http://sourceforge.net/projects/pywin32/files/) Ghostscript accepts the PDF file and converts the file to PostScript. The Win32 Extensions provides an easy way to interface with the windows OS to select the default printer. if sys.platform == 'win32': if selectedPrinter=='Default Printer': import win32print selectedPrinter=win32print.GetDefaultPrinter() cmd='.\\ghostview\\gsview\\gsprint.exe -ghostscript ". \\ghostscript\\gs8.64\\bin\\gswin32c.exe" %s %s -printer "%s" "%s" '%(orientation, '-query', selectedPrinter.strip(),outputfile.strip()) #where outputfile is the PDF file produced by reportWriter # where selectedPrinter is what the user picked # then send the command to the OS. sendtoprint = Popen(cmd) I leave it up to the reader design a dialog to retrieve a list of printers (hint try “win32print.EnumPrinters()”) On Linux most distro's already have GhostScript and all printing is done via PostScript so there is nothing to download or install. Linux reconizes the file type of PDF and converts the file to PostScript (in the background linux uses GhostScript) Therefore there is little that is required in the code. cmd= "lp -d %s '%s' " % (selectedPrinter.strip(), outputfile.strip(),) sendtoprint = Popen(cmd, shell = True) On linux I use the “cups” module to assist in providing a means to retrieve available printers (works well with network printers). You may ask why I didn't use wxPython tools to retrieve printer data. I found that on windows (don't know about Linux) I was not able to select network printers. Johnf _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users Searchable Archives: http://leafe.com/archives/search/dabo-users This message: http://leafe.com/archives/byMID/[email protected]
