-1
我有一个包含中文字符和其他亚洲语言的docx文件。我可以在我的笔记本电脑上完美地将docx文件转换为PDF文件,中文字符正确地嵌入到PDF中,但是当相同的代码作为Linux服务器上的可运行jar运行时,中文字符会被替换为#符号。 有人可以指导我解决这个问题吗? 感谢您提前给予帮助。 下面替换字符为Doc的Docx
public static void main(String[] args) throws Exception {
try {
Docx4jProperties.getProperties().setProperty("docx4j.Log4j.Configurator.disabled", "true");
Log4jConfigurator.configure();
org.docx4j.convert.out.pdf.viaXSLFO.Conversion.log.setLevel(Level.OFF);
System.out.println("Getting input Docx File");
InputStream is = new FileInputStream(new File(
"C:/Users/nithins/Documents/plugin docx to pdf/other documents/Contains Complex Fonts Verified.docx"));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
wordMLPackage.setFontMapper(new IdentityPlusMapper());
System.out.println("Setting File Encoding");
System.setProperty("file.encoding", "Identity-H");
System.out.println("Generating PDF file");
org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
wordMLPackage);
File outFile = new File(
"C:/Users/nithins/Documents/plugin docx to pdf/other documents/Contains Complex Fonts Verified.pdf");
OutputStream os = new FileOutputStream(outFile);
c.output(os, new PdfSettings());
os.close();
System.out.println("Output pdf file generated");
} catch (Exception e) {
e.printStackTrace();
}
}
public static String changeExtensionToPdf(String path) {
int markerIndex = path.lastIndexOf(".docx");
String pdfFile = path.substring(0, markerIndex) + ".pdf";
return pdfFile;
}
您对该docx使用java解决方案进行pdf转换。这就是你告诉我们的。所以我们只能说在这个解决方案中你似乎做错了什么。 – mkl
对不起,我刚刚用我的java代码编辑了这个问题 –
好的,所以你使用[tag:docx4j]。我添加了该标签。不幸的是我根本不知道那个产品。只有一句话:'System.setProperty(“file.encoding”,“Identity-H”)应该没有任何意义,** Identity-H **是PDF内部的东西;系统属性“file.encoding”通常指的是文本文件,因此,* not *为PDF,其毕竟是二进制文件,而不是文本文件。此外,即使您仍然遇到麻烦,您仍然可以将日志级别设置为关闭状态,这是奇怪的,毕竟可能会有日志输出可以帮助您。 – mkl