开发者

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.

M using This Code ,It works bt I can't provide the print Specifications?

import java.awt.Desktop;
import java.io.File;
开发者_JS百科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.

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:

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.

MediaSize.ISO.A4 or MediaSize.ISO_A4 doesn't work. Instead MediaSizeName.ISO_A4 is correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜