Embed TimesNewRomanPSMT not working

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

The most likely problem is that these fonts have different encoding.

A font can be swapped without side effects iff
a) PDF font encoding is the same and
b) Fonts contains the same glyph set.

If a or b does not hold, you may run into rendering/processing issues.

For more info please see: https://groups.google.com/d/msg/pdfnet-sdk/OOfbGefzWwU/JB4enkPI72cJ

I’ve dealt with the issue.

Apparently, you only want to swap each unique font name once, or else it doesn’t actually work. So if you iterate over each page, you get a new entry each time TimesNewRomanPSMT comes up. If you run swap once for each entry, it fails. But if you only swap the first one, then they all get changed.

Spencer Rathbun

I see, the problem was that you were swapping the same font oven number of times - ending with the original font.

Now, even though this works in your particular situation, still this technique not work in general (due to different encodings etc).