当我打印报告时,评论JasperExportManager.exportReportToPdf(JasperPrint)
报告在 Jar文件中显示正常。否则报告会卡在此功能中,报表查看器也不会出现,甚至不会出现任何错误。在Netbeans中,它运行良好。我在JDK8u25(32位)工作。这是我的报告打印代码:
public void PrepareReport(ResultSet rs) {
try{
String reportName ="/com/mmts/reports/challan.jasper";
InputStream st = getClass().getResourceAsStream(reportName);
JasperReport jr= (JasperReport) JRLoader.loadObject(st);
JasperPrint jp =
JasperFillManager.fillReport(jr,new HashMap<>(),new JRResultSetDataSource(rs));
JRViewer jv = new JRViewer(jp);
JFrame jf = new JFrame();
jf.getContentPane().add(jv);
JasperExportManager.exportReportToPdf(jp);
jf.validate();
jf.setVisible(true);
jf.setTitle("Challan");
jf.setSize(new Dimension(1200,600));
jf.setLocation(20,20);
jf.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}catch(JRException ex){
JOptionPane.showMessageDialog(null, ex);
}
}
这是我的包装控制台输出:
ant -f D:\\Metro\\MMTS\\NetBeansProjects\\MMTS -Djar.archive.disabled=true -Dnative.bundling.type=image build-native
Detected JavaFX Ant API version 1.3
init:
deps-clean:
Updating property file: D:\Metro\MMTS\NetBeansProjects\MMTS\build\built-clean.properties
Deleting directory D:\Metro\MMTS\NetBeansProjects\MMTS\build
clean:
deps-jar:
Created dir: D:\Metro\MMTS\NetBeansProjects\MMTS\build
Updating property file: D:\Metro\MMTS\NetBeansProjects\MMTS\build\built-jar.properties
Created dir: D:\Metro\MMTS\NetBeansProjects\MMTS\build\classes
Created dir: D:\Metro\MMTS\NetBeansProjects\MMTS\build\empty
Created dir: D:\Metro\MMTS\NetBeansProjects\MMTS\build\generated-sources\ap-source-output
Compiling 24 source files to D:\Metro\MMTS\NetBeansProjects\MMTS\build\classes
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Copying 5 files to D:\Metro\MMTS\NetBeansProjects\MMTS\build\classes
Copied 2 empty directories to 1 empty directory under D:\Metro\MMTS\NetBeansProjects\MMTS\build\classes
compile:
Created dir: D:\Metro\MMTS\NetBeansProjects\MMTS\dist
Copying 33 files to D:\Metro\MMTS\NetBeansProjects\MMTS\dist\lib
Launching <fx:jar> task from C:\Program Files (x86)\Java\jdk1.8.0_25\jre\..\lib\ant-javafx.jar
Launching <fx:deploy> task from C:\Program Files (x86)\Java\jdk1.8.0_25\jre\..\lib\ant-javafx.jar
Note: To create native bundles the <fx:deploy> task may require external tools. See JavaFX 2.2+ documentation for details.
Launching <fx:deploy> in native packager mode...
No base JDK. Package will use system JRE.
Creating app bundle: MMTS in D:\Metro\MMTS\NetBeansProjects\MMTS\dist\bundles
Result application bundle: D:\Metro\MMTS\NetBeansProjects\MMTS\dist\bundles
Deleting: D:\Metro\MMTS\NetBeansProjects\MMTS\dist\MMTS.html
Deleting: D:\Metro\MMTS\NetBeansProjects\MMTS\dist\MMTS.jnlp
Deleting: D:\Metro\MMTS\NetBeansProjects\MMTS\dist\MMTS_browser.jnlp
build-native:
BUILD SUCCESSFUL (total time: 17 seconds)
以pdf格式保存生成的报告对我来说是必须的。请帮助。
答案 0 :(得分:1)
好的......现在我得到了解决方案。 问题出现在itextpdf和lowagie jar的版本中。 早些时候,我的包括如下:
(1)itextpdf-2.1.7.jar
(2)com.springsource.com.lowagie.text-2.0.8.jar
现在我已将它们更改为以下内容:
(1)itextpdf-5.5.3.jar
(2)com.lowagie.text-2.1.7
由于这个原因,我可以在报告查看器中查看我的报告打印到打印机或者可以保存为pdf
现在最终代码如下:
public void PrepareReport(ResultSet rs){
try{
String reportName ="/com/mmts/reports/challan.jasper";
InputStream st = getClass().getResourceAsStream(reportName);
JasperReport jr= (JasperReport) JRLoader.loadObject(st);
Map parameters = new HashMap();
JasperPrint jp = JasperFillManager.fillReport(jr,parameters,new JRResultSetDataSource(rs));
JasperExportManager.exportReportToPdf(jp);
JasperViewer jv=new JasperViewer(jp,false);
jv.setTitle("Challan");
jv.setVisible(true);
}catch(JRException ex)
{
JOptionPane.showMessageDialog(null, ex);
}
}
感谢