itextsharp - Embedding font using itext 5 for PDF/UA compliance -
we building proof of concept generate pdf/ua compliant pdf from css , html (xhtml) file using xslt. able tag pdf , add appropriate metadata information.
the last major issue unable solve embedding standard pdf font zapfdinbats, our accessibility assessment tool complains - using pac 2.0 along adobe dc built in checker.
as can see image below other fonts using seems automatically embedded using xmlworker our css.
i have tried finding font indicated , found one, however, doesn't seem correct one.
here sample of our code
private static returnvalue createfromhtml(string html) { returnvalue result = new returnvalue(); var stream = new memorystream(); using (var doc = new document(pagesize.letter)) { using (var ms = new memorystream()) { using (var writer = pdfwriter.getinstance(doc, ms)) { writer.closestream = false; writer.setpdfversion(pdfwriter.pdf_version_1_7); //tagged pdfversion_1_7 //make document tagged writer.settagged(); //=============== //pdf/ua //set document metadata writer.viewerpreferences = pdfwriter.displaydoctitle; doc.addlanguage("en-us"); doc.addtitle("document title"); writer.createxmpmetadata(); doc.open(); var embedfont = httpcontext.current.server.mappath("~/scripts/zapfdingbats.ttf"); var fontprov = new xmlworkerfontprovider(); fontprov.defaultencoding = "utf-8"; fontprov.register(embedfont); //testing zapfdingbats font font font = fontfactory.getfont(embedfont, basefont.identity_h, basefont.embedded); paragraph p1 = new paragraph("testing of fonts", font); doc.add(p1); //end font processing var tagprocessors = (defaulttagprocessorfactory)tags.gethtmltagprocessorfactory(); tagprocessors.removeprocessor(html.tag.img); tagprocessors.addprocessor(html.tag.img, new customimagetagprocessor()); var cssfiles = new cssfilesimpl(); cssfiles.add(xmlworkerhelper.getinstance().getdefaultcss()); var cssresolver = new styleattrcssresolver(cssfiles); var charset = encoding.utf8; var context = new htmlpipelinecontext(new cssappliersimpl(new xmlworkerfontprovider())); context.setacceptunknown(true).autobookmark(true).settagfactory(tagprocessors); var htmlpipeline = new htmlpipeline(context, new pdfwriterpipeline(doc, writer)); var csspipeline = new cssresolverpipeline(cssresolver, htmlpipeline); var worker = new xmlworker(csspipeline, true); var xmlparser = new xmlparser(true, worker, charset); using (var sr = new stringreader(html)) { xmlparser.parse(sr); doc.close(); ms.position = 0; ms.copyto(stream); stream.position = 0; } } } } // bytes stream result.data = stream.toarray(); // success result.success = true; return result; }
maybe there in css need (our css quite large f
itext ships adobe font metrics (afm) file of zapfdingbats. means can't embed font unless provide corresponding postscript font binary (pfb) file. pfb file can't shipped itext because itext doesn't have license so.
the first step solve this, to:
- purchase zapfdingbats license pfb (if recall correctly, it's font owned adobe), or
- use alternative font when want insert special characters (check boxes, phone symbols,...) text (e.g. purchase license adobepistd font used substitution font , use font instead of zapfdingbats).
in case, provided font zapfdingbats.ttf
register xmlworkerfontprovider
. when register font, can recognized through alias. if zapfdingbats.ttf
isn't picked xml worker, there mismatch between name of font used in pdf , alias used when zapfdingbats.ttf
registered.
what font name used zapfdingbats in css? should register zapfdingbats
using name alias.