简体   繁体   English

具有规范的Java Print程序?

[英]Java Print program with Specifications?

I want a java program for windows in which I can also send the print specification like Layout Orientation,Number of copies,Pages from and to,etc along with the file path to be printed. 我想要一个用于Windows的Java程序,在该程序中,我还可以发送打印规范,例如版面方向,份数,往返页面等,以及要打印的文件路径。

M using This Code ,It works bt I can't provide the print Specifications? M使用此代码,可以工作bt我无法提供打印规格?

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

public class PrintFile {    

  public static void fileToPrint(File fis) {
    try {
      Desktop desktop = null;
      if (Desktop.isDesktopSupported())
      {               
        desktop = Desktop.getDesktop();          
      }   
       desktop.print(fis);    
       System.out.print("Printing Document");
    }
    catch (IOException ioe)
    {
      ioe.printStackTrace();
    }
  }
}

Check out Java Print Service API The javax.print.attribute and javax.print.attribute.standard packages define print attributes which describe the capabilities of a print service, specify the requirements of a print job, and track the progress of the print job. 检出Java Print Service API javax.print.attributejavax.print.attribute.standard软件包定义了打印属性,这些属性描述了打印服务的功能,指定了打印作业的要求并跟踪了打印作业的进度。

For example, if you would like to use A4 paper format and print three copies of your document you will have to create a set of the following attributes implementing the PrintRequestAttributeSet interface: 例如,如果您想使用A4纸张格式并打印文档的三个副本,则必须创建一组以下属性来实现PrintRequestAttributeSet接口:

PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();
attr_set.add(MediaSizeName.ISO_A4); 
attr_set.add(new Copies(3)); 

Then you must pass the attribute set to the print job's print method, along with the DocFlavor. 然后,您必须将属性集和DocFlavor一起传递给打印作业的打印方法。

MediaSize.ISO.A4 or MediaSize.ISO_A4 doesn't work. MediaSize.ISO.A4MediaSize.ISO_A4不起作用。 Instead MediaSizeName.ISO_A4 is correct. 而是MediaSizeName.ISO_A4是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM