Xojo Conferences

« LDAP in FileMaker | Home | Xojo 2015r4 »

Print to Printer in Xojo on Windows

We do have quite a few printing classes in our MBS Xojo Win plugin for Windows. You can query installed printers, learn about page formats and print jobs, show page setup and print dialogs, modify the device mode and create print jobs.

As we can enumerate printers, we can show them in a popupmenu. User can select one and we modify the printer setup string for a Xojo printerSetup object and than use normal Xojo printing functions to print:

// now we have nice setupstring dim ss as string = ps.SetupString 'MsgBox str(len(ss)) // parse it in device mode, to retain settings there dim d as WindowsDeviceModeMBS = WindowsDeviceModeMBS.FromSetupString(ss) if d = nil then // or start with a blank one d = new WindowsDeviceModeMBS end if // change printer if PopupPrinter.ListIndex >= 0 then dim w as WindowsPrinterInfoMBS = PopupPrinter.RowTag(PopupPrinter.ListIndex) // set device name d.DeviceName = w.PrinterName else MsgBox "No printer selected." Return end if // enable duplex 'd.Fields = BitwiseOr(d.Fields, d.DM_DUPLEX) 'd.Duplex = d.DMDUP_HORIZONTAL // get back as setup string dim da as string = d.SetupString if da = "" then MsgBox "failed to create setup string" Return end if // assign back ps.SetupString = da // and print something dim g as Graphics = OpenPrinter(ps) g.DrawString "Page on "+d.DeviceName, 50, 50
PS: Works in Real Studio, too.
17 12 15 - 09:43