How to Print Directly to Printer without showing Preview Window?


I have designed a report in my Xojo Project that compiles a Mac OS X app.
I am using following code to show a preview of the report and then user has to click on Print button to print it.

Dim rpt AS New rptPrescriptionsBig win_PrintPreview.ReportPreviewContainer1.ShowReport(rpt, data) win_PrintPreview.ShowModalWithin(win_ManagePrescription)

In the ShowReport procedure I have following code:

'-Print Report method:
mReport = New rptPrescriptionsBig

Dim ps As New PrinterSetup

// set the resolution to 300 DPI for printing
ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300

If ps.PageSetupDialog Then
Dim g As Graphics
g = OpenPrinterDialog(ps, Nil)
If g <> Nil Then

  // if the report runs successfully
  If mReport.Run(mData, ps) Then
  End If
End If

End If

'-Show Page Method:
ReportScrollbar.Maximum = mReportDocument.Page(mCurrentPage).Height - ReportCanvas.Height
ReportScrollbar.Value = 0


'-Show Report Method:
// Save for use when printing
mReport = rpt
mData = data

Dim ps As New PrinterSetup

If rpt.Run(data, ps) Then
If rpt.Document <> Nil Then
mReportDocument = rpt.Document
mCurrentPage = 1
End If
End If

PrintButton.Enabled = True[/code]

How can I just print directly to default printer instead of having to show a print preview to user and then the user has to click on print button and this win in turn open up a print setup dialog and then it will print.


Yogi Yang

use openprinter instead of openprinterdialog ?


Thanks for the tip. But how to avoid showing the preview?