-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