【问题标题】:No print service found error message未找到打印服务错误消息
【发布时间】:2013-07-21 12:46:08
【问题描述】:

我开始使用以下代码创建一个简单的 Java 应用程序来打印“Hello World”:

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);
}
} 

这不起作用,我收到“未找到打印服务”警告消息。

我使用的是 Ubuntu 12.04,Java 版本是 1.7.0_25。

我怎样才能摆脱这个警报?

【问题讨论】:

    标签: java printing ubuntu-12.04


    【解决方案1】:

    安装cups-pdf,它将安装一个创建PDF文件的虚拟打印机:

    sudo apt-get install cups-pdf
    

    【讨论】:

      【解决方案2】:

      这就是我在 Arch Linux 上打印 PDF 的方式:

      1. sudo pacman -S cups-pdf
      2. sudo systemctl enable org.cups.cupsd.service
      3. sudo systemctl start org.cups.cupsd.service
      4. 使用sudo system-config-printer 添加打印机“Generic CUPS-PDF”,请参见下面的屏幕截图
      5. 创建的 PDF 位于 /var/spool/cups-pdf/$USER
      6. 要更改输出目录,请编辑/etc/cups/cups-pdf.conf 中的Out 配置键

      【讨论】:

        【解决方案3】:

        对于 MacOS,我使用了 PDFWriter:

        1. 您可以从here 获取安装程序

        2。安装包后,返回并单击它 -> 显示包内容。 3. 从那里解压缩 Archive.pax.gz 并将 PDFwriter.ppd 文件复制到 /Library/Printers/PPDs/Contents/Resources。您可能需要创建最后 3 个文件夹。另外,如果你没有找到 Library 文件夹,它默认是隐藏的,所以只需按 shift+command+"。" 4. 现在转到设置中的打印机对话框并添加打印机。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-01-16
          • 1970-01-01
          • 1970-01-01
          • 2020-08-25
          相关资源
          最近更新 更多