Меню

No print service found ошибка

I started to create a simple Java application to print «Hello World» with the following code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.print.*;

public class HelloWorldPrinter implements Printable, ActionListener { 

public int print(Graphics g, PageFormat pf, int page) throws
                                                    PrinterException {

    if (page > 0) { /* We have only one page, and 'page' is zero-based */
        return NO_SUCH_PAGE;
    }

    /* User (0,0) is typically outside the imageable area, so we must
     * translate by the X and Y values in the PageFormat to avoid clipping
     */
    Graphics2D g2d = (Graphics2D)g;
    g2d.translate(pf.getImageableX(), pf.getImageableY());

    /* Now we perform our rendering */
    g.drawString("Hello world!", 100, 100);

    /* tell the caller that this page is part of the printed document */
    return PAGE_EXISTS;
}

public void actionPerformed(ActionEvent e) {
     PrinterJob job = PrinterJob.getPrinterJob();
     job.setPrintable(this);
     boolean ok = job.printDialog();
     if (ok) {
         try {
              job.print();
         } catch (PrinterException ex) {
          /* The job did not successfully complete */
         }
     }
}

public static void main(String args[]) {

    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JFrame f = new JFrame("Hello World Printer");
    f.addWindowListener(new WindowAdapter() {
       public void windowClosing(WindowEvent e) {System.exit(0);}
    });
    JButton printButton = new JButton("Print Hello World");
    printButton.addActionListener(new HelloWorldPrinter());
    f.add("Center", printButton);
    f.pack();
    f.setVisible(true);
}
} 

This doesn’t work, I get a «No print service found» alert message.

I am using Ubuntu 12.04 and the Java version is 1.7.0_25.

How can I get rid of this alert?

I started to create a simple Java application to print «Hello World» with the following code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.print.*;

public class HelloWorldPrinter implements Printable, ActionListener { 

public int print(Graphics g, PageFormat pf, int page) throws
                                                    PrinterException {

    if (page > 0) { /* We have only one page, and 'page' is zero-based */
        return NO_SUCH_PAGE;
    }

    /* User (0,0) is typically outside the imageable area, so we must
     * translate by the X and Y values in the PageFormat to avoid clipping
     */
    Graphics2D g2d = (Graphics2D)g;
    g2d.translate(pf.getImageableX(), pf.getImageableY());

    /* Now we perform our rendering */
    g.drawString("Hello world!", 100, 100);

    /* tell the caller that this page is part of the printed document */
    return PAGE_EXISTS;
}

public void actionPerformed(ActionEvent e) {
     PrinterJob job = PrinterJob.getPrinterJob();
     job.setPrintable(this);
     boolean ok = job.printDialog();
     if (ok) {
         try {
              job.print();
         } catch (PrinterException ex) {
          /* The job did not successfully complete */
         }
     }
}

public static void main(String args[]) {

    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JFrame f = new JFrame("Hello World Printer");
    f.addWindowListener(new WindowAdapter() {
       public void windowClosing(WindowEvent e) {System.exit(0);}
    });
    JButton printButton = new JButton("Print Hello World");
    printButton.addActionListener(new HelloWorldPrinter());
    f.add("Center", printButton);
    f.pack();
    f.setVisible(true);
}
} 

This doesn’t work, I get a «No print service found» alert message.

I am using Ubuntu 12.04 and the Java version is 1.7.0_25.

How can I get rid of this alert?

HI:
I am trying to print an image from a printDialog . It compiles fine but when I try to run, the print dialog box appears from where I can choose a printer. But after that, nothing is printed. I tried to log the error and this is what I found:
java.awt.print.PrinterException: No print service found

The console show me this error :

java.awt.print.PrinterException: No print service found.
at sun.print.RasterPrinterJob.print(Unknown Source)
at sun.print.RasterPrinterJob.print(Unknown Source)
at PrinterGUI.printMyJob(PrinterGUI.java:303)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.invoke.JSInvoke.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
at sun.plugin.com.DispatchImpl$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.com.DispatchImpl.invoke(Unknown Source)

I found this fix BUG ID: 5024816 and Related Bugs 4930594 but my problem continue.

Can anyone help me with this?

i’m using CUPs v2.1.3 to access 2 printers shared by another linux mint pc.

The problem: jedit v 5.3.0 pops-up an error message «No print service found.» when I try ‘File > Print’ or ‘File > Page setup’ on any text file I’m editing.

Other text editors (e.g. Geany 1.27 and xed 1.6.3) see the shared printers and print ok.

Googling I found a 12-year old Bugzilla issue
https://bugzilla.novell.com/show_bug.cgi?id=213362
which suggests the root cause lies with some Java versions not working with some CUPs versions.
To quote from that bug report:

I’ve actually had some discussions with Sun the other day; the issue
is that the default server address in CUPS 1.2 is a domain socket,
which Java does not support. They will be implementing a fix for
that (fallback to localhost IP socket), but in the meantime you can
create/update an /etc/cups/client.conf file containing:

ServerName localhost

to force your Java applications to use IP instead of domain sockets.

I tried this work-around, but no dice — the problem persists. I’m using Oracle Java v1.8.0-181, specifically:

java -version
openjdk version «1.8.0_181»
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-1ubuntu0.16.04.1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

This is a niggling problem! Has anyone seen it and found a fix (other than printing using a non-java text editor)?

Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.

Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.

Печатаю в консольном приложении через JasperReport-6 несколько тысяч заданий в день на разные сетевые принтеры. Периодически вылетает ошибка:

Ошибка:No suitable print service found.
 net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:323)

При повторной отправке задания все отлично. Отловить отладчиком не могу. Этих ошибок в день около 100, а заданий несколько тысяч. Печатаю вот так:

jasperPrint = JasperFillManager.fillReport(getClass().getResourceAsStream(fn), parameters, cn);
if (!jasperPrint.getPages().isEmpty()) {
   PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
   printRequestAttributeSet.add(new JobName("Picklist_ID" + picklistId + "", null));
    if (ps != null) {
        System.out.println("PICKLIST_ID:" + picklistId + " WID:" + workshopId + " MS:" + ms + " " + curWorkMode.toString() + " PRINTER:" + ps.getName() + " " + new Date().toString() + " Prior" + priority);
        JRPrintServiceExporter exporter = new JRPrintServiceExporter();
        exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
        SimplePrintServiceExporterConfiguration conf = new SimplePrintServiceExporterConfiguration();
        conf.setPrintRequestAttributeSet(printRequestAttributeSet);
        conf.setPrintServiceAttributeSet(ps.getAttributes());
        conf.setDisplayPageDialog(Boolean.FALSE);
        conf.setDisplayPrintDialog(Boolean.FALSE);
        exporter.setConfiguration(conf);
        exporter.exportReport();
}}

Ошибка вылетает на последней строчке:

exporter.exportReport();

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Nginx ошибки где лежат
  • Nginx как посмотреть ошибки