2

当我将 docx 文档转换为 pdf 时,我的国家字符转换为“#”标记。
有没有办法为pdf文档设置字体编码?

我过去使用过 xdocreport,它可以处理这个问题,但我在图像、页眉和页脚方面遇到了问题。

Docx4j 设法做到这一点,但不是字体。转换后,字体有 ANSI 编码,而我想有 windows-1250。有没有设置这个选项?

4

2 回答 2

4

我的问题是 - 在 linux 服务器上缺少正确的 True Type 字体。代替插入的默认字体(没有我的代码页)。

我通过 ttf-mscorefonts-installer 解决了安装默认 Ms Windows 字体的问题

在 debian 上:

apt-get install ttf-mscorefonts-installer
于 2012-09-10T08:19:18.783 回答
2

我有同样的问题,发现正如你自己提到的,字体问题。系统上的字体需要支持您的编码。

例如:对于使用“Arial”字体的文档,德语变音符号显示为“?”。

我找到了另一种解决方案,以覆盖 PDF 字体编码,如下所示:

    //
    // read template
    //
    File docxFile = new File(System.getProperty("user.dir") + "/" + "Test.docx");
    InputStream in = new FileInputStream(docxFile);

    // 
    // prepare document context
    //
    IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
    IContext context = report.createContext();
    context.put("name", "Michael Küfner");

    // 
    // generate PDF output
    //
    Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.XWPF);
    PdfOptions pdfOptions = PdfOptions.create();
    pdfOptions.fontEncoding("iso-8859-15");
    options.subOptions(pdfOptions);     


    OutputStream out = new FileOutputStream(new File(docxFile.getPath() + ".pdf"));
    report.convert(context, options, out);

尝试根据您的需要设置 pdfOptions.fontEndcoding 中的属性(在我的情况下为“iso-8859-15”)。

将此设置为“UTF-8”,这是默认的接缝,导致特殊字符出现同样的问题。

我发现的另一件事:

使用 Word 2007/2010 默认的“Calibri”字体,即使使用 UTF-8 编码也不会出现问题。可能 iText 中用于生成 PDF 的嵌入式 Type-1 Arial 字体不支持 UTF-8 编码。

于 2013-08-29T07:30:12.607 回答