java在XWPF文档中使用阿拉伯语和波斯语
我想用阿拉伯字母将word转换为pdf, 经过一段时间的研发,;我决定使用
org.apache.poi.xwpf.converter.pdf.PdfConverter
但当我写下面的代码时,最终的结果是从左到右,单词杂乱无章,例如pdf中的“سعید”结果是“سعید”。我的docx非常大,没有一段:
public class ConvertWord {
public static void ConvertToPDF(String docPath, String pdfPath) {
try {
InputStream doc = new FileInputStream(new File(docPath));
XWPFDocument document = new
PdfOptions options = PdfOptions.create();
options.fontEncoding("UTF-8")
OutputStream out = new FileOutputStream(new File(pdfPath));
PdfConverter.getInstance().convert(document,out,options);
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
}
public static void main(String[] args) {
ConvertWord cwoWord=new ConvertWord();
cwoWord.ConvertToPDF("D://" + "usc.docx","D://test12.pdf");
}
}
# 1 楼答案
有一个解决方法可以解决这个问题。 你需要使用ICU4J库。 然后:
尽管你可能对波斯独角兽有一些问题。出现了一个问题,有人通过修补
ArabicShaping
解决了这个问题。我没有找到它的链接但是 here是修补代码。 (我必须把文件上传到我的谷歌硬盘上,这样它就不会被删除了)另外,here是指向代码及其与主代码的差异的链接
为了方便起见,我把类名改为
PersianShaping
# 2 楼答案
此线程:Creating PDF document from Word document using java api,包含您可以使用的其他库。我认为你正在使用的这个库不会支持布局选项;它还包含许多bug,不支持这里提到的表、图和页码:https://github.com/opensagres/xdocreport/wiki/XWPFConverterPDFViaIText