创建PDF/A文件时,出现错误:“未嵌入Helvetica". [英] When creating a PDF/A file, I get the error: "Helvetica is not embedded"

查看:343
本文介绍了创建PDF/A文件时,出现错误:“未嵌入Helvetica".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将iText用于.NET,并且出现带有消息的PdfAConformanceException:

I'm using iText for .NET and I get a PdfAConformanceException with message:

必须嵌入所有字体.这不是:Helvetica"

"All the fonts must be embedded. This one isn't: Helvetica"

如何嵌入Helvetica?

How can I embed Helvetica?

这是我的代码

static void Main(string[] args)
{
   ConverterProperties properties = new ConverterProperties();
   properties.SetBaseUri(null);
   PdfWriter writer = new PdfWriter("hello.pdf");    

   PdfADocument pdf = new PdfADocument(writer, 
   PdfAConformanceLevel.PDF_A_3A, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new StreamReader(INTENT).BaseStream));                   

   pdf.SetTagged();

   var html = @"<!DOCTYPE html>
                <html>
                   <body>
                      <h1>My First Heading</h1>
                      <p>My first paragraph.</p>
                   </body>
                </html>
              ";

  HtmlConverter.ConvertToPdf(html, pdf, properties);
}

推荐答案

请阅读 iText 7入门教程,更具体地讲我引用:

创建长期保存的PDF,第1部分

ISO 19005的第1部分于2005年发布.它被定义为子集 的PDF规范1.4版(当时, 还不是ISO标准). ISO 19005-1引入了一系列 义务与限制:

Creating PDFs for long-term preservation, part 1

Part 1 of ISO 19005 was released in 2005. It was defined as a subset of version 1.4 of Adobe's PDF specification (which, at that time, wasn't an ISO standard yet). ISO 19005-1 introduced a series of obligations and restrictions:

  • 文档必须是独立的:所有字体都必须为 嵌入式不允许使用外部电影,声音或其他二进制文件.
  • 文档需要在可扩展元数据中包含元数据 平台(XMP)格式: ISO 16684(XMP)描述了如何嵌入XML 元数据转换为二进制文件,从而使不知道如何操作的软件 解释二进制数据格式仍可以提取文件的 元数据.
  • 不允许过时的功能: PDF不能 包含任何JavaScript,并且可能未加密.
  • The document needs to be self-contained: all fonts need to be embedded; external movie, sound or other binary files are not allowed.
  • The document needs to contain metadata in the eXtensible Metadata Platform (XMP) format: ISO 16684 (XMP) describes how to embed XML metadata into a binary file, so that software that doesn't know how to interpret the binary data format can still extract the file's metadata.
  • Functionality that isn't future-proof isn't allowed: the PDF can't contain any JavaScript and may not be encrypted.

您正面临未嵌入字体的问题.这是因为您没有提供字体程序. iText随附14种标准Type 1字体的字体规格(版本中有14个AFM文件).这些是每个PDF查看器都应该知道的字体.如果您确实想使用Helvetica,则需要提供字体二进制文件(PFB文件). iText不能附带这些文件,因为这些文件是专有文件.如果要使用它们,则需要从字体所有者那里购买许可证.

You are facing the problem that the font isn't embedded. This is because you don't provide a font program. iText ships with the font metrics of the 14 standard Type 1 fonts (there are 14 AFM files in the release). These are fonts that are supposed to be known by every PDF viewer. If you really want to use Helvetica, you need to provide the font binaries (PFB files). These can't be shipped with iText, because those files are proprietary. You need to purchase a license from the owner of the font if you want to use them.

我假设您的问题是错误的:如何嵌入Helvetica?"也就是说:您不想购买所需的PFB文件.另外,您也可以按照本教程中的说明使用免费字体:

I'm assuming that your question is wrong: "How can I embed Helvetica?" That is: that you don't want to purchase the required PFB file. As an alternative you can use a free font as is done in the tutorial:

public const String FONT = "resources/font/FreeSans.ttf";
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true);
Paragraph p = new Paragraph()
    .SetFont(font).Add(new Text("Text with embedded font."));

这是实现PDF/A一致性的第一步.它将解决您在问题中描述的问题.但是,由于您不共享问题中的任何代码(这违反了Stack Overflow的规则),因此我假设您缺少许多其他PDF/A要求.您可以在官方网站上的教程中找到有关这些要求的更多信息.

This is a first step towards PDF/A conformance. It will solve the problem you describe in your question. However, as you don't share any code in your question (which goes against the rules of Stack Overflow), I'm assuming that you are missing plenty of other PDF/A requirements. You'll discover more about those requirements in the tutorials on the official web site.

这篇关于创建PDF/A文件时,出现错误:“未嵌入Helvetica".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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