I'm using iText for .NET and I get a PdfAConformanceException
with message:
"All the fonts must be embedded. This one isn't: Helvetica"
How can I embed Helvetica?
This is my code
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);
}
Please read the iText 7 Jump-start tutorial, more specifically Chapter 7: Creating PDF/UA and PDF/A documents!
I quote:
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:
- 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.
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.
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."));
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.