Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid PDF/A-3 test failure #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

abelykh0
Copy link

@abelykh0 abelykh0 commented Jan 8, 2023

Avoid PDF/A-3 test failure (ISO 32000-1:2008, 9.7.4, Table 117 requires that all embedded Type 2 CIDFonts in the CIDFont dictionary shall contain a CIDToGIDMap entry that shall be a stream mapping from CIDs to glyph indices or the name Identity, as described in ISO 32000-1:2008, 9.7.4, Table 117)

There's no easy way to do it otherwise. This is what works, but it is really ugly

			// HACK: Add required /CIDToGIDMap /Identity to fonts
			//var fontTable = document.FontTable;
			//var documentFonts = fontTable._fonts;
			var fontTableProperty = typeof(PdfDocument).GetProperty("FontTable", BindingFlags.NonPublic | BindingFlags.Instance);
			object fontTable = fontTableProperty.GetValue(document, null);
			var fontsField = fontTable.GetType().GetField("_fonts", BindingFlags.NonPublic | BindingFlags.Instance);
			var documentFonts = (IDictionary<string, PdfFont>)fontsField.GetValue(fontTable);
			foreach (var documentFont in documentFonts.Values)
			{
				if (documentFont.Elements.TryGetValue("/DescendantFonts", out PdfItem descendantFontItem))
				{
					PdfArray descendantFont = (PdfArray)descendantFontItem;
					var descendantFontDictionary = (PdfDictionary)((PdfReference)descendantFont.Elements[0]).Value;
					descendantFontDictionary.Elements.SetName("/CIDToGIDMap", "/Identity");
				}
			}

…es that all embedded Type 2 CIDFonts in the CIDFont dictionary shall contain a CIDToGIDMap entry that shall be a stream mapping from CIDs to glyph indices or the name Identity, as described in ISO 32000-1:2008, 9.7.4, Table 117)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant