I'm doing various manipulations to a pdf, and at one point I create a new pdf from a set of pages in the original. The original pdf does not have any fonts embedded, so I want to embed the used fonts into the new pdf when I create it. However, when I open the new pdf, the fonts are not embedded. What step am I missing?
# Python 2.7 Snippet
for group in groupings:
logger.info("pages {0}-{1}".format(group[1], group[2]))
new_doc = PDFDoc()
copy_pages = VectorPage()
itr = in_doc.GetPageIterator(group[1])
while itr.HasNext():
if itr.Current().GetIndex() > group[2]:
break
page = itr.Current()
res = page.GetResourceDict()
copy_pages.push_back(page)
if (res != None):
fonts = res.FindObj("Font")
if (fonts != None):
#itr2 = fonts.DictBegin()
itr2 = fonts.GetDictIterator()
#end = fonts.DictEnd()
while itr2.HasNext():
fnt_dict = itr2.Value()
font = Font(fnt_dict)
if font.GetName() not in fontsToEmbed:
fontsToEmbed.append(font.GetName())
itr2.Next()
itr.Next()
for f in fontsToEmbed:
if f == 'Times-Roman':
Font.Create(new_doc.GetSDFDoc(), Font.e_times_roman, True)
elif f == 'CourierNewPSMT':
Font.Create(new_doc.GetSDFDoc(), Font.e_courier, True)
else:
logger.info("Unknown font: {0}".format(f))
fontsToEmbed = []
imported_pages = new_doc.ImportPages(copy_pages)
i = iter(imported_pages)
for x in i:
new_doc.PagePushBack(x)
new_doc.Save("{0}.pdf".format(os.path.join(output_path, basename)), 0)
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