我需要使用 Java 版 Apache PDFBox 库向 PDF/A 文件添加一些文本。问题是,因为它需要是有效的 PDF/A 文件,所以所有使用的字体都必须嵌入其中。我知道我可以使用 PDFBox 嵌入 TTF 字体,但我想避免必须向应用程序提供字体文件,所以我想知道是否有一种方法可以嵌入 PDFBox 中可用的标准字体之一,就好像它一样是外部的。
例如,当我使用其中一种标准字体编写内容时,PDF 验证器会抱怨:
我使用以下代码来编写文本:
PDFont standardFont = PDType1Font.HELVETICA_BOLD;
PDPage pag = new PDPage();
pag.setResources(new PDResources());
PDPageContentStream contentStream = new PDPageContentStream(pdfFile, pag);
//Begin the Content stream
contentStream.beginText();
//Setting the font to the Content stream
contentStream.setFont(standardFont, 12);
//Setting the position for the line
contentStream.newLineAtOffset(25, 500);
//Adding text in the form of string
contentStream.showText("JUST A SAMPLE STRING");
//Ending the content stream
contentStream.endText();
//Closing the content stream
contentStream.close();
pdfFile.addPage(pag);
pdfFile.save(file);
pdfFile.close();
设置时是否有任何选项可以强制嵌入字体?
提前致谢,
PDFBox 中仅嵌入一种字体。您可以这样使用它:
PDFont font = PDType0Font.load(doc, SomePdfboxClass.class.getResourceAsStream(
"/org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf"));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)