From ad90b69592d30ce8e7f787d1f1f7fceeb77ec9ed Mon Sep 17 00:00:00 2001 From: Matthew Stamy Date: Wed, 17 Aug 2016 13:28:21 -0500 Subject: [PATCH] Fixed TabError in Py3 --- PyPDF2/pdf.py | 107 +++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 58 deletions(-) diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py index b47247f..d1751a7 100644 --- a/PyPDF2/pdf.py +++ b/PyPDF2/pdf.py @@ -896,73 +896,64 @@ class PdfFileWriter(object): pageRef.__setitem__(NameObject('/Contents'), content) - def addURI(self, pagenum, uri, rect, border=None): - """ - - Add an URI from a rectangular area to the specified page. - This uses the basic structure of AddLink + """ + Add an URI from a rectangular area to the specified page. + This uses the basic structure of AddLink - :param int pagenum: index of the page on which to place the link. - :param int uri: string -- uri of resource to link to. - :param rect: :class:`RectangleObject` or array of four - integers specifying the clickable rectangular area - ``[xLL, yLL, xUR, yUR]``, or string in the form ``"[ xLL yLL xUR yUR ]"``. - :param border: if provided, an array describing border-drawing - properties. See the PDF spec for details. No border will be - drawn if this argument is omitted. - - REMOVED FIT/ZOOM ARG - -John Mulligan + :param int pagenum: index of the page on which to place the URI action. + :param int uri: string -- uri of resource to link to. + :param rect: :class:`RectangleObject` or array of four + integers specifying the clickable rectangular area + ``[xLL, yLL, xUR, yUR]``, or string in the form ``"[ xLL yLL xUR yUR ]"``. + :param border: if provided, an array describing border-drawing + properties. See the PDF spec for details. No border will be + drawn if this argument is omitted. - """ + REMOVED FIT/ZOOM ARG + -John Mulligan + """ - - - - pageLink = self.getObject(self._pages)['/Kids'][pagenum] - pageRef = self.getObject(pageLink) - - if border is not None: - borderArr = [NameObject(n) for n in border[:3]] - if len(border) == 4: - dashPattern = ArrayObject([NameObject(n) for n in border[3]]) - borderArr.append(dashPattern) - else: - borderArr = [NumberObject(2)] * 3 + pageLink = self.getObject(self._pages)['/Kids'][pagenum] + pageRef = self.getObject(pageLink) - if isString(rect): - rect = NameObject(rect) - elif isinstance(rect, RectangleObject): - pass - else: - rect = RectangleObject(rect) + if border is not None: + borderArr = [NameObject(n) for n in border[:3]] + if len(border) == 4: + dashPattern = ArrayObject([NameObject(n) for n in border[3]]) + borderArr.append(dashPattern) + else: + borderArr = [NumberObject(2)] * 3 - lnk2 = DictionaryObject() + if isString(rect): + rect = NameObject(rect) + elif isinstance(rect, RectangleObject): + pass + else: + rect = RectangleObject(rect) - lnk2.update({ - NameObject('/S'): NameObject('/URI'), - NameObject('/URI'): TextStringObject(uri) - }); - lnk = DictionaryObject() - lnk.update({ - NameObject('/Type'): NameObject('/Annot'), - NameObject('/Subtype'): NameObject('/Link'), - NameObject('/P'): pageLink, - NameObject('/Rect'): rect, - NameObject('/H'): NameObject('/I'), - NameObject('/Border'): ArrayObject(borderArr), - NameObject('/A'): lnk2 - }) - lnkRef = self._addObject(lnk) + lnk2 = DictionaryObject() + lnk2.update({ + NameObject('/S'): NameObject('/URI'), + NameObject('/URI'): TextStringObject(uri) + }); + lnk = DictionaryObject() + lnk.update({ + NameObject('/Type'): NameObject('/Annot'), + NameObject('/Subtype'): NameObject('/Link'), + NameObject('/P'): pageLink, + NameObject('/Rect'): rect, + NameObject('/H'): NameObject('/I'), + NameObject('/Border'): ArrayObject(borderArr), + NameObject('/A'): lnk2 + }) + lnkRef = self._addObject(lnk) - if "/Annots" in pageRef: - pageRef['/Annots'].append(lnkRef) - else: - pageRef[NameObject('/Annots')] = ArrayObject([lnkRef]) + if "/Annots" in pageRef: + pageRef['/Annots'].append(lnkRef) + else: + pageRef[NameObject('/Annots')] = ArrayObject([lnkRef]) - _valid_layouts = ['/NoLayout', '/SinglePage', '/OneColumn', '/TwoColumnLeft', '/TwoColumnRight', '/TwoPageLeft', '/TwoPageRight'] - def addLink(self, pagenum, pagedest, rect, border=None, fit='/Fit', *args): """ Add an internal link from a rectangular area to the specified page.