Itext嵌入PDF中的字体 [英] Itext embed font in a PDF

查看:832
本文介绍了Itext嵌入PDF中的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Foxit表单设计器创建的pdf。在我的设计系统上,我安装了条形码字体。条形码字体用于其中一个AcroFields。看来,狐狸不会在文档中嵌入字体。



我也有客户没有安装在他们的计算机中的条形码字体,因此我想将字体嵌入到PDF中。有没有一种方法可以将AcroField中使用的字体嵌入到iText的PDF中?



编辑:字体似乎被包含在文本中,但不包括字段,因此字体(条形码)将不会被打印。

确定你现在得到了一个答案,但是也许其他人想要得到解决方案的详细的观点。下面是我用来在生成的PDF中嵌入字体的示例java代码(仅在某些情况下有用,因为文档的大小显着增加)。
作为创建PDF表单的免费工具,我使用了OpenOffice编写器,在文档中添加表单并将文档导出为PDF文件:

  PdfReader pdfTemplate = new PdfReader(templateName); 
ByteArrayOutputStream out = new ByteArrayOutputStream();
BaseFont unicode = BaseFont.createFont(unicodeFontPath,BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
PdfStamper stamper = new PdfStamper(pdfTemplate,out);
//将字体分配给字段
stamper.getAcroFields()。setFieldProperty(myField,textfont,unicode,null);
stamper.getAcroFields()。setField(myField,someValue);
stamper.close();
pdfTemplate.close();


I have a pdf that has been created using the Foxit form designer. On my design system, I have the barcode font installed. The barcode font is used in one of the AcroFields. It appears that foxit does not embed the font in the document.

I also have customers that do not have the barcode font installed in their computers, and thus I would like to embed the font into the PDF. Is there a way for me to embed a font that is used in the AcroFields into the PDF using iText?

EDIT: The font seems to be included in the text, but not the fields, Therefore the font(barcode) will not print.

解决方案

I'm almost sure that you got an answer by now, but maybe others would like to get a detailed view on the solution. Below is the sample java code I used to embed fonts in the generated PDF (useful only in some cases, as the size of the documents increases dramatically). As a free tool to create the PDF forms, I have used the OpenOffice writer, by adding forms inside the documents and exporting the documents as PDF files :

PdfReader pdfTemplate = new PdfReader(templateName);
ByteArrayOutputStream out = new ByteArrayOutputStream();
BaseFont unicode = BaseFont.createFont(unicodeFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
PdfStamper stamper = new PdfStamper(pdfTemplate, out);
//assigning the font to the field
stamper.getAcroFields().setFieldProperty("myField", "textfont", unicode, null);
stamper.getAcroFields().setField("myField", someValue);
stamper.close();
pdfTemplate.close();

这篇关于Itext嵌入PDF中的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆