我已经在按下按钮时创建了 itext 报告,并进行了编码以自动打印创建的报告。
其中的一些代码;
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
AttributeSet attributeSet = new HashAttributeSet();
attributeSet.add(new PrinterName("NPI8DA48A", null));
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job= service.createPrintJob();
Doc pdfp = new SimpleDoc(salepdf, flavor, null);
PrintJobWatcher watcher = new PrintJobWatcher(job);
job.print(pdfp, null);
watcher.waitForDone();
但这显示了异常
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: data is not of declared type
at javax.print.SimpleDoc.<init>(SimpleDoc.java:103)
at com.bit.project.Newsale.saveprint_btnActionPerformed(Newsale.java:1128)
at com.bit.project.Newsale.access$1300(Newsale.java:57)
at com.bit.project.Newsale$16.actionPerformed(Newsale.java:683)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
第1128行是DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
。
最佳答案
线程“AWT-EventQueue-0”java.lang.IllegalArgumentException中的异常:数据不是声明的类型
似乎表明数据和DocFlavor
之间存在不匹配。
由于您使用的是 DocFlavor.INPUT_STREAM.AUTOSENSE
,我猜测它要么无法读取您的 salepdf
,要么它不是 InputStream
。
当我测试您的代码时,我必须确保数据是从 PDF 文件读取的 InputStream
。
关于java - 自动打印Java中创建的itext报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32389851/