用java打印多页tiff

时间:2013-06-20 09:40:35

标签: java swing file printing tiff

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

我用过 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);  
}  

}

1 个答案:

答案 0 :(得分:0)

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