All,
After looking around, I have a method to iterate over all of a pdf file's pages and get the fonts. Then I embed some alternative fonts and convert all of the old fonts to the new fonts. This works fine for CourierNewPSMT, but not for TimesNewRomanPSMT. I don't receive any errors, but the output pdf still lists TimesNewRomanPSMT as not being embedded in the pdf. Python code below:
doc = PDFDoc(infile)
doc.InitSecurityHandler()
itr = doc.GetPageIterator()
while itr.HasNext():
page = itr.Current()
res = page.GetResourceDict()
if (res != None):
fonts = res.FindObj("Font")
if (fonts != None):
itr2 = fonts.GetDictIterator()
while itr2.HasNext():
fnt_dict = itr2.Value()
font = Font(fnt_dict)
if font not in fontsToEmbed:
fontsToEmbed.append(font)
itr2.Next()
itr.Next()
timesRoman = Font.Create(doc.GetSDFDoc(), Font.e_times_roman, True)
courierNew = Font.Create(doc.GetSDFDoc(), Font.e_courier, True)
for f in fontsToEmbed:
if f.GetName() == 'Times-Roman':
doc.GetSDFDoc().Swap(timesRoman.GetSDFObj().GetObjNum(), f.GetSDFObj().GetObjNum())
elif f.GetName() == 'TimesNewRomanPSMT':
doc.GetSDFDoc().Swap(timesRoman.GetSDFObj().GetObjNum(), f.GetSDFObj().GetObjNum())
elif f.GetName() == 'CourierNewPSMT':
doc.GetSDFDoc().Swap(courierNew.GetSDFObj().GetObjNum(), f.GetSDFObj().GetObjNum())
elif f.GetName() == 'Courier':
doc.GetSDFDoc().Swap(courierNew.GetSDFObj().GetObjNum(), f.GetSDFObj().GetObjNum())
else:
logger.info("Unknown font: {0}".format(f.GetName()))
doc.Save(infile, SDFDoc.e_remove_unused)
doc.Close()
I checked to see if the if logic was wrong, but it does enter the TimesNewRomanPSMT section. So, why would swap not work for that font only?
Spencer Rathbun
IT/Programming
L & D Mail Masters, Inc.
110 Security Parkway
New Albany, IN 47150
Phone: 812.981.7161
Fax: 812.981.7169
srathbun@ldmailmasters.com