zoukankan      html  css  js  c++  java
  • java打印技术---javax.print

    import java.io.*;

    import javax.print.*;

    import javax.print.attribute.*;

    import javax.print.attribute.standard.*;

    public class PrintImage{

              public  PrintImage(String filename){

                           try{

                               //获得打印属性

                               PrintRequestAttributeSet  prass=new HashPrintRequestAtteributeSet();

                               prass.add(new Copies(1));

                              //获得打印设备

                               PrintService pss[]=PrintServerLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF,prass);

                               if(pss.length==0)

                                    throw new RuntimeException("No printer services available.");

                                PrintService ps=pss[0];

                                System.out.println("Printing to"+ps);

                                //获得打印工作

                               DocPrintJob job=ps.createPrintJob();

                               FileInputStream fin=new FileInputSTream(filename);

                              Doc doc=new SimpleDoc(fin,DocFlavor.INPUT_STREAM.GIF,null);

                              //开始打印

                             job.print(doc,prass);

                             fin.close();

                             }catch(IOException ie){

                              ie.printStackTrace();

                               }catch(PrintException pe){

                            pe.printStackTrace();

                               }

                          }

                 public static void main(String args[]) throws Exception{

                          if(args.length<1){

                                System.err.println("Usage:java PrintImage<image name>");

                               System.exit(1);

                                 }

                              new PrintImage(args[0]);

                          }

             }

                                    

  • 相关阅读:
    Java开发常用知识点总结
    Net实现阿里云开放云存储服务(OSS)
    KEIL MDK-ARM Version 5.26正式版开发工具下载
    【NXP开发板应用—智能插排】4. PWM驱动
    【NXP开发板应用—智能插排】3.驱动GPIO点亮外接LED
    【NXP开发板应用—智能插排】2.初步解析example之GPI
    【NXP开发板应用—智能插排】1.如何使用scp传输文件
    Keil MDK最新版 5.25介绍及下载地址
    springmvc框架helloword
    单例设计模式
  • 原文地址:https://www.cnblogs.com/zhouzetian/p/8567956.html
Copyright © 2011-2022 走看看