使用 fr.opensagres.xdocreport 将 odt 文档转换为 pdf:变量保持为空

Converting odt document to pdf with fr.opensagres.xdocreport: variables remain empty

opensagres.xdocreport把odt文档转PDF过去。但是这次 PDF 文档中的变量保持为空,即使 pojo 和上下文具有所有信息。我使用此代码:

private ByteArrayOutputStream makePdf(Object sheet, String file)
{
  final java.util.logging.Logger app = java.util.logging.Logger.getLogger("org.odftoolkit.odfdom.pkg.OdfXMLFactory");
  app.setLevel(java.util.logging.Level.ALL);

  try (InputStream in = DocumentPortImpl.class
        .getResourceAsStream(PATH + file);
        ByteArrayOutputStream out = new ByteArrayOutputStream())
  {
     IXDocReport report = XDocReportRegistry.getRegistry()
           .loadReport(in, TemplateEngineKind.Freemarker);
     IContext context = report.createContext();
     context.put("h", sheet);

     Options options = Options.getFrom(
           fr.opensagres.xdocreport.core.document.DocumentKind.ODT).to(ConverterTypeTo.PDF);

     report.convert(context, options, out);
     return out;
  } catch (IOException | XDocReportException e)
  {
     LOGGER.error("Error producing pdf", e);
     return null;
  }
}

这是 pojo sheet:

private class HerbarySheetComplete
{
  private String herbary = "";
  private String latinname = "";
  private String author = "";
  private String germanname = "";
  private String book = "";
  private String locality = "";
  private String coordinates = "";
  private String epsg = "";
  private String blur = "";
  private String habitat = "";
  private String person = "";
  private String date = "";
  private String uuid = "";

  public String getHerbary()
  {
     return herbary;
  }

  public void setHerbary(String herbary)
  {
     this.herbary = herbary;
  }

  public String getLatinname()
  {
     return latinname;
  }

  public void setLatinname(String latinname)
  {
     this.latinname = latinname;
  }

  public String getAuthor()
  {
     return author;
  }

  public void setAuthor(String author)
  {
     this.author = author;
  }

  public String getGermanname()
  {
     return germanname;
  }

  public void setGermanname(String germanname)
  {
     this.germanname = germanname;
  }

  public String getBook()
  {
     return book;
  }

  public void setBook(String book)
  {
     this.book = book;
  }

  public String getLocality()
  {
     return locality;
  }

  public void setLocality(String locality)
  {
     this.locality = locality;
  }

  public String getCoordinates()
  {
     return coordinates;
  }

  public void setCoordinates(String coordinates)
  {
     this.coordinates = coordinates;
  }

  public String getEpsg()
  {
     return epsg;
  }

  public void setEpsg(String epsg)
  {
     this.epsg = epsg;
  }

  public String getBlur()
  {
     return blur;
  }

  public void setBlur(String blur)
  {
     this.blur = blur;
  }

  public String getHabitat()
  {
     return habitat;
  }

  public void setHabitat(String habitat)
  {
     this.habitat = habitat;
  }

  public String getPerson()
  {
     return person;
  }

  public void setPerson(String person)
  {
     this.person = person;
  }

  public String getDate()
  {
     return date;
  }

  public void setDate(String date)
  {
     this.date = date;
  }

  public String getUuid()
  {
     return uuid;
  }

  public void setUuid(String uuid)
  {
     this.uuid = uuid;
  }
}

然后我这样引用 odt 文档中的变量:

Herbarium: ${h.herbary!}
Lat. Name: ${h.latinname!} ${h.author!}
Dt. Name:  ${h.germanname!}
Bestimmungsquelle: ${h.book!}
Fundort: ${h.locality!}
Koordinaten: ${h.coordinates!} Länge/Breite
EPSG-Code: ${h.epsg!}, ${h.blur!} Unschärfe
Habitat: ${h.habitat!}
Sammler: ${h.person!}
Funddatum: ${h.date!}
UUID: ${h.uuid!}

有人知道哪里出了问题吗?我尝试使用版本 1.0.5 和 2.0.1 作为依赖项。我得到的唯一信息是这样的:

org.odftoolkit.odfdom.pkg.OdfXMLFactory : None-为 loext:contextual-spacing

创建的 ODF 属性

我在谷歌上搜索了很多,但找不到任何有用的信息。提前致谢。

class HerbarySheetComplete 不能是私有的,ist 必须是 public!!!

问题在这里:

       fr.opensagres.xdocreport.core.document.DocumentKind.ODT).to(ConverterTypeTo.PDF);

您在这里缺少一些依赖项。