Question

Is it possible to use SWT PrintDialog just to display the local printers and then return the selected printer value?

I have a print class that works well for me. I pass in the following variables to the class.

String filePath String printerName String jobName

I call the Print class from my GUI class the following way.

new AplotPdfPrintLocal().printPDF("c:\\Temp\\test.pdf", "\\\\PrintServer\\MyPrinter","PDF Print Job");

Right now the call is passing in the default printer.

Before the above call, I would be great to open a local printer dialog (Like PrintDialog). Be able to select a local printer, then call my Print Class with the selected printer value. I would prefer to have my Print Class preform the printing action instead of PrintDialog.

I was thinking that when the OK button is pressed in the PrintDialog, we go do something like the following pseudo code

public void widgetSelected(SelectionEvent e) {
   new AplotPdfPrintLocal().printPDF("c:\\Temp\\test.pdf", "SelectedPrinterValue","PDF Print Job");
}

Is this possible?
Is there a better way to preform this action?

I know there is a way to look up the local printers (PrinterJob.lookupPrintServices()). But I really don't want to have to write a new dialog around it, I would rather use a pre written existing Dialog like PrintDialog

Was it helpful?

Solution

PrintDialog provides you native printing options. If you do not want to use PrintDialog then you end up setting all printing options ( PrintData and other paper option..etc that you see in PrintDialog).

Define PrintData with print options and create Printer(printerdata) and start printing job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top