Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pypdf/generic/__init__.py: 80%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

50 statements  

1# Copyright (c) 2006, Mathieu Fenniak 

2# All rights reserved. 

3# 

4# Redistribution and use in source and binary forms, with or without 

5# modification, are permitted provided that the following conditions are 

6# met: 

7# 

8# * Redistributions of source code must retain the above copyright notice, 

9# this list of conditions and the following disclaimer. 

10# * Redistributions in binary form must reproduce the above copyright notice, 

11# this list of conditions and the following disclaimer in the documentation 

12# and/or other materials provided with the distribution. 

13# * The name of the author may not be used to endorse or promote products 

14# derived from this software without specific prior written permission. 

15# 

16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 

17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 

18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 

19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 

20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 

21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 

22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 

23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 

24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 

25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 

26# POSSIBILITY OF SUCH DAMAGE. 

27 

28"""Implementation of generic PDF objects (dictionary, number, string, ...).""" 

29__author__ = "Mathieu Fenniak" 

30__author_email__ = "biziqe@mathieu.fenniak.net" 

31 

32from typing import List, Optional, Tuple, Union 

33 

34from .._utils import ( 

35 deprecation_with_replacement, 

36) 

37from ..constants import OutlineFontFlag 

38from ._base import ( 

39 BooleanObject, 

40 ByteStringObject, 

41 FloatObject, 

42 IndirectObject, 

43 NameObject, 

44 NullObject, 

45 NumberObject, 

46 PdfObject, 

47 TextStringObject, 

48 encode_pdfdocencoding, 

49 is_null_or_none, 

50) 

51from ._data_structures import ( 

52 ArrayObject, 

53 ContentStream, 

54 DecodedStreamObject, 

55 Destination, 

56 DictionaryObject, 

57 EncodedStreamObject, 

58 Field, 

59 StreamObject, 

60 TreeObject, 

61 read_object, 

62) 

63from ._files import EmbeddedFile 

64from ._fit import Fit 

65from ._outline import OutlineItem 

66from ._rectangle import RectangleObject 

67from ._utils import ( 

68 create_string_object, 

69 decode_pdfdocencoding, 

70 hex_to_rgb, 

71 read_hex_string_from_stream, 

72 read_string_from_stream, 

73) 

74from ._viewerpref import ViewerPreferences 

75 

76PAGE_FIT = Fit.fit() 

77 

78 

79class AnnotationBuilder: # deprecated 

80 """ 

81 The AnnotationBuilder is deprecated. 

82 

83 Instead, use the annotation classes in pypdf.annotations. 

84 

85 See `adding PDF annotations <../user/adding-pdf-annotations.html>`_ for 

86 its usage combined with PdfWriter. 

87 """ 

88 

89 from ..generic._rectangle import RectangleObject # noqa: PLC0415 

90 

91 @staticmethod 

92 def text( 

93 rect: Union[RectangleObject, Tuple[float, float, float, float]], 

94 text: str, 

95 open: bool = False, 

96 flags: int = 0, 

97 ) -> None: 

98 deprecation_with_replacement( 

99 "AnnotationBuilder.text", "pypdf.annotations.Text", "5.0.0" 

100 ) 

101 

102 @staticmethod 

103 def free_text( 

104 text: str, 

105 rect: Union[RectangleObject, Tuple[float, float, float, float]], 

106 font: str = "Helvetica", 

107 bold: bool = False, 

108 italic: bool = False, 

109 font_size: str = "14pt", 

110 font_color: str = "000000", 

111 border_color: Optional[str] = "000000", 

112 background_color: Optional[str] = "ffffff", 

113 ) -> None: 

114 deprecation_with_replacement( 

115 "AnnotationBuilder.free_text", "pypdf.annotations.FreeText", "5.0.0" 

116 ) 

117 

118 @staticmethod 

119 def popup( 

120 *, 

121 rect: Union[RectangleObject, Tuple[float, float, float, float]], 

122 flags: int = 0, 

123 parent: Optional[DictionaryObject] = None, 

124 open: bool = False, 

125 ) -> None: 

126 deprecation_with_replacement( 

127 "AnnotationBuilder.popup", "pypdf.annotations.Popup", "5.0.0" 

128 ) 

129 

130 @staticmethod 

131 def line( 

132 p1: Tuple[float, float], 

133 p2: Tuple[float, float], 

134 rect: Union[RectangleObject, Tuple[float, float, float, float]], 

135 text: str = "", 

136 title_bar: Optional[str] = None, 

137 ) -> None: 

138 deprecation_with_replacement( 

139 "AnnotationBuilder.line", "pypdf.annotations.Line", "5.0.0" 

140 ) 

141 

142 @staticmethod 

143 def polyline( 

144 vertices: List[Tuple[float, float]], 

145 ) -> None: 

146 deprecation_with_replacement( 

147 "AnnotationBuilder.polyline", "pypdf.annotations.PolyLine", "5.0.0" 

148 ) 

149 

150 @staticmethod 

151 def rectangle( 

152 rect: Union[RectangleObject, Tuple[float, float, float, float]], 

153 interiour_color: Optional[str] = None, 

154 ) -> None: 

155 deprecation_with_replacement( 

156 "AnnotationBuilder.rectangle", "pypdf.annotations.Rectangle", "5.0.0" 

157 ) 

158 

159 @staticmethod 

160 def highlight( 

161 *, 

162 rect: Union[RectangleObject, Tuple[float, float, float, float]], 

163 quad_points: ArrayObject, 

164 highlight_color: str = "ff0000", 

165 printing: bool = False, 

166 ) -> None: 

167 deprecation_with_replacement( 

168 "AnnotationBuilder.highlight", "pypdf.annotations.Highlight", "5.0.0" 

169 ) 

170 

171 @staticmethod 

172 def ellipse( 

173 rect: Union[RectangleObject, Tuple[float, float, float, float]], 

174 interiour_color: Optional[str] = None, 

175 ) -> None: 

176 deprecation_with_replacement( 

177 "AnnotationBuilder.ellipse", "pypdf.annotations.Ellipse", "5.0.0" 

178 ) 

179 

180 @staticmethod 

181 def polygon(vertices: List[Tuple[float, float]]) -> None: 

182 deprecation_with_replacement( 

183 "AnnotationBuilder.polygon", "pypdf.annotations.Polygon", "5.0.0" 

184 ) 

185 

186 from ._fit import DEFAULT_FIT # noqa: PLC0415 

187 

188 @staticmethod 

189 def link( 

190 rect: Union[RectangleObject, Tuple[float, float, float, float]], 

191 border: Optional[ArrayObject] = None, 

192 url: Optional[str] = None, 

193 target_page_index: Optional[int] = None, 

194 fit: Fit = DEFAULT_FIT, 

195 ) -> None: 

196 deprecation_with_replacement( 

197 "AnnotationBuilder.link", "pypdf.annotations.Link", "5.0.0" 

198 ) 

199 

200 

201__all__ = [ 

202 "PAGE_FIT", 

203 "AnnotationBuilder", 

204 "ArrayObject", 

205 "BooleanObject", 

206 "ByteStringObject", 

207 "ContentStream", 

208 "DecodedStreamObject", 

209 "Destination", 

210 "DictionaryObject", 

211 "EmbeddedFile", 

212 "EncodedStreamObject", 

213 "Field", 

214 "Fit", 

215 "FloatObject", 

216 "IndirectObject", 

217 "NameObject", 

218 "NullObject", 

219 "NumberObject", 

220 "OutlineFontFlag", 

221 "OutlineItem", 

222 "PdfObject", 

223 "RectangleObject", 

224 "StreamObject", 

225 "TextStringObject", 

226 "TreeObject", 

227 "ViewerPreferences", 

228 # Utility functions 

229 "create_string_object", 

230 "decode_pdfdocencoding", 

231 "encode_pdfdocencoding", 

232 "hex_to_rgb", 

233 "is_null_or_none", 

234 "read_hex_string_from_stream", 

235 # Data structures core functions 

236 "read_object", 

237 "read_string_from_stream", 

238]