@@ -896,6 +896,64 @@ def removeText(self, ignoreByteStringObject=False):
896896
897897 pageRef .__setitem__ (NameObject ('/Contents' ), content )
898898
899+ def addURI (self , pagenum , uri , rect , border = None ):
900+ """
901+ Add an URI from a rectangular area to the specified page.
902+ This uses the basic structure of AddLink
903+
904+ :param int pagenum: index of the page on which to place the URI action.
905+ :param int uri: string -- uri of resource to link to.
906+ :param rect: :class:`RectangleObject<PyPDF2.generic.RectangleObject>` or array of four
907+ integers specifying the clickable rectangular area
908+ ``[xLL, yLL, xUR, yUR]``, or string in the form ``"[ xLL yLL xUR yUR ]"``.
909+ :param border: if provided, an array describing border-drawing
910+ properties. See the PDF spec for details. No border will be
911+ drawn if this argument is omitted.
912+
913+ REMOVED FIT/ZOOM ARG
914+ -John Mulligan
915+ """
916+
917+ pageLink = self .getObject (self ._pages )['/Kids' ][pagenum ]
918+ pageRef = self .getObject (pageLink )
919+
920+ if border is not None :
921+ borderArr = [NameObject (n ) for n in border [:3 ]]
922+ if len (border ) == 4 :
923+ dashPattern = ArrayObject ([NameObject (n ) for n in border [3 ]])
924+ borderArr .append (dashPattern )
925+ else :
926+ borderArr = [NumberObject (2 )] * 3
927+
928+ if isString (rect ):
929+ rect = NameObject (rect )
930+ elif isinstance (rect , RectangleObject ):
931+ pass
932+ else :
933+ rect = RectangleObject (rect )
934+
935+ lnk2 = DictionaryObject ()
936+ lnk2 .update ({
937+ NameObject ('/S' ): NameObject ('/URI' ),
938+ NameObject ('/URI' ): TextStringObject (uri )
939+ });
940+ lnk = DictionaryObject ()
941+ lnk .update ({
942+ NameObject ('/Type' ): NameObject ('/Annot' ),
943+ NameObject ('/Subtype' ): NameObject ('/Link' ),
944+ NameObject ('/P' ): pageLink ,
945+ NameObject ('/Rect' ): rect ,
946+ NameObject ('/H' ): NameObject ('/I' ),
947+ NameObject ('/Border' ): ArrayObject (borderArr ),
948+ NameObject ('/A' ): lnk2
949+ })
950+ lnkRef = self ._addObject (lnk )
951+
952+ if "/Annots" in pageRef :
953+ pageRef ['/Annots' ].append (lnkRef )
954+ else :
955+ pageRef [NameObject ('/Annots' )] = ArrayObject ([lnkRef ])
956+
899957 def addLink (self , pagenum , pagedest , rect , border = None , fit = '/Fit' , * args ):
900958 """
901959 Add an internal link from a rectangular area to the specified page.
0 commit comments