[英]XDocReport Java API: problem converting ODT to PDF
當 ODT 中存在表格時,嘗試將簡單 ODT 轉換為 PDF 時出現問題。 表格不會出現,並且字符在文檔中亂七八糟地出現。
XDocReport: https : //github.com/opensagres/xdocreport
編碼:
/**
* https://github.com/opensagres/xdocreport/wiki
*/
public OdtBuilder gravaPdf(File fileDest) throws Exception {
File file = new File(fileName);
if (!file.exists()) {
throw new RuntimeException("Documento precisa ser gravado antes de exportar para PDF");
}
// 1) Create options ODT to PDF
Options options = Options.getFrom(DocumentKind.ODT).to(ConverterTypeTo.PDF);
// 2) Get the converter from the registry
IConverter converter = ConverterRegistry.getRegistry().getConverter(options);
InputStream in = new FileInputStream(file);
OutputStream out = new FileOutputStream(fileDest);
// 3) Convert ODT to PDF
converter.convert(in, out, options);
in.close();
out.close();
return this;
}
pom.xml:
<!-- https://mvnrepository.com/artifact/fr.opensagres.xdocreport/xdocreport -->
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>xdocreport</artifactId>
<version>2.0.2</version>
</dependency>
ODT:
生成的PDF:
我的文檔中的樣式有問題。 解決了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.