以下代码在 Windows 上运行时工作正常,但如果这是在服务器中部署并通过 Windows 系统访问,则会引发运行时异常“没有可用的打印机服务。 ”。这段代码有什么问题吗,或者你能提出任何替代方案吗
package com.rajsoft.CAF.APController;
import java.io.FileInputStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
public class SamplePrint {
static public void main(String args[]) throws Exception {
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
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();
//FileInputStream fin = new FileInputStream("C:/SignImage.GIF");
FileInputStream fin = new FileInputStream("C:/SignImages/Hyderabad.GIF");
Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
job.print(doc, pras);
fin.close();
}
}