私はspring-mvcプロジェクトに取り組んでいます。私はJasperReportsを使用してレポートしています。 pdf形式のレポートを生成するリンクがあります。リンクは正常に動作しており、レポートが生成されますが、問題はpdfレポートには画像が表示されません。私jrxmlファイルからの抜粋:
JasperReportがpdfに変換したときに画像を表示しない
<frame>
<reportElement x="0" y="0" width="70" height="67" uuid="0af2e978-7c0c-4805-afb4-4069d1297a12"/>
<image onErrorType="Blank" evaluationTime="Report">
<reportElement mode="Opaque" x="0" y="0" width="70" height="67" uuid="c572c836-8d67-480a-b1b1-d603940e6c74"/>
<imageExpression><![CDATA["images/geLogo.jpg"]]></imageExpression>
</image>
</frame>
は、私は再びチェックした画像は、私のプロジェクトで私のwebapp/imagesフォルダに存在しています。私は自分のJSPページでこの同じイメージを使用しています。
コードはJasperReportからPDFを生成するために使用:同じパスでJasperReportデザイナーで画像を表示するものの画像は、PDFに来ていない理由
try {
JasperPrint print = service.loadReceipt(RECEIPT_NAME, paymentId);
pdfFile = JasperExportManager.exportReportToPdf(print);
OutputStream outStream = res.getOutputStream();
res.setContentType("application/pdf");
res.addHeader("Content-disposition", "inline; filename=Receipt.pdf");
outStream.write(pdfFile);
outStream.flush();
outStream.close();
}
あなたは私を伝えることができます。私は、EclipseにJasperReportsプラグインを使用してレポートを設計しました。私はjboss 6.4でwarファイルを使ってプロジェクトを展開します。
ありがとうございます。
--------
私は@ KDavid-Valerioの答えから戦争の中でプロジェクトの構造をチェックするというアイデアを得ました。実際のプロジェクト構造とは異なります。まだ動作していないよう
Project
images
image1.jpg
image2.jpg
WEB-INF
classes
reports
report1.jrxml
report2.jrxml
:戦争の構造は次のようになります。
------- UPDATE --------
ジャスパーレポートを埋めコード:
public JasperPrint loadReceipt(String reportName, String paymentId, String imagePath) {
HashMap<String, Object> params = new HashMap<String, Object>();
JasperReport report = null;
JasperPrint print = null;
try {
if (jrReportMap == null) {
jrReportMap = new HashMap<String, JasperReport>();
}
if (jrReportMap.get(reportName) == null) {
report = JasperCompileManager.compileReport(reportManager.load(reportName));
jrReportMap.put(reportName, report);
log.info(Logger.EVENT_SUCCESS, "--- Report Compilation done --- " + reportName);
} else {
report = jrReportMap.get(reportName);
log.info(Logger.EVENT_SUCCESS, "--- Report already Compiled --- " + reportName);
}
params.put("paymentId", paymentId);
params.put("realPath", imagePath);
try {
Connection conn = reportDataSource.getConnection();
print = JasperFillManager.fillReport(report, params, conn);
conn.close();
} catch (SQLException e) {
System.err.println("--- SQL ERR - to get connection -----");
log.error(Logger.EVENT_FAILURE, "--- Report already Compiled --- " + reportName);
e.printStackTrace();
}
} catch (JRException e1) {
log.error(Logger.EVENT_FAILURE, "Oops... Something wrong while rendering the report !!!");
e1.printStackTrace();
}
return print;
}
、実行時にJasperReportで使用されるパス、それは違います設計者が使用したものからあなたのJavaコードでは、WAR内の.jasperファイルに相対的な画像のパスを置く必要があります。 –
私は多くの異なった道を試みました。何も動作していないようです。私はC:/ somethingのような外部パスを試したことさえあります。それは動作しません。 – Waquar
私は自分のプロジェクトでどのようにしたのかを説明する答えを書くつもりです。これがあなたを助けてくれることを願っています。 –