No print service found error message
Asked Answered
M

3

8

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?

Macklin answered 22/7, 2013 at 17:9 Comment(0)
H
9

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

sudo apt-get install cups-pdf
Henrie answered 4/5, 2014 at 5:41 Comment(0)
E
0

This is how I got printing to PDFs working on Arch Linux:

  1. sudo pacman -S cups-pdf
  2. sudo systemctl enable org.cups.cupsd.service
  3. sudo systemctl start org.cups.cupsd.service
  4. Add printer "Generic CUPS-PDF" with sudo system-config-printer, see screenshot below
  5. Created PDFs are in /var/spool/cups-pdf/$USER
  6. To change the output directory, edit the Out configuration key in /etc/cups/cups-pdf.conf

Screenshot of system-config-printer

Earpiercing answered 18/7, 2018 at 12:15 Comment(0)
O
0

For MacOS i have used PDFWriter :

  1. You can get the installer from here

2. After installing the package, go back and click on it -> Show Package Contents. 3. From there uncompress Archive.pax.gz and copy PDFwriter.ppd file into /Library/Printers/PPDs/Contents/Resources. You may need to create the last 3 folders. Also, if you don't find the Library folder, it is hidden by default, so just press shift+command+"." 4. Now go to the Printers dialog in Settings and add the printer.

Ontology answered 27/9, 2021 at 14:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.