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