itextsharp - How to avoid duplicate font resources? -
i have code uses itextsharp's pdfsmartcopy
class combine multiple smaller pdf files 1 big one:
filestream outstream = new filestream(outputfilename, filemode.create, fileaccess.write); document document = new document(); pdfsmartcopy copy = new pdfsmartcopy(document, outstream); document.open(); foreach (string filename in filelist) { pdfreader reader = new pdfreader(filename); (int pagenum = 1; pagenum <= reader.numberofpages; ++pagenum) { copy.addpage(copy.getimportedpage(reader, pagenum)); } } document.close();
when extract pdf's resources using mutool extract
, there multiple identical copies of each of fonts uses:
c:\[...]>sha1sum *.cff *.ttf *.png | sort 0d150f99593d385764a1c7096b72448d09af8d72 *jpioad+helvetica-0020.cff 0d150f99593d385764a1c7096b72448d09af8d72 *jpioad+helvetica-0036.cff 0d150f99593d385764a1c7096b72448d09af8d72 *jpioad+helvetica-0049.cff 0d150f99593d385764a1c7096b72448d09af8d72 *jpioad+helvetica-0069.cff 0d150f99593d385764a1c7096b72448d09af8d72 *jpioad+helvetica-0084.cff 0d150f99593d385764a1c7096b72448d09af8d72 *jpioad+helvetica-0099.cff 17a99e597d3ec2cabf567cbfec032972f7e00962 *dxlqzy+lettergothicw1bold-0032.ttf 17a99e597d3ec2cabf567cbfec032972f7e00962 *gmyldu+lettergothicw1bold-0014.ttf 17a99e597d3ec2cabf567cbfec032972f7e00962 *mnvlmo+lettergothicw1bold-0045.ttf [etc.]
i've examined *.cff , *.ttf files in fontforge, , looks contain subset of characters used in document.
is there way make generated file contain 1 copy of fonts?
itext nor itextsharp can merge subsets of fonts 1 single subset. fonts, making such larger subset might doable, in cases, merging different fonts 1 impossible (in theory, large font sets, such chinese), in other cases, difficult (it mean entire contents streams need rewritten because character/glyph mapping has changed in merged font).
in other words: you're asking isn't trivial. it's not supported. it's kind of functionality we'd consider in context of paid consultancy.
Comments
Post a Comment