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

                          }

             }

                                    

  • 相关阅读:
    hdu 2527:Safe Or Unsafe(数据结构,哈夫曼树,求WPL)
    hdu 2019:数列有序!(数据结构,直接插入排序+折半插入排序)
    hdu 3791:二叉搜索树(数据结构,二叉搜索树 BST)
    hdu 3336:Count the string(数据结构,串,KMP算法)
    hdu 1022:Train Problem I(数据结构,栈,递归,dfs)
    hdu 2141:Can you find it?(数据结构,二分查找)
    hdu 1232:畅通工程(数据结构,树,并查集)
    hdu 2025:查找最大元素(水题,顺序查找)
    hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)
    hdu 1174:爆头(计算几何,三维叉积求点到线的距离)
  • 原文地址:https://www.cnblogs.com/zhouzetian/p/8567956.html
Copyright © 2011-2022 走看看