0

如何multipage .tiff在java中打印文件?

我用过 DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;,但它不起作用。
有没有其他方法或 docflavor 来打印这个可分页文件???
这就是我们正在做的示例代码,

public class Printing { 

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

 IIORegistry registry = IIORegistry.getDefaultInstance();    
 registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriterSpi());    
 registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.tiff.TIFFImageReaderSpi());     


   String filename = "C:/Users/trainees/Desktop/abcd.TIFF";  
   PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();  
   DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;  

   PrintService printService[] =   
   PrintServiceLookup.lookupPrintServices(flavor, pras);  
   PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();  
   PrintService service = defaultService;  

   if (service != null) {  
      DocPrintJob job = service.createPrintJob();  
      FileInputStream fis = new FileInputStream(filename);  
      DocAttributeSet das = new HashDocAttributeSet();  
      Doc doc = new SimpleDoc(fis, flavor, das);  
      job.print(doc, pras);  
      Thread.sleep(10000);  
   }  
   System.exit(0);  
}  

}

4

1 回答 1

0

您可以创建一个java.awt.print.Book并将每个页面附加到Bookusingbook.append(this,pageformat,pages);方法。然后打印将打印所有 tiff 页面。

于 2013-06-20T09:48:36.490 回答