Printing a .TIF file

徘徊边缘 提交于 2019-12-08 12:22:53

问题


I am able to print a .GIF, .JPG or .PNG successfully using the following code snippet but it doesn't work for .TIF file. Also I can't get the color even after adding the chromaticity.color attribute.

public class PrintImage {
    static public void main(String args[]) throws Exception {
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    pras.add(new Copies(1));
    pras.add(chromaticity.color);
    PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF,     pras);

    if (pss.length == 0)
        throw new RuntimeException("No printer services available.");

    PrintService ps = pss[0];
    System.out.println("Printing to " + ps);
    DocPrintJob job = ps.createPrintJob();
    String fileName = "C:/labels/2.tif"
    FileInputStream fin = new FileInputStream(fileName);
    Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
    job.print(doc, pras);
    fin.close();
}

How do I support .TIF for printing?


回答1:


Use Java Advanced Imaging API for TIFF. JAI can handle multipage TIFF files, JPEG in TIFF and a few compression schemes. If you still have trouble printing, with the API you could convert your TIFF file to PNG.



来源:https://stackoverflow.com/questions/7843338/printing-a-tif-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!