首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PDF Java API:将XDocReport转换为PDF时出现的问题

PDF Java API:将XDocReport转换为PDF时出现的问题
EN

Stack Overflow用户
提问于 2020-03-05 05:46:11
回答 1查看 489关注 0票数 0

当ODT中存在表时,尝试将简单ODT转换为PDF时出现问题。该表不会出现,并且字符在整个文档中显示为乱码。

XDocReport:https://github.com/opensagres/xdocreport

代码:

代码语言:javascript
复制
  /**
   * 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:

代码语言:javascript
复制
<!-- 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:

EN

回答 1

Stack Overflow用户

发布于 2020-03-05 23:41:09

这是我的文档中的样式问题。解决了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60535183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档