怎样能使打印的时候按照默认的设置进行打印,而不出现打印设置的对话框? 打印的时候使用PrintJob printjob = getToolkit().getPrintJob(this, "Print Test", null);这样会弹出一个对话框设置打印的一些选项,现在我不想让这个对话框出现,而是按照默认的设置进行打印,有没有办法啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用Toolkit.getPrintJob(Frame f, String jobtitle, Properties prop)设置prop也不行啊 如果没记错的话,print API中有一个默认的不用弹出对话框的方法,直接就可以打印看下它的API 吧,1.4以上的 给你个例子:package print;import javax.print.*; import javax.print.attribute.*; import java.io.*; public class Printing { public static void main(String args[]) throws Exception { String filename = "C:\\work\\sina_kjsd.gif"; PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = null; //flavor = DocFlavor.INPUT_STREAM.PNG; // DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8; flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;//lookupDefaultPrintService lookupPrintServices// PrintService printService[] = // PrintServiceLookup.lookupPrintServices(flavor, pras); //锟斤拷锟揭伙拷锟斤拷锟侥拷系拇锟接★拷锟� PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); System.out.println("获取默认打印服务�"+defaultService);// PrintService service = ServiceUI.printDialog(null, 200, 200, // printService, defaultService, flavor, pras); PrintService service = defaultService; DocFlavor printerFlavor[] = service.getSupportedDocFlavors(); for(int i = 0;i<printerFlavor.length;i++){ System.out.println("SupportedDocFlavors"+printerFlavor[i]); } System.out.println("当前打印机是否支持该格式"+defaultService.isDocFlavorSupported(flavor)); if (service != null &&defaultService.isDocFlavorSupported(flavor)) { DocPrintJob job = service.createPrintJob(); System.out.println("创建打印任务 = "+job); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); //锟斤拷锟斤拷要锟斤拷印锟斤拷锟侥碉拷// Doc doc = new SimpleDoc(fis, flavor, das); ByteArrayInputStream os = null; String str = "这是个测试 � "; char [] b = null;;b = str.toCharArray(); // os = new CharArrayInputStream(b);//str.getBytes("gb2312");os = new ByteArrayInputStream(str.getBytes("gb2312")); Doc doc = new SimpleDoc(os, flavor, null); //Doc doc = new SimpleDoc(fis, flavor, null); System.out.println("锟斤拷锟斤拷要锟斤拷印锟斤拷锟侥碉拷 ="+doc); job.print(doc, pras); // Thread.sleep(10000); } System.out.println("print test----------0007 "); System.exit(0); } } 过来人帮我推荐下学JDBC和数据库应该买些什么书 dom.jar包那里有下的啊! 这个for循环怎么这样用 JAVA操作ZIP文件...急急急急急急急急急急急急 Java中类对象的共享问题 applet 中怎么得到主机的ip地址 网上抄的JMF Player的例子,不能播放,请教? 这个程序的higher错在哪里? 有关JDK1.3.1的配置问题: 各位大侠,小侠,快过来看看。 对比的问题,请大家指点。 对Null和""的疑惑?
看下它的API 吧,1.4以上的
package print;import javax.print.*;
import javax.print.attribute.*;
import java.io.*; public class Printing {
public static void main(String args[]) throws Exception {
String filename = "C:\\work\\sina_kjsd.gif";
PrintRequestAttributeSet pras =
new HashPrintRequestAttributeSet();
DocFlavor flavor = null;
//flavor = DocFlavor.INPUT_STREAM.PNG;
// DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8;
flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;//lookupDefaultPrintService lookupPrintServices
// PrintService printService[] =
// PrintServiceLookup.lookupPrintServices(flavor, pras);
//锟斤拷锟揭伙拷锟斤拷锟侥拷系拇锟接★拷锟�
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
System.out.println("获取默认打印服务�"+defaultService);// PrintService service = ServiceUI.printDialog(null, 200, 200,
// printService, defaultService, flavor, pras);
PrintService service = defaultService;
DocFlavor printerFlavor[] = service.getSupportedDocFlavors();
for(int i = 0;i<printerFlavor.length;i++){
System.out.println("SupportedDocFlavors"+printerFlavor[i]);
}
System.out.println("当前打印机是否支持该格式"+defaultService.isDocFlavorSupported(flavor));
if (service != null &&defaultService.isDocFlavorSupported(flavor)) {
DocPrintJob job = service.createPrintJob();
System.out.println("创建打印任务 = "+job);
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
//锟斤拷锟斤拷要锟斤拷印锟斤拷锟侥碉拷
// Doc doc = new SimpleDoc(fis, flavor, das);
ByteArrayInputStream os = null;
String str = "这是个测试 � ";
char [] b = null;
;b = str.toCharArray();
// os = new CharArrayInputStream(b);
//str.getBytes("gb2312");
os = new ByteArrayInputStream(str.getBytes("gb2312"));
Doc doc = new SimpleDoc(os, flavor, null);
//Doc doc = new SimpleDoc(fis, flavor, null);
System.out.println("锟斤拷锟斤拷要锟斤拷印锟斤拷锟侥碉拷 ="+doc); job.print(doc, pras);
// Thread.sleep(10000);
}
System.out.println("print test----------0007 ");
System.exit(0);
}
}