*.odt
一部のファイルをIXDocReport*.pdf
を使用するように変換しようとしています。
*.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())
}
}
結果は文字列を含むpdfファイルです$10.00 to be paid
結果を他の通貨に正しく変更できるように、変換中に XDocReport に必要なロケールを設定するにはどうすればよいですか?
PSテンプレート自体を制御することはできません<#setting locale="${bean.locale}">
。そのため、テンプレート自体に何かを追加するように言わないでください。私が変更できる唯一の場所はコードです。前もって感謝します。
PPSリクエストごとに多くのテンプレートをレンダリングする必要があり、各テンプレートごとにロケールを設定する必要があります。