trn2
unread,Sep 22, 2009, 8:14:46 PM9/22/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PDFTron PDFNet SDK
Q: Thanks for the response. From the knowledge base articles I see
that people have had the same issue. However, I couldn't find any
sample code that would show how to figure out and create a "substitute
font". Do you know of any sample code that can get me started?
-----------
A: Windows can search for the font with the same name or find a
substitute when you create 'System.Drawing.Font'.
For example:
System.Drawing.Font font = new System.Drawing.Font(fontname, 1,
eStyle);
pdftron.PDF.Font f = pdftron.PDF.Font.CreateTrueTypeFont(doc, font,
true, false);
The remaining task it to obtain the font name (i.e. fontname) and font
styles (e.g. font weight, italic angle, etc) from the old PDF font.
All of this information can be used to select the appropriate font
from the user system. For example:
string fn = oldfont.GetName();
Please note that in PDF, subsetted fonts sometimes start with a 'ABCDEF
+' prefix and this prefix should be removed. Also you should remove
any trailing text following a comma (as in TimesNewRoman,Bold ->
TimesNewRoman). Something along the following lines:
int idx = fn.find_first_of('+');
if (idx==6 && fn.size()>7) { // remove font substitution prefix
fn = fn.substr(idx+1);
}
// extract name for TrueType fonts with extra styles idx =
fn.find_first_of (','); if (idx != string::npos) {
string style = fn.substr(idx+1);
fn = fn.substr(0, idx);
if (style == "Bold") {
is_bold = true;
}
else if (style == "Italic") {
is_italic = true;
}
else if (style == "BoldItalic") {
is_bold = true;
is_italic = true;
}
}
You can obtain FontWeight and other styles from a PDF font as follows:
double GetFontWeight(pdftron.PDF.Font font) {
double v = 400;
Obj font_desc = font.GetDescriptor();
if (font_desc != null) {
Obj a = font_desc.FindObj("FontWeight");
if (a != null) {
v = a.GetNumber();
}
}
return v;
}
Font 'weight' is a number in the range 300-900 where each number
indicates a weight that is at least as dark as its predecessor. A
value of 400 indicates a normal weight; 700 indicates bold.
---
In case you don't like Windows font substitution you can also
implement your own substitution, however it is a bit more work.