简体   繁体   English

如何使用Docx4J设置pdf输出的字体

[英]How to set a font for pdf output using Docx4J

I am using Docx4J.toPDF(wordMLPackage, new FOS("path/to/file.pdf")) in order to convert a ".docx" file to ".pdf" . 我正在使用Docx4J.toPDF(wordMLPackage, new FOS("path/to/file.pdf"))以将".docx"文件转换为".pdf" Although the conversion is happening fine but the original document had Calibri font and the resultant pdf has Arial . 虽然转换发生得很好但原始文档有Calibri字体,因此pdf有Arial Is there a way to set the font while doing this conversion. 有没有办法在进行此转换时设置字体。

It would be better if you could give some link to how font properties can be set in general like font size, font family etc, if there is facility for that. 如果您可以提供一些链接,如果有一些设施,可以更好地设置字体属性,如字体大小,字体系列等。

I searched online but could not find any help on this. 我在网上搜索但没有找到任何帮助。 Waiting for your responses. 等待你的回复。 Thanks! 谢谢!

I think that you will have to embend the Calibiri font (file) into the PDF. 我认为您必须将Calibiri字体(文件)嵌入到PDF中。 I am using Calibri in generated PDFs as well and this is what i had to do. 我也在生成的PDF中使用Calibri,这就是我必须要做的。 I was using PDFe 我在使用PDFe

I dont know how how to do this in docx4j , but in case of iText(that I am using) I had to register the font like this 我不知道如何在docx4j执行此操作,但在iText(我正在使用)的情况下,我必须注册这样的字体

    FontFactory.registerDirectory("./resources/fonts/", true);
    com.itextpdf.text.Font iFont = FontFactory.getFont(font, getEncodingForFont(font), true);

and after this, iFont was automaticly embended into PDF so it can be displayed correctly on systems that does not have Calibri installed. 之后,iFont自动加入PDF,因此可以在没有安装Calibri系统上正确显示。

This may be related to your issue http://www.docx4java.org/forums/docx-java-f6/embedded-fonts-not-used-in-pdf-conversion-t1137.html 这可能与您的问题有关http://www.docx4java.org/forums/docx-java-f6/embedded-fonts-not-used-in-pdf-conversion-t1137.html

And also there seems to be something into the canse on SO already: How to change font encoding when converting docx -> pdf with docx4j? 而且在SO上似乎还有一些东西: 如何在转换docx时更改字体编码 - > pdf with docx4j?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM