Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca2726a

Browse files
committed
Resolve PDFObjRef objects to strings (fix jdmonaco#1)
1 parent 3387488 commit ca2726a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

‎pdf-title-rename.py‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,34 +123,43 @@ def _get_info(self, fn):
123123
info = self._get_metadata(pdf)
124124

125125
if 'Title' in info:
126+
ti = self._resolve_objref(info['Title'])
126127
try:
127-
title = info['Title'].decode()
128+
title = ti.decode()
128129
except AttributeError:
129130
pass
130-
else:
131-
title = title.strip()
132131

133132
if 'Author' in info:
133+
au = self._resolve_objref(info['Author'])
134134
try:
135-
author = info['Author'].decode()
135+
author = au.decode()
136136
except AttributeError:
137137
pass
138138

139139
if 'Metadata' in self.doc.catalog:
140140
xmpt, xmpa = self._get_xmp_metadata()
141+
xmpt = self._resolve_objref(xmpt)
142+
xmpa = self._resolve_objref(xmpa)
141143
if xmpt:
142144
title = xmpt
143145
if xmpa:
144146
author = xmpa
145147

146-
if type(title) is str and title.lower().strip() == 'untitled':
147-
title = None
148+
if type(title) is str:
149+
title = title.strip()
150+
if title.lower() == 'untitled':
151+
title = None
148152

149153
if self.interactive:
150154
title, author = self._interactive_info_query(fn, title, author)
151155

152156
return title, author
153157

158+
def _resolve_objref(self, ref):
159+
if hasattr(ref, 'resolve'):
160+
return ref.resolve()
161+
return ref
162+
154163
def _interactive_info_query(self, fn, t, a):
155164
print('-' * 60)
156165
print('Filename:'.ljust(20), fn)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /