i have add a menu item print in the File Menu and when i click the print menu item the print dialog should open as it is opening in MsWord i am using the following code for the dialog to pop up , but it does not pop up, if anyone know how to resolve it, it would be great helpfull to me.
The code that i used is
FileDialog fileChooser = new FileDialog(shell, SWT.OPEN);
String fileName = fileChooser.open();
if (fileName == null) { return; }
// Load the image
ImageLoader loader = new ImageLoader();
ImageData[] imageData = loader.load(fileName);
PrinterData printerData = null;
if (imageData.length > 0) {//
// Show the Choose Printer dialog
PrintDialog dialog = new PrintDialog(shell, SWT.CLOSE);
try{
printerData = dialog.open();
}catch(Exception e){
e.printStackTrace();
}
if (printerData != null) {
// Create the printer object
Printer printer = new Printer(printerData);
// Calculate the scale factor between the screen resolution and printer
// resolution in order to correctly size the image for the printer
Point screenDPI = display.getDPI();
Point printerDPI = printer.getDPI();
int scaleFactor = printerDPI.x / screenDPI.x;
// Determine the bounds of the entire area of the printer
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
// Start the print job
if (printer.startJob(fileName)) {
if (printer.startPage()) {
GC gc = new GC(printer);
Image printerImage = new Image(printer, imageData[0]);
// Draw the image
gc.drawImage(printerImage, 0, 0, imageData[0].width,
imageData[0].height, -trim.x, -trim.y,
scaleFactor * imageData[0].width,
scaleFactor * imageData[0].height);
// Clean up
printerImage.dispose();
gc.dispose();
printer.endPage();
}
}
// End the job and dispose the printer
printer.endJob();
printer.dispose();
} else {
System.out.println("No data to print");
}
KINDLY HELP ME TO KNOW IF ANY THING THAT NEEDED TO BE CHANGED TO BRING THE PRINTER DIALOG BOX.