在Java中如何更改或设置默认打印机 [英] In Java how do I change or set a default printer

查看:1348
本文介绍了在Java中如何更改或设置默认打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何获取可用打印机列表,我希望用户能够从列表中进行选择并将其设置为会话的默认值

I know how to get the list of available printers, I want users to be able to select from a list and set that to the default for the session

使用Windows 7

Using Windows 7

我知道这很容易完成我只想创建一个简单的java程序
a:增加我的知识
b:这里的老师是非常不利于打印属性

I know that this is easily done I just want to create a simple java program a: To increase my knowledge b: Teachers here are very adverse to playing with printing properties

感谢您提前的帮助

推荐答案

此程序适用于Eclipse。

This program works in Eclipse.

import java.awt.print.PageFormat;

import java.awt.print.PrinterJob;

public class PrinterSetup 
{

    public static void main(String[] args) throws Exception
    {
        PrinterJob pjob = PrinterJob.getPrinterJob();
        PageFormat pf = pjob.defaultPage();
        pjob.setPrintable(null, pf);

        if (pjob.printDialog()) {
          pjob.print();
        }
    }
}

这篇关于在Java中如何更改或设置默认打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆