0
如何在java中打印multipage
.tiff
文件?
用java打印multipage tiff
我已經使用 DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
但它不工作。
是否有任何其他方式或文檔打印此可分頁文件???
這就是我們正在做的示例代碼,
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);
}
}
由於質量目的,我不想將.tiff文件轉換爲.pdf文件。 – Jaykishan
您可能需要實現'Printable'並直接渲染圖像,請查看[Printing](http://docs.oracle.com/javase/tutorial/2d/printing/)瞭解更多詳情。只要知道你負責重新縮放。此外,您將需要使用'ImageIO'來加載文件,但也需要[JAI ImageIO插件](https://java.net/projects/jai-imageio)才能使其工作 – MadProgrammer
我們正在使用的Ya夥伴同樣的東西(可打印,JAI),但它不打印'.tiff'文件。 – Jaykishan