Jasper ReportsでDateをフォーマットしようとしましたが、Windowsでは動作しますが、Linuxでは動作しません。 Linuxの場合、結果のテキストは切り捨てられます。LinuxでPDFでテキストが切り詰められるのはなぜですか?
コード:
JRXML:
<parameter name="timestamp" class="java.util.Date"/>
[...]
<textField>
<reportElement x="0" y="0" width="50" height="16" uuid="0007846a-26f1-457a-a198-67a2f7c8417c">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unity" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<box padding="2"/>
<textElement textAlignment="Left" verticalAlignment="Top">
<font size="8" pdfFontName="Helvetica" pdfEncoding="Cp1250" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[DATEFORMAT($P{timestamp},"dd.MM HH:mm")]]></textFieldExpression>
</textField>
Mavenの依存関係:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-functions</artifactId>
<version>5.6.0</version>
</dependency>
のJava:
private byte[] createPdf() {
try {
InputStream is = getClass().getResourceAsStream("MyReport.jasper");
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(is);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("timestamp", new Date());
JRDataSource jrDataSource = new JRBeanCollectionDataSource(new Vector(), false);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, jrDataSource);
byte[] pdf = JasperExportManager.exportReportToPdf(jasperPrint);
return pdf;
} catch (JRException e) {
throw new RuntimeException("Could not create PDF.", e);
}
}
の
結果:Windowsとの
結果:Linuxで
結果:
PDFのプロパティ:
どちらも生成されたPDFファイルは、Windows用のAcrobat Readerで同じフォントプロパティを持っている:あなたが見ることができるように
は、フォントが埋め込まれていません。依存関係jasperreports-fonts
を追加し、属性pdfFontName
,pdfEncoding
およびisPdfEmbedded
を削除すると、2番目のフォント "Helvetica"が消えます。
研究:私が読ん
:
- PDF generated with jasperreport not showing well on Linux but yes on Mac, could the os be related?
- http://community.jaspersoft.com/questions/527138/pdf-text-truncated-linux-fine-windows
- http://community.jaspersoft.com/questions/803503/why-text-filed-value-will-be-truncated-if-application-running-linux
およびソリューションは、フォントを埋め込むことのようですが、それはしていません作業。
私は、デフォルトのフォントの一つであり、それが理由です、 Wikipedia参照フォント「ヘルベチカ」を使用:同じメトリックで
これらのフォント、または適切な代替フォントは、常にすべてのPDFで使用可能でなければなりません読者ので、PDF
とhttps://stackoverflow.com/a/27345103/5277820に埋め込まれていない必要があります:あなたはiTextの、iTextのワットでこれらのフォントを使用する場合は
Adobe Readerや他の閲覧者がこれらのフォントを正しくレンダリングできると想定するのは安全ですから、埋め込みパラメータは無視してください。
質問:
なぜWindowsとLinuxと同じフォント異なる幅を持っていますか?あるいは、テキストの切り詰めや折り返しが異なるのはなぜですか?
問題を避けるため、フォントを埋め込むことになっています。ポストhttp://stackoverflow.com/a/26632606/5292302で4つのミスを参照してください(答えはitextの創設者からです)、最良の例ではありませんが、コーディング練習の考え方、常に、提供され、埋め込まれたフォント –