Fixed TabError in Py3

This commit is contained in:
Matthew Stamy 2016-08-17 13:28:21 -05:00
parent 0208955e1d
commit ad90b69592
1 changed files with 49 additions and 58 deletions

View File

@ -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<PyPDF2.generic.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<PyPDF2.generic.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.