From 1d52530229e8dce7415708f1a28332b2c383a1cb Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Thu, 7 Apr 2022 21:55:45 +0200 Subject: [PATCH] support new pikepdf.Page object when making indirect objects (closes: #132) --- src/img2pdf.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/img2pdf.py b/src/img2pdf.py index 7bb2e2c..b84fc24 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -1106,9 +1106,17 @@ class pdfdoc(object): [initial_page, PdfName.XYZ, NullObject, NullObject, 0] ) - # the /OpenAction array must contain the page as an indirect object + # The /OpenAction array must contain the page as an indirect object. + # This changed some time after 4.2.0 and on or before 5.0.0 and current + # versions require to use .obj or otherwise we get: + # TypeError: Can't convert ObjectHelper (or subclass) to Object + # implicitly. Use .obj to get access the underlying object. + # See https://github.com/pikepdf/pikepdf/issues/313 for details. if self.engine == Engine.pikepdf: - initial_page = self.writer.make_indirect(initial_page) + if isinstance(initial_page, pikepdf.Page): + initial_page = self.writer.make_indirect(initial_page.obj) + else: + initial_page = self.writer.make_indirect(initial_page) if self.magnification == Magnification.fit: catalog[PdfName.OpenAction] = PdfArray([initial_page, PdfName.Fit])