java Word模板到PDF转换与多种语言使用Docx4J

wljmcqd8  于 2023-02-28  发布在  Java
关注(0)|答案(2)|浏览(164)

你好,我正在使用Docx4j来转换文字模板到PDF格式。但泰米尔字体是不支持的。它看起来很奇怪。我用下面的Java代码,似乎减少了奇怪的外观,仍然字显示不正确。我已经安装了Latha作为泰米尔字体。请帮助

FontTablePart fontTablePart= wordMLPackage.getMainDocumentPart().getFontTablePart();
        fontTablePart.processEmbeddings();
        Set<String> fontsInUse = wordMLPackage.getMainDocumentPart().fontsInUse();
        // Make each embedded font available to the font mapper.
        for(String s : fontsInUse) {
            System.out.println("Font in use : "+s);
            PhysicalFont physicalFont = PhysicalFonts.get(s);
            fontMapper.put(s, physicalFont);
        }
mm5n2pyu

mm5n2pyu1#

假设您使用docx 4j-export-fo进行转换,请确保已安装字体并使用IdentityPlusMapper,或者使用BestMatchingMapperMap合适的字体。
更多信息请参见https://github.com/plutext/docx4j/blob/VERSION_11_4_8/docx4j-samples-docx-export-fo/src/main/java/org/docx4j/samples/ConvertOutPDFviaXSLFO.java#L152

bqujaahr

bqujaahr2#

Docx4J不支持所有语言。我必须使用OpenOffice与JDO转换器创建PDF从Word文档。工作起来像一个魅力。下面的代码,如果它帮助任何人:

public static void file2pdf(File input, File output) throws IOException {
        if (input == null) {
            throw new IllegalArgumentException("Input file must not be null");
        }
        if (output == null) {
            throw new IllegalArgumentException("Output file must not be null");
        }
        File path = output.getParentFile();
        if (path != null && !path.exists()) {
            path.mkdirs();
        }
        OpenOfficeConnection connection = new SocketOpenOfficeConnection("localhost", 8100);
        connection.connect();
        try {
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
            converter.convert(input, output);
        } finally {
            connection.disconnect();
        }
    }

相关问题