我用java编写了下面的代码来打印一个简单的pdf文件,
public class Test {
public static void main(String[] args) throws PrinterException, IOException {
PrinterJob pj= PrinterJob.getPrinterJob();
List<PrintService> plist= new ArrayList<PrintService>();
for (PrintService ps: pj.lookupPrintServices()) {
plist.add(printService);
}
for (PrintService ps: plist) {
if (printService.getName().contains("MyPrinterName")) {
pj.setJobName("test");
pj.setPrintService(printService);
print(pj, "C:\\Users\\been\\Desktop\\hi.pdf", MediaTray.TOP);
}
}
}
private static void print(final PrinterJob pj, final String path, final MediaTray tray) throws IOException, PrinterException {
PrintRequestAttributeSet pas= new HashPrintRequestAttributeSet();
pas.add(tray);
PDDocument document = PDDocument.load(path);
pj.setPageable(document);
pas.add(new PageRanges(1, 2));
pj.print(printRequestAttributeSet);
}
}
我正在使用 pdfbox 1.8.0 jar 来读取 pdf 文件。我使用 JDK1.6.0_43 的 eclips 作为开发平台。我可以在windows 操作系统中打印,但是当我在solaris os中运行相同的代码时,我没有打印出来。我的印刷品得到了零页的工作。你能帮忙吗?非常感谢。