java打印带格式文件_如何从java程序打印文件的任何风格(文本,文字,PDF格式,图像等)?...

我需要一个

Java程序将任何文件打印到默认/选定的打印机(实际上我使用RICOH通用PostScript打印机将任何文件打印到PostScript文件).此外,我将从打印机读取该流并将其写入PostScript文件.我已经尝试过谷歌下面的示例程序了,但是当我收到PostScript文件时,它是以某种未知的格式.

public class PrintToFileWithJava {

private static boolean jobRunning = true;

public static void main(String[] args) throws Exception {

InputStream is = new BufferedInputStream(new FileInputStream("Authentication in Hive.pdf"));

DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;

PrintService service = PrintServiceLookup.lookupDefaultPrintService();

DocPrintJob printJob = service.createPrintJob();

printJob.addPrintJobListener(new JobCompleteMonitor());

Doc doc = new SimpleDoc(is, flavor, null);

PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

printJob.print(doc, attributes);

while (jobRunning) {

Thread.sleep(1000);

}

System.out.println("Exiting app");

is.close();

}

private static class JobCompleteMonitor extends PrintJobAdapter {

@Override

public void printJobCompleted(PrintJobEvent jobEvent) {

System.out.println("Job completed");

jobRunning = false;

}

}

}

任何建议表示赞赏.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值