我可以使用以下代码片段成功打印.GIF、.JPG或.PNG,但它不适用于.TIF文件。另外,即使添加了chromaticity.color属性,我也无法获得颜色。
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();
}如何支持.TIF打印?
发布于 2011-10-21 07:33:56
对TIFF使用Java Advanced Imaging API。JAI可以处理多页TIFF文件,TIFF中的JPEG和一些压缩方案。如果打印仍然有问题,可以使用API将TIFF文件转换为PNG。
https://stackoverflow.com/questions/7843338
复制相似问题