我正在尝试使用*.odt将一些*.pdf文件转换为IXDocReport。
下面是*.odt文件的假设内容:${amount?string.currency} to be paid
下面是我使用的转换代码(可以在kotlin REPL中运行):
import fr.opensagres.xdocreport.converter.ConverterTypeTo
import fr.opensagres.xdocreport.converter.ConverterTypeVia
import fr.opensagres.xdocreport.converter.Options
import fr.opensagres.xdocreport.document.IXDocReport
import fr.opensagres.xdocreport.document.registry.XDocReportRegistry
import fr.opensagres.xdocreport.template.TemplateEngineKind
import java.io.ByteArrayInputStream
import java.io.File
val options: Options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.ODFDOM)
val content: ByteArray = File("/home/sandro/tmp/report.odt").readBytes()
val templateId: String = "someId"
val registry: XDocReportRegistry = XDocReportRegistry.getRegistry()
val data: MutableMap<String, Any> = mutableMapOf("amount" to 10)
ByteArrayInputStream(content).use { input ->
val report: IXDocReport =
registry.loadReport(input, templateId, TemplateEngineKind.Freemarker, true)
val tmpFile: File = createTempFile("out", ".pdf")
tmpFile.outputStream().use { output ->
report.convert(data, options, output)
println(tmpFile.toString())
}
}结果是具有字符串$10.00 to be paid的pdf文件。
如何在转换过程中将所需的区域设置为XDocReport,以便将结果正确地更改为其他货币?
P.S.我无法控制模板本身,所以请不要告诉我向模板本身添加<#setting locale="${bean.locale}">或其他东西。我唯一能改变的地方就是代码。提前谢谢。
P.S.S.--我需要为每个请求呈现许多模板,并且需要为每个模板设置区域设置。
发布于 2019-11-30 21:34:22
我从未使用过XDocReport,但这可能会奏效:https://github.com/opensagres/xdocreport/wiki/FreemarkerTemplate“如何配置共济会?”
引文:
要使用XDocReport配置共济会会员,您必须获得配置实例。你必须做的事
所以你需要一个这样的类:
public class MyFreemarkerConfiguration implements ITemplateEngineInitializerDiscovery {
[...]
public void initialize(ITemplateEngine templateEngine) {
if (TemplateEngineKind.Freemarker.name().equals( templateEngine.getKind())) {
Configuration cfg = ((FreemarkerTemplateEngine) templateEngine).getFreemarkerConfiguration();
cfg.setLocale(...);
}
}
}https://stackoverflow.com/questions/59119237
复制相似问题