Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No print service found error message

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?

like image 451
k.elgohary Avatar asked Jul 22 '13 17:07

k.elgohary


People also ask

How do you fix word Cannot print there is no printer installed?

When you attempt to print a Microsoft Word document or send the document as a fax, you may receive the following error message: No printers are installed. To install a printer, point to Settings on the Windows Start menu, click Printers, and then double-click Add Printer. Follow the instructions in the wizard.

Why does it say my printer is not installed?

If you're receiving an error message about a printer not being installed, or it isn't appearing as an option in Windows and your applications, then the root cause can lie with the device itself, the connection to your computer, or something on your system.


1 Answers

Install cups-pdf, it will install a virtual printer which creates PDF files:

sudo apt-get install cups-pdf
like image 129
anand Avatar answered Sep 19 '22 07:09

anand