Estou com uma classe para impressão, ela está funcionando bem no linux e no windows XP, só que no Windows Server 2003, ela ta dando erro na hora de exibir o caixa de díalogo da impressão segue aí o código:
public class Imprimir implements Printable {
private Component paraSerImpresso;
public static void printComponent(Component c) {
new Imprimir(c).print();
}
public Imprimir(Component paraSerImpresso) {
this.paraSerImpresso = paraSerImpresso;
}
public void print() {
Paper papel = new Paper();
PageFormat pf = new PageFormat();
double fC = 2.834646D;
double w = 210.0 * fC;
double h = 297.0 * fC;
papel.setSize(w, h);
papel.setImageableArea(0.0, 0.0, w, h);
pf.setPaper(papel);
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
printJob.pageDialog(pf); // <<< O Erro ta ocorrendo aqui, mas somente no Server 2003
// if (printJob.printDialog()) // <<< Aqui tb ocorre o mesmo Erro
try {
printJob.print();
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
}
}
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return(NO_SUCH_PAGE);
} else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
Font font = new Font("Arial", Font.PLAIN, 5);
disableDoubleBuffering(paraSerImpresso);
// g2d.scale(1, 1); // define tamanho
paraSerImpresso.paint(g2d);
enableDoubleBuffering(paraSerImpresso);
return(PAGE_EXISTS);
}
}
/** The speed and quality of printing suffers dramatically if
* any of the containers have double buffering turned on.
* So this turns if off globally.
* @see enableDoubleBuffering
*/
public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
}
/** Re-enables double buffering globally. */
public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}
}
o erro é o seguinte:
Exception in thread “AWT-EventQueue-0” java.security.PrivilegedActionException: java.awt.print.PrinterException: Invalid name of PrintService.
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:1095)
at java.awt.Component.show(Component.java:1422)
at java.awt.Component.setVisible(Component.java:1375)
at java.awt.Window.setVisible(Window.java:806)
at java.awt.Dialog.setVisible(Dialog.java:985)
at merco01.JanelaPedidoGravacao$2.run(JanelaPedidoGravacao.java:108)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.awt.print.PrinterException: Invalid name of PrintService.
at sun.awt.windows.WPrinterJob.setNativePrintService(Native Method)
at sun.awt.windows.WPrinterJob.getPrintService(WPrinterJob.java:573)
at sun.awt.windows.WPrinterJob.pageDialog(WPrinterJob.java:386)
Estou usando o windows como administrador.
Alguem pode me dar uma luz do porque disto ??
Obrigado