[英]Character encoding for French locale while creating PDF - Java
I have a spring boot application which renders a XML document into PDF. 我有一个Spring Boot应用程序,它将XML文档转换为PDF。 The document contains French characters like é à
. 该文档包含é à
等法语字符。 While running the application through STS I have no issues the PDF is generated as expected. 通过STS运行应用程序时,我没有问题,不会生成预期的PDF。 But while running the application through command line using java -jar target\\application.jar
the generated PDF has French characters as é Ã
. 但是,在使用java -jar target\\application.jar
application.jar通过命令行运行应用java -jar target\\application.jar
,生成的PDF的法语字符为é Ã
。 I am converting the XML into byte[] and creating the PDF. 我将XML转换为byte []并创建PDF。 I couldn't figure out a way out. 我想不出办法。 Any help is much appreciated. 任何帮助深表感谢。
Two options: 两种选择:
Force the encoding with the file.encoding
argument, such as -Dfile.encoding=utf-8
. 使用file.encoding
参数强制编码,例如-Dfile.encoding=utf-8
。
java -Dfile.encoding=utf-8 -jar target\\application.jar
(better) When you convert the xml file into a byte array, specify the encoding: (更好)将xml文件转换为字节数组时,请指定编码:
Reader reader = new InputStreamReader(new FileInputStream("/path/to/xml/file"), StandardCharsets.UTF_8); // do your file reading ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.