nwo
stringlengths
10
28
sha
stringlengths
40
40
path
stringlengths
11
97
identifier
stringlengths
1
64
parameters
stringlengths
2
2.24k
return_statement
stringlengths
0
2.17k
docstring
stringlengths
0
5.45k
docstring_summary
stringlengths
0
3.83k
func_begin
int64
1
13.4k
func_end
int64
2
13.4k
function
stringlengths
28
56.4k
url
stringlengths
106
209
project
int64
1
48
executed_lines
list
executed_lines_pc
float64
0
153
missing_lines
list
missing_lines_pc
float64
0
100
covered
bool
2 classes
filecoverage
float64
2.53
100
function_lines
int64
2
1.46k
mccabe
int64
1
253
coverage
float64
0
100
docstring_lines
int64
0
112
function_nodoc
stringlengths
9
56.4k
id
int64
0
29.8k
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
Transformation.scale
( self, sx: Optional[float] = None, sy: Optional[float] = None )
return Transformation(ctm)
Scale the contents of a page towards the origin of the coordinate system. Typically, that is the lower-left corner of the page. That can be changed by translating the contents / the page boxes. Args: sx: The scale factor along the x-axis. sy: The scale factor along the y-axis. Returns: A new Transformation instance with the scaled matrix.
Scale the contents of a page towards the origin of the coordinate system.
264
290
def scale( self, sx: Optional[float] = None, sy: Optional[float] = None ) -> "Transformation": """ Scale the contents of a page towards the origin of the coordinate system. Typically, that is the lower-left corner of the page. That can be changed by translating the contents / the page boxes. Args: sx: The scale factor along the x-axis. sy: The scale factor along the y-axis. Returns: A new Transformation instance with the scaled matrix. """ if sx is None and sy is None: raise ValueError("Either sx or sy must be specified") if sx is None: sx = sy if sy is None: sy = sx assert sx is not None assert sy is not None op: TransformationMatrixType = ((sx, 0, 0), (0, sy, 0), (0, 0, 1)) ctm = Transformation.compress(matrix_multiply(self.matrix, op)) return Transformation(ctm)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L264-L290
39
[ 0, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 ]
48.148148
[]
0
false
91.202346
27
7
100
11
def scale( self, sx: Optional[float] = None, sy: Optional[float] = None ) -> "Transformation": if sx is None and sy is None: raise ValueError("Either sx or sy must be specified") if sx is None: sx = sy if sy is None: sy = sx assert sx is not None assert sy is not None op: TransformationMatrixType = ((sx, 0, 0), (0, sy, 0), (0, 0, 1)) ctm = Transformation.compress(matrix_multiply(self.matrix, op)) return Transformation(ctm)
24,054
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
Transformation.rotate
(self, rotation: float)
return Transformation(ctm)
Rotate the contents of a page. Args: rotation: The angle of rotation in degrees. Returns: A new `Transformation` instance with the rotated matrix.
Rotate the contents of a page.
292
309
def rotate(self, rotation: float) -> "Transformation": """ Rotate the contents of a page. Args: rotation: The angle of rotation in degrees. Returns: A new `Transformation` instance with the rotated matrix. """ rotation = math.radians(rotation) op: TransformationMatrixType = ( (math.cos(rotation), math.sin(rotation), 0), (-math.sin(rotation), math.cos(rotation), 0), (0, 0, 1), ) ctm = Transformation.compress(matrix_multiply(self.matrix, op)) return Transformation(ctm)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L292-L309
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
100
[]
0
true
91.202346
18
1
100
7
def rotate(self, rotation: float) -> "Transformation": rotation = math.radians(rotation) op: TransformationMatrixType = ( (math.cos(rotation), math.sin(rotation), 0), (-math.sin(rotation), math.cos(rotation), 0), (0, 0, 1), ) ctm = Transformation.compress(matrix_multiply(self.matrix, op)) return Transformation(ctm)
24,055
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
Transformation.__repr__
(self)
return f"Transformation(ctm={self.ctm})"
311
312
def __repr__(self) -> str: return f"Transformation(ctm={self.ctm})"
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L311-L312
39
[]
0
[]
0
false
91.202346
2
1
100
0
def __repr__(self) -> str: return f"Transformation(ctm={self.ctm})"
24,056
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
Transformation.apply_on
( self, pt: Union[Tuple[Decimal, Decimal], Tuple[float, float], List[float]] )
return list(pt1) if isinstance(pt, list) else pt1
Apply the transformation matrix on the given point. Args: pt: A tuple or list representing the point in the form (x, y) Returns: A tuple or list representing the transformed point in the form (x', y')
Apply the transformation matrix on the given point.
314
330
def apply_on( self, pt: Union[Tuple[Decimal, Decimal], Tuple[float, float], List[float]] ) -> Union[Tuple[float, float], List[float]]: """ Apply the transformation matrix on the given point. Args: pt: A tuple or list representing the point in the form (x, y) Returns: A tuple or list representing the transformed point in the form (x', y') """ pt1 = ( float(pt[0]) * self.ctm[0] + float(pt[1]) * self.ctm[2] + self.ctm[4], float(pt[0]) * self.ctm[1] + float(pt[1]) * self.ctm[3] + self.ctm[5], ) return list(pt1) if isinstance(pt, list) else pt1
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L314-L330
39
[ 0, 11, 12, 13, 14, 15, 16 ]
41.176471
[]
0
false
91.202346
17
1
100
7
def apply_on( self, pt: Union[Tuple[Decimal, Decimal], Tuple[float, float], List[float]] ) -> Union[Tuple[float, float], List[float]]: pt1 = ( float(pt[0]) * self.ctm[0] + float(pt[1]) * self.ctm[2] + self.ctm[4], float(pt[0]) * self.ctm[1] + float(pt[1]) * self.ctm[3] + self.ctm[5], ) return list(pt1) if isinstance(pt, list) else pt1
24,057
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.__init__
( self, pdf: Optional[PdfReaderProtocol] = None, indirect_reference: Optional[IndirectObject] = None, indirect_ref: Optional[IndirectObject] = None, # deprecated )
351
371
def __init__( self, pdf: Optional[PdfReaderProtocol] = None, indirect_reference: Optional[IndirectObject] = None, indirect_ref: Optional[IndirectObject] = None, # deprecated ) -> None: DictionaryObject.__init__(self) self.pdf: Optional[PdfReaderProtocol] = pdf if indirect_ref is not None: # deprecated warnings.warn( ( "indirect_ref is deprecated and will be removed in " "pypdf 4.0.0. Use indirect_reference instead of indirect_ref." ), DeprecationWarning, ) if indirect_reference is not None: raise ValueError("Use indirect_reference instead of indirect_ref.") indirect_reference = indirect_ref self.indirect_reference = indirect_reference
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L351-L371
39
[ 6, 7, 8, 20 ]
26.666667
[]
0
false
91.202346
21
3
100
0
def __init__( self, pdf: Optional[PdfReaderProtocol] = None, indirect_reference: Optional[IndirectObject] = None, indirect_ref: Optional[IndirectObject] = None, # deprecated ) -> None: DictionaryObject.__init__(self) self.pdf: Optional[PdfReaderProtocol] = pdf if indirect_ref is not None: # deprecated warnings.warn( ( "indirect_ref is deprecated and will be removed in " "pypdf 4.0.0. Use indirect_reference instead of indirect_ref." ), DeprecationWarning, ) if indirect_reference is not None: raise ValueError("Use indirect_reference instead of indirect_ref.") indirect_reference = indirect_ref self.indirect_reference = indirect_reference
24,058
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.indirect_ref
(self)
return self.indirect_reference
374
382
def indirect_ref(self) -> Optional[IndirectObject]: # deprecated warnings.warn( ( "indirect_ref is deprecated and will be removed in pypdf 4.0.0" "Use indirect_reference instead of indirect_ref." ), DeprecationWarning, ) return self.indirect_reference
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L374-L382
39
[]
0
[]
0
false
91.202346
9
1
100
0
def indirect_ref(self) -> Optional[IndirectObject]: # deprecated warnings.warn( ( "indirect_ref is deprecated and will be removed in pypdf 4.0.0" "Use indirect_reference instead of indirect_ref." ), DeprecationWarning, ) return self.indirect_reference
24,059
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.indirect_ref
(self, value: Optional[IndirectObject])
385
386
def indirect_ref(self, value: Optional[IndirectObject]) -> None: # deprecated self.indirect_reference = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L385-L386
39
[]
0
[]
0
false
91.202346
2
1
100
0
def indirect_ref(self, value: Optional[IndirectObject]) -> None: # deprecated self.indirect_reference = value
24,060
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.hash_value_data
(self)
return data
388
391
def hash_value_data(self) -> bytes: data = super().hash_value_data() data += b"%d" % id(self) return data
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L388-L391
39
[ 0, 1, 2, 3 ]
100
[]
0
true
91.202346
4
1
100
0
def hash_value_data(self) -> bytes: data = super().hash_value_data() data += b"%d" % id(self) return data
24,061
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.user_unit
(self)
return self.get(PG.USER_UNIT, 1)
A read-only positive number giving the size of user space units. It is in multiples of 1/72 inch. Hence a value of 1 means a user space unit is 1/72 inch, and a value of 3 means that a user space unit is 3/72 inch.
A read-only positive number giving the size of user space units.
394
402
def user_unit(self) -> float: """ A read-only positive number giving the size of user space units. It is in multiples of 1/72 inch. Hence a value of 1 means a user space unit is 1/72 inch, and a value of 3 means that a user space unit is 3/72 inch. """ return self.get(PG.USER_UNIT, 1)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L394-L402
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
91.202346
9
1
100
5
def user_unit(self) -> float: return self.get(PG.USER_UNIT, 1)
24,062
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.create_blank_page
( pdf: Optional[Any] = None, # PdfReader width: Union[float, Decimal, None] = None, height: Union[float, Decimal, None] = None, )
return page
Return a new blank page. If ``width`` or ``height`` is ``None``, try to get the page size from the last page of *pdf*. Args: pdf: PDF file the page belongs to width: The width of the new page expressed in default user space units. height: The height of the new page expressed in default user space units. Returns: The new blank page Raises: PageSizeNotDefinedError: if ``pdf`` is ``None`` or contains no page
Return a new blank page.
405
447
def create_blank_page( pdf: Optional[Any] = None, # PdfReader width: Union[float, Decimal, None] = None, height: Union[float, Decimal, None] = None, ) -> "PageObject": """ Return a new blank page. If ``width`` or ``height`` is ``None``, try to get the page size from the last page of *pdf*. Args: pdf: PDF file the page belongs to width: The width of the new page expressed in default user space units. height: The height of the new page expressed in default user space units. Returns: The new blank page Raises: PageSizeNotDefinedError: if ``pdf`` is ``None`` or contains no page """ page = PageObject(pdf) # Creates a new page (cf PDF Reference 7.7.3.3) page.__setitem__(NameObject(PG.TYPE), NameObject("/Page")) page.__setitem__(NameObject(PG.PARENT), NullObject()) page.__setitem__(NameObject(PG.RESOURCES), DictionaryObject()) if width is None or height is None: if pdf is not None and len(pdf.pages) > 0: lastpage = pdf.pages[len(pdf.pages) - 1] width = lastpage.mediabox.width height = lastpage.mediabox.height else: raise PageSizeNotDefinedError page.__setitem__( NameObject(PG.MEDIABOX), RectangleObject((0, 0, width, height)) # type: ignore ) return page
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L405-L447
39
[ 0, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 ]
46.511628
[]
0
false
91.202346
43
5
100
18
def create_blank_page( pdf: Optional[Any] = None, # PdfReader width: Union[float, Decimal, None] = None, height: Union[float, Decimal, None] = None, ) -> "PageObject": page = PageObject(pdf) # Creates a new page (cf PDF Reference 7.7.3.3) page.__setitem__(NameObject(PG.TYPE), NameObject("/Page")) page.__setitem__(NameObject(PG.PARENT), NullObject()) page.__setitem__(NameObject(PG.RESOURCES), DictionaryObject()) if width is None or height is None: if pdf is not None and len(pdf.pages) > 0: lastpage = pdf.pages[len(pdf.pages) - 1] width = lastpage.mediabox.width height = lastpage.mediabox.height else: raise PageSizeNotDefinedError page.__setitem__( NameObject(PG.MEDIABOX), RectangleObject((0, 0, width, height)) # type: ignore ) return page
24,063
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.createBlankPage
( pdf: Optional[Any] = None, # PdfReader width: Union[float, Decimal, None] = None, height: Union[float, Decimal, None] = None, )
return PageObject.create_blank_page(pdf, width, height)
.. deprecated:: 1.28.0 Use :meth:`create_blank_page` instead.
.. deprecated:: 1.28.0
450
461
def createBlankPage( pdf: Optional[Any] = None, # PdfReader width: Union[float, Decimal, None] = None, height: Union[float, Decimal, None] = None, ) -> "PageObject": # deprecated """ .. deprecated:: 1.28.0 Use :meth:`create_blank_page` instead. """ deprecation_with_replacement("createBlankPage", "create_blank_page", "3.0.0") return PageObject.create_blank_page(pdf, width, height)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L450-L461
39
[]
0
[]
0
false
91.202346
12
1
100
3
def createBlankPage( pdf: Optional[Any] = None, # PdfReader width: Union[float, Decimal, None] = None, height: Union[float, Decimal, None] = None, ) -> "PageObject": # deprecated deprecation_with_replacement("createBlankPage", "create_blank_page", "3.0.0") return PageObject.create_blank_page(pdf, width, height)
24,064
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.images
(self)
return images_extracted
Get a list of all images of the page. This requires pillow. You can install it via 'pip install pypdf[image]'. For the moment, this does NOT include inline images. They will be added in future.
Get a list of all images of the page.
464
484
def images(self) -> List[File]: """ Get a list of all images of the page. This requires pillow. You can install it via 'pip install pypdf[image]'. For the moment, this does NOT include inline images. They will be added in future. """ images_extracted: List[File] = [] if RES.XOBJECT not in self[PG.RESOURCES]: # type: ignore return images_extracted x_object = self[PG.RESOURCES][RES.XOBJECT].get_object() # type: ignore for obj in x_object: if x_object[obj][IA.SUBTYPE] == "/Image": extension, byte_stream = _xobj_to_image(x_object[obj]) if extension is not None: filename = f"{obj[1:]}{extension}" images_extracted.append(File(name=filename, data=byte_stream)) return images_extracted
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L464-L484
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
100
[]
0
true
91.202346
21
5
100
6
def images(self) -> List[File]: images_extracted: List[File] = [] if RES.XOBJECT not in self[PG.RESOURCES]: # type: ignore return images_extracted x_object = self[PG.RESOURCES][RES.XOBJECT].get_object() # type: ignore for obj in x_object: if x_object[obj][IA.SUBTYPE] == "/Image": extension, byte_stream = _xobj_to_image(x_object[obj]) if extension is not None: filename = f"{obj[1:]}{extension}" images_extracted.append(File(name=filename, data=byte_stream)) return images_extracted
24,065
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.rotation
(self)
return int(self.get(PG.ROTATE, 0))
The VISUAL rotation of the page. This number has to be a multiple of 90 degrees: 0, 90, 180, or 270 are valid values. This property does not affect ``/Contents``.
The VISUAL rotation of the page.
487
495
def rotation(self) -> int: """ The VISUAL rotation of the page. This number has to be a multiple of 90 degrees: 0, 90, 180, or 270 are valid values. This property does not affect ``/Contents``. """ return int(self.get(PG.ROTATE, 0))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L487-L495
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
91.202346
9
1
100
5
def rotation(self) -> int: return int(self.get(PG.ROTATE, 0))
24,066
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.rotation
(self, r: Union[int, float])
498
499
def rotation(self, r: Union[int, float]) -> None: self[NameObject(PG.ROTATE)] = NumberObject((((int(r) + 45) // 90) * 90) % 360)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L498-L499
39
[ 0, 1 ]
100
[]
0
true
91.202346
2
1
100
0
def rotation(self, r: Union[int, float]) -> None: self[NameObject(PG.ROTATE)] = NumberObject((((int(r) + 45) // 90) * 90) % 360)
24,067
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.transfer_rotation_to_content
(self)
Apply the rotation of the page to the content and the media/crop/... boxes. It's recommended to apply this function before page merging.
Apply the rotation of the page to the content and the media/crop/... boxes.
501
533
def transfer_rotation_to_content(self) -> None: """ Apply the rotation of the page to the content and the media/crop/... boxes. It's recommended to apply this function before page merging. """ r = -self.rotation # rotation to apply is in the otherway self.rotation = 0 mb = RectangleObject(self.mediabox) trsf = ( Transformation() .translate( -float(mb.left + mb.width / 2), -float(mb.bottom + mb.height / 2) ) .rotate(r) ) pt1 = trsf.apply_on(mb.lower_left) pt2 = trsf.apply_on(mb.upper_right) trsf = trsf.translate(-min(pt1[0], pt2[0]), -min(pt1[1], pt2[1])) self.add_transformation(trsf, False) for b in ["/MediaBox", "/CropBox", "/BleedBox", "/TrimBox", "/ArtBox"]: if b in self: rr = RectangleObject(self[b]) # type: ignore pt1 = trsf.apply_on(rr.lower_left) pt2 = trsf.apply_on(rr.upper_right) self[NameObject(b)] = RectangleObject( ( min(pt1[0], pt2[0]), min(pt1[1], pt2[1]), max(pt1[0], pt2[0]), max(pt1[1], pt2[1]), ) )
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L501-L533
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 ]
100
[]
0
true
91.202346
33
3
100
3
def transfer_rotation_to_content(self) -> None: r = -self.rotation # rotation to apply is in the otherway self.rotation = 0 mb = RectangleObject(self.mediabox) trsf = ( Transformation() .translate( -float(mb.left + mb.width / 2), -float(mb.bottom + mb.height / 2) ) .rotate(r) ) pt1 = trsf.apply_on(mb.lower_left) pt2 = trsf.apply_on(mb.upper_right) trsf = trsf.translate(-min(pt1[0], pt2[0]), -min(pt1[1], pt2[1])) self.add_transformation(trsf, False) for b in ["/MediaBox", "/CropBox", "/BleedBox", "/TrimBox", "/ArtBox"]: if b in self: rr = RectangleObject(self[b]) # type: ignore pt1 = trsf.apply_on(rr.lower_left) pt2 = trsf.apply_on(rr.upper_right) self[NameObject(b)] = RectangleObject( ( min(pt1[0], pt2[0]), min(pt1[1], pt2[1]), max(pt1[0], pt2[0]), max(pt1[1], pt2[1]), ) )
24,068
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.rotate
(self, angle: int)
return self
Rotate a page clockwise by increments of 90 degrees. Args: angle: Angle to rotate the page. Must be an increment of 90 deg.
Rotate a page clockwise by increments of 90 degrees.
535
549
def rotate(self, angle: int) -> "PageObject": """ Rotate a page clockwise by increments of 90 degrees. Args: angle: Angle to rotate the page. Must be an increment of 90 deg. """ if angle % 90 != 0: raise ValueError("Rotation angle must be a multiple of 90") rotate_obj = self.get(PG.ROTATE, 0) current_angle = ( rotate_obj if isinstance(rotate_obj, int) else rotate_obj.get_object() ) self[NameObject(PG.ROTATE)] = NumberObject(current_angle + angle) return self
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L535-L549
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
100
[]
0
true
91.202346
15
2
100
4
def rotate(self, angle: int) -> "PageObject": if angle % 90 != 0: raise ValueError("Rotation angle must be a multiple of 90") rotate_obj = self.get(PG.ROTATE, 0) current_angle = ( rotate_obj if isinstance(rotate_obj, int) else rotate_obj.get_object() ) self[NameObject(PG.ROTATE)] = NumberObject(current_angle + angle) return self
24,069
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.rotate_clockwise
(self, angle: int)
return self.rotate(angle)
551
553
def rotate_clockwise(self, angle: int) -> "PageObject": # deprecated deprecation_with_replacement("rotate_clockwise", "rotate", "3.0.0") return self.rotate(angle)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L551-L553
39
[]
0
[]
0
false
91.202346
3
1
100
0
def rotate_clockwise(self, angle: int) -> "PageObject": # deprecated deprecation_with_replacement("rotate_clockwise", "rotate", "3.0.0") return self.rotate(angle)
24,070
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.rotateClockwise
(self, angle: int)
return self.rotate(angle)
.. deprecated:: 1.28.0 Use :meth:`rotate_clockwise` instead.
.. deprecated:: 1.28.0
555
562
def rotateClockwise(self, angle: int) -> "PageObject": # deprecated """ .. deprecated:: 1.28.0 Use :meth:`rotate_clockwise` instead. """ deprecation_with_replacement("rotateClockwise", "rotate", "3.0.0") return self.rotate(angle)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L555-L562
39
[]
0
[]
0
false
91.202346
8
1
100
3
def rotateClockwise(self, angle: int) -> "PageObject": # deprecated deprecation_with_replacement("rotateClockwise", "rotate", "3.0.0") return self.rotate(angle)
24,071
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.rotateCounterClockwise
(self, angle: int)
return self.rotate(-angle)
.. deprecated:: 1.28.0 Use :meth:`rotate_clockwise` with a negative argument instead.
.. deprecated:: 1.28.0
564
571
def rotateCounterClockwise(self, angle: int) -> "PageObject": # deprecated """ .. deprecated:: 1.28.0 Use :meth:`rotate_clockwise` with a negative argument instead. """ deprecation_with_replacement("rotateCounterClockwise", "rotate", "3.0.0") return self.rotate(-angle)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L564-L571
39
[]
0
[]
0
false
91.202346
8
1
100
3
def rotateCounterClockwise(self, angle: int) -> "PageObject": # deprecated deprecation_with_replacement("rotateCounterClockwise", "rotate", "3.0.0") return self.rotate(-angle)
24,072
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject._merge_resources
( res1: DictionaryObject, res2: DictionaryObject, resource: Any )
return new_res, rename_res
574
590
def _merge_resources( res1: DictionaryObject, res2: DictionaryObject, resource: Any ) -> Tuple[Dict[str, Any], Dict[str, Any]]: new_res = DictionaryObject() new_res.update(res1.get(resource, DictionaryObject()).get_object()) page2res = cast( DictionaryObject, res2.get(resource, DictionaryObject()).get_object() ) rename_res = {} for key in list(page2res.keys()): if key in new_res and new_res.raw_get(key) != page2res.raw_get(key): newname = NameObject(key + str(uuid.uuid4())) rename_res[key] = newname new_res[newname] = page2res[key] elif key not in new_res: new_res[key] = page2res.raw_get(key) return new_res, rename_res
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L574-L590
39
[ 0, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
76.470588
[]
0
false
91.202346
17
5
100
0
def _merge_resources( res1: DictionaryObject, res2: DictionaryObject, resource: Any ) -> Tuple[Dict[str, Any], Dict[str, Any]]: new_res = DictionaryObject() new_res.update(res1.get(resource, DictionaryObject()).get_object()) page2res = cast( DictionaryObject, res2.get(resource, DictionaryObject()).get_object() ) rename_res = {} for key in list(page2res.keys()): if key in new_res and new_res.raw_get(key) != page2res.raw_get(key): newname = NameObject(key + str(uuid.uuid4())) rename_res[key] = newname new_res[newname] = page2res[key] elif key not in new_res: new_res[key] = page2res.raw_get(key) return new_res, rename_res
24,073
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject._content_stream_rename
( stream: ContentStream, rename: Dict[Any, Any], pdf: Any # PdfReader )
return stream
593
612
def _content_stream_rename( stream: ContentStream, rename: Dict[Any, Any], pdf: Any # PdfReader ) -> ContentStream: if not rename: return stream stream = ContentStream(stream, pdf) for operands, _operator in stream.operations: if isinstance(operands, list): for i in range(len(operands)): op = operands[i] if isinstance(op, NameObject): operands[i] = rename.get(op, op) elif isinstance(operands, dict): for i in operands: op = operands[i] if isinstance(op, NameObject): operands[i] = rename.get(op, op) else: raise KeyError(f"type of operands is {type(operands)}") return stream
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L593-L612
39
[ 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 19 ]
55
[ 12, 13, 14, 15, 16, 18 ]
30
false
91.202346
20
9
70
0
def _content_stream_rename( stream: ContentStream, rename: Dict[Any, Any], pdf: Any # PdfReader ) -> ContentStream: if not rename: return stream stream = ContentStream(stream, pdf) for operands, _operator in stream.operations: if isinstance(operands, list): for i in range(len(operands)): op = operands[i] if isinstance(op, NameObject): operands[i] = rename.get(op, op) elif isinstance(operands, dict): for i in operands: op = operands[i] if isinstance(op, NameObject): operands[i] = rename.get(op, op) else: raise KeyError(f"type of operands is {type(operands)}") return stream
24,074
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject._push_pop_gs
(contents: Any, pdf: Any)
return stream
615
622
def _push_pop_gs(contents: Any, pdf: Any) -> ContentStream: # PdfReader # adds a graphics state "push" and "pop" to the beginning and end # of a content stream. This isolates it from changes such as # transformation matricies. stream = ContentStream(contents, pdf) stream.operations.insert(0, ([], "q")) stream.operations.append(([], "Q")) return stream
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L615-L622
39
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
91.202346
8
1
100
0
def _push_pop_gs(contents: Any, pdf: Any) -> ContentStream: # PdfReader # adds a graphics state "push" and "pop" to the beginning and end # of a content stream. This isolates it from changes such as # transformation matricies. stream = ContentStream(contents, pdf) stream.operations.insert(0, ([], "q")) stream.operations.append(([], "Q")) return stream
24,075
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject._add_transformation_matrix
( contents: Any, pdf: Any, ctm: CompressedTransformationMatrix )
return contents
625
646
def _add_transformation_matrix( contents: Any, pdf: Any, ctm: CompressedTransformationMatrix ) -> ContentStream: # PdfReader # adds transformation matrix at the beginning of the given # contents stream. a, b, c, d, e, f = ctm contents = ContentStream(contents, pdf) contents.operations.insert( 0, [ [ FloatObject(a), FloatObject(b), FloatObject(c), FloatObject(d), FloatObject(e), FloatObject(f), ], " cm", ], ) return contents
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L625-L646
39
[ 0, 4, 5, 6, 7, 21 ]
27.272727
[]
0
false
91.202346
22
1
100
0
def _add_transformation_matrix( contents: Any, pdf: Any, ctm: CompressedTransformationMatrix ) -> ContentStream: # PdfReader # adds transformation matrix at the beginning of the given # contents stream. a, b, c, d, e, f = ctm contents = ContentStream(contents, pdf) contents.operations.insert( 0, [ [ FloatObject(a), FloatObject(b), FloatObject(c), FloatObject(d), FloatObject(e), FloatObject(f), ], " cm", ], ) return contents
24,076
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.get_contents
(self)
Access the page contents. Returns: The ``/Contents`` object, or ``None`` if it doesn't exist. ``/Contents`` is optional, as described in PDF Reference 7.7.3.3
Access the page contents.
648
659
def get_contents(self) -> Optional[ContentStream]: """ Access the page contents. Returns: The ``/Contents`` object, or ``None`` if it doesn't exist. ``/Contents`` is optional, as described in PDF Reference 7.7.3.3 """ if PG.CONTENTS in self: return self[PG.CONTENTS].get_object() # type: ignore else: return None
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L648-L659
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
91.202346
12
2
100
5
def get_contents(self) -> Optional[ContentStream]: if PG.CONTENTS in self: return self[PG.CONTENTS].get_object() # type: ignore else: return None
24,077
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.getContents
(self)
return self.get_contents()
.. deprecated:: 1.28.0 Use :meth:`get_contents` instead.
.. deprecated:: 1.28.0
661
668
def getContents(self) -> Optional[ContentStream]: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`get_contents` instead. """ deprecation_with_replacement("getContents", "get_contents", "3.0.0") return self.get_contents()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L661-L668
39
[]
0
[]
0
false
91.202346
8
1
100
3
def getContents(self) -> Optional[ContentStream]: # deprecated deprecation_with_replacement("getContents", "get_contents", "3.0.0") return self.get_contents()
24,078
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.merge_page
(self, page2: "PageObject", expand: bool = False)
Merge the content streams of two pages into one. Resource references (i.e. fonts) are maintained from both pages. The mediabox/cropbox/etc of this page are not altered. The parameter page's content stream will be added to the end of this page's content stream, meaning that it will be drawn after, or "on top" of this page. Args: page2: The page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. expand: If true, the current page dimensions will be expanded to accommodate the dimensions of the page to be merged.
Merge the content streams of two pages into one.
670
686
def merge_page(self, page2: "PageObject", expand: bool = False) -> None: """ Merge the content streams of two pages into one. Resource references (i.e. fonts) are maintained from both pages. The mediabox/cropbox/etc of this page are not altered. The parameter page's content stream will be added to the end of this page's content stream, meaning that it will be drawn after, or "on top" of this page. Args: page2: The page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. expand: If true, the current page dimensions will be expanded to accommodate the dimensions of the page to be merged. """ self._merge_page(page2, expand=expand)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L670-L686
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
91.202346
17
1
100
13
def merge_page(self, page2: "PageObject", expand: bool = False) -> None: self._merge_page(page2, expand=expand)
24,079
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mergePage
(self, page2: "PageObject")
return self.merge_page(page2)
.. deprecated:: 1.28.0 Use :meth:`merge_page` instead.
.. deprecated:: 1.28.0
688
695
def mergePage(self, page2: "PageObject") -> None: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`merge_page` instead. """ deprecation_with_replacement("mergePage", "merge_page", "3.0.0") return self.merge_page(page2)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L688-L695
39
[]
0
[]
0
false
91.202346
8
1
100
3
def mergePage(self, page2: "PageObject") -> None: # deprecated deprecation_with_replacement("mergePage", "merge_page", "3.0.0") return self.merge_page(page2)
24,080
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject._merge_page
( self, page2: "PageObject", page2transformation: Optional[Callable[[Any], ContentStream]] = None, ctm: Optional[CompressedTransformationMatrix] = None, expand: bool = False, )
697
795
def _merge_page( self, page2: "PageObject", page2transformation: Optional[Callable[[Any], ContentStream]] = None, ctm: Optional[CompressedTransformationMatrix] = None, expand: bool = False, ) -> None: # First we work on merging the resource dictionaries. This allows us # to find out what symbols in the content streams we might need to # rename. new_resources = DictionaryObject() rename = {} try: original_resources = cast(DictionaryObject, self[PG.RESOURCES].get_object()) except KeyError: original_resources = DictionaryObject() try: page2resources = cast(DictionaryObject, page2[PG.RESOURCES].get_object()) except KeyError: page2resources = DictionaryObject() new_annots = ArrayObject() for page in (self, page2): if PG.ANNOTS in page: annots = page[PG.ANNOTS] if isinstance(annots, ArrayObject): for ref in annots: new_annots.append(ref) for res in ( RES.EXT_G_STATE, RES.FONT, RES.XOBJECT, RES.COLOR_SPACE, RES.PATTERN, RES.SHADING, RES.PROPERTIES, ): new, newrename = PageObject._merge_resources( original_resources, page2resources, res ) if new: new_resources[NameObject(res)] = new rename.update(newrename) # Combine /ProcSet sets. new_resources[NameObject(RES.PROC_SET)] = ArrayObject( frozenset( original_resources.get(RES.PROC_SET, ArrayObject()).get_object() ).union( frozenset(page2resources.get(RES.PROC_SET, ArrayObject()).get_object()) ) ) new_content_array = ArrayObject() original_content = self.get_contents() if original_content is not None: new_content_array.append( PageObject._push_pop_gs(original_content, self.pdf) ) page2content = page2.get_contents() if page2content is not None: page2content = ContentStream(page2content, self.pdf) rect = page2.trimbox page2content.operations.insert( 0, ( map( FloatObject, [ rect.left, rect.bottom, rect.width, rect.height, ], ), "re", ), ) page2content.operations.insert(1, ([], "W")) page2content.operations.insert(2, ([], "n")) if page2transformation is not None: page2content = page2transformation(page2content) page2content = PageObject._content_stream_rename( page2content, rename, self.pdf ) page2content = PageObject._push_pop_gs(page2content, self.pdf) new_content_array.append(page2content) # if expanding the page to fit a new page, calculate the new media box size if expand: self._expand_mediabox(page2, ctm) self[NameObject(PG.CONTENTS)] = ContentStream(new_content_array, self.pdf) self[NameObject(PG.RESOURCES)] = new_resources self[NameObject(PG.ANNOTS)] = new_annots
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L697-L795
39
[ 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 39, 42, 43, 44, 45, 46, 47, 54, 55, 56, 57, 58, 59, 62, 63, 64, 65, 66, 67, 82, 83, 84, 86, 89, 90, 91, 92, 93, 95, 96, 97, 98 ]
54.545455
[ 85, 94 ]
2.020202
false
91.202346
99
13
97.979798
0
def _merge_page( self, page2: "PageObject", page2transformation: Optional[Callable[[Any], ContentStream]] = None, ctm: Optional[CompressedTransformationMatrix] = None, expand: bool = False, ) -> None: # First we work on merging the resource dictionaries. This allows us # to find out what symbols in the content streams we might need to # rename. new_resources = DictionaryObject() rename = {} try: original_resources = cast(DictionaryObject, self[PG.RESOURCES].get_object()) except KeyError: original_resources = DictionaryObject() try: page2resources = cast(DictionaryObject, page2[PG.RESOURCES].get_object()) except KeyError: page2resources = DictionaryObject() new_annots = ArrayObject() for page in (self, page2): if PG.ANNOTS in page: annots = page[PG.ANNOTS] if isinstance(annots, ArrayObject): for ref in annots: new_annots.append(ref) for res in ( RES.EXT_G_STATE, RES.FONT, RES.XOBJECT, RES.COLOR_SPACE, RES.PATTERN, RES.SHADING, RES.PROPERTIES, ): new, newrename = PageObject._merge_resources( original_resources, page2resources, res ) if new: new_resources[NameObject(res)] = new rename.update(newrename) # Combine /ProcSet sets. new_resources[NameObject(RES.PROC_SET)] = ArrayObject( frozenset( original_resources.get(RES.PROC_SET, ArrayObject()).get_object() ).union( frozenset(page2resources.get(RES.PROC_SET, ArrayObject()).get_object()) ) ) new_content_array = ArrayObject() original_content = self.get_contents() if original_content is not None: new_content_array.append( PageObject._push_pop_gs(original_content, self.pdf) ) page2content = page2.get_contents() if page2content is not None: page2content = ContentStream(page2content, self.pdf) rect = page2.trimbox page2content.operations.insert( 0, ( map( FloatObject, [ rect.left, rect.bottom, rect.width, rect.height, ], ), "re", ), ) page2content.operations.insert(1, ([], "W")) page2content.operations.insert(2, ([], "n")) if page2transformation is not None: page2content = page2transformation(page2content) page2content = PageObject._content_stream_rename( page2content, rename, self.pdf ) page2content = PageObject._push_pop_gs(page2content, self.pdf) new_content_array.append(page2content) # if expanding the page to fit a new page, calculate the new media box size if expand: self._expand_mediabox(page2, ctm) self[NameObject(PG.CONTENTS)] = ContentStream(new_content_array, self.pdf) self[NameObject(PG.RESOURCES)] = new_resources self[NameObject(PG.ANNOTS)] = new_annots
24,081
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject._expand_mediabox
( self, page2: "PageObject", ctm: Optional[CompressedTransformationMatrix] )
797
838
def _expand_mediabox( self, page2: "PageObject", ctm: Optional[CompressedTransformationMatrix] ) -> None: corners1 = ( self.mediabox.left.as_numeric(), self.mediabox.bottom.as_numeric(), self.mediabox.right.as_numeric(), self.mediabox.top.as_numeric(), ) corners2 = ( page2.mediabox.left.as_numeric(), page2.mediabox.bottom.as_numeric(), page2.mediabox.left.as_numeric(), page2.mediabox.top.as_numeric(), page2.mediabox.right.as_numeric(), page2.mediabox.top.as_numeric(), page2.mediabox.right.as_numeric(), page2.mediabox.bottom.as_numeric(), ) if ctm is not None: ctm = tuple(float(x) for x in ctm) # type: ignore[assignment] new_x = tuple( ctm[0] * corners2[i] + ctm[2] * corners2[i + 1] + ctm[4] for i in range(0, 8, 2) ) new_y = tuple( ctm[1] * corners2[i] + ctm[3] * corners2[i + 1] + ctm[5] for i in range(0, 8, 2) ) else: new_x = corners2[0:8:2] new_y = corners2[1:8:2] lowerleft = (min(new_x), min(new_y)) upperright = (max(new_x), max(new_y)) lowerleft = (min(corners1[0], lowerleft[0]), min(corners1[1], lowerleft[1])) upperright = ( max(corners1[2], upperright[0]), max(corners1[3], upperright[1]), ) self.mediabox.lower_left = lowerleft self.mediabox.upper_right = upperright
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L797-L838
39
[ 0 ]
2.380952
[ 3, 9, 19, 20, 21, 25, 30, 31, 32, 33, 34, 35, 40, 41 ]
33.333333
false
91.202346
42
2
66.666667
0
def _expand_mediabox( self, page2: "PageObject", ctm: Optional[CompressedTransformationMatrix] ) -> None: corners1 = ( self.mediabox.left.as_numeric(), self.mediabox.bottom.as_numeric(), self.mediabox.right.as_numeric(), self.mediabox.top.as_numeric(), ) corners2 = ( page2.mediabox.left.as_numeric(), page2.mediabox.bottom.as_numeric(), page2.mediabox.left.as_numeric(), page2.mediabox.top.as_numeric(), page2.mediabox.right.as_numeric(), page2.mediabox.top.as_numeric(), page2.mediabox.right.as_numeric(), page2.mediabox.bottom.as_numeric(), ) if ctm is not None: ctm = tuple(float(x) for x in ctm) # type: ignore[assignment] new_x = tuple( ctm[0] * corners2[i] + ctm[2] * corners2[i + 1] + ctm[4] for i in range(0, 8, 2) ) new_y = tuple( ctm[1] * corners2[i] + ctm[3] * corners2[i + 1] + ctm[5] for i in range(0, 8, 2) ) else: new_x = corners2[0:8:2] new_y = corners2[1:8:2] lowerleft = (min(new_x), min(new_y)) upperright = (max(new_x), max(new_y)) lowerleft = (min(corners1[0], lowerleft[0]), min(corners1[1], lowerleft[1])) upperright = ( max(corners1[2], upperright[0]), max(corners1[3], upperright[1]), ) self.mediabox.lower_left = lowerleft self.mediabox.upper_right = upperright
24,082
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mergeTransformedPage
( self, page2: "PageObject", ctm: Union[CompressedTransformationMatrix, Transformation], expand: bool = False, )
mergeTransformedPage is similar to merge_page, but a transformation matrix is applied to the merged stream. :param PageObject page2: The page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param tuple ctm: a 6-element tuple containing the operands of the transformation matrix :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead.
mergeTransformedPage is similar to merge_page, but a transformation matrix is applied to the merged stream.
840
876
def mergeTransformedPage( self, page2: "PageObject", ctm: Union[CompressedTransformationMatrix, Transformation], expand: bool = False, ) -> None: # deprecated """ mergeTransformedPage is similar to merge_page, but a transformation matrix is applied to the merged stream. :param PageObject page2: The page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param tuple ctm: a 6-element tuple containing the operands of the transformation matrix :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead. """ deprecation_with_replacement( "page.mergeTransformedPage(page2, ctm)", "page2.add_transformation(ctm); page.merge_page(page2)", "3.0.0", ) if isinstance(ctm, Transformation): ctm = ctm.ctm ctm = cast(CompressedTransformationMatrix, ctm) self._merge_page( page2, lambda page2Content: PageObject._add_transformation_matrix( page2Content, page2.pdf, ctm # type: ignore[arg-type] ), ctm, expand, )
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L840-L876
39
[]
0
[]
0
false
91.202346
37
2
100
13
def mergeTransformedPage( self, page2: "PageObject", ctm: Union[CompressedTransformationMatrix, Transformation], expand: bool = False, ) -> None: # deprecated deprecation_with_replacement( "page.mergeTransformedPage(page2, ctm)", "page2.add_transformation(ctm); page.merge_page(page2)", "3.0.0", ) if isinstance(ctm, Transformation): ctm = ctm.ctm ctm = cast(CompressedTransformationMatrix, ctm) self._merge_page( page2, lambda page2Content: PageObject._add_transformation_matrix( page2Content, page2.pdf, ctm # type: ignore[arg-type] ), ctm, expand, )
24,083
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mergeScaledPage
( self, page2: "PageObject", scale: float, expand: bool = False )
mergeScaledPage is similar to merge_page, but the stream to be merged is scaled by applying a transformation matrix. :param PageObject page2: The page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float scale: The scaling factor :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead.
mergeScaledPage is similar to merge_page, but the stream to be merged is scaled by applying a transformation matrix.
878
901
def mergeScaledPage( self, page2: "PageObject", scale: float, expand: bool = False ) -> None: # deprecated """ mergeScaledPage is similar to merge_page, but the stream to be merged is scaled by applying a transformation matrix. :param PageObject page2: The page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float scale: The scaling factor :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead. """ deprecation_with_replacement( "page.mergeScaledPage(page2, scale, expand)", "page2.add_transformation(Transformation().scale(scale)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().scale(scale, scale) self.mergeTransformedPage(page2, op, expand)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L878-L901
39
[]
0
[]
0
false
91.202346
24
1
100
12
def mergeScaledPage( self, page2: "PageObject", scale: float, expand: bool = False ) -> None: # deprecated deprecation_with_replacement( "page.mergeScaledPage(page2, scale, expand)", "page2.add_transformation(Transformation().scale(scale)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().scale(scale, scale) self.mergeTransformedPage(page2, op, expand)
24,084
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mergeRotatedPage
( self, page2: "PageObject", rotation: float, expand: bool = False )
mergeRotatedPage is similar to merge_page, but the stream to be merged is rotated by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float rotation: The angle of the rotation, in degrees :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead.
mergeRotatedPage is similar to merge_page, but the stream to be merged is rotated by applying a transformation matrix.
903
926
def mergeRotatedPage( self, page2: "PageObject", rotation: float, expand: bool = False ) -> None: # deprecated """ mergeRotatedPage is similar to merge_page, but the stream to be merged is rotated by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float rotation: The angle of the rotation, in degrees :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead. """ deprecation_with_replacement( "page.mergeRotatedPage(page2, rotation, expand)", "page2.add_transformation(Transformation().rotate(rotation)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().rotate(rotation) self.mergeTransformedPage(page2, op, expand)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L903-L926
39
[]
0
[]
0
false
91.202346
24
1
100
12
def mergeRotatedPage( self, page2: "PageObject", rotation: float, expand: bool = False ) -> None: # deprecated deprecation_with_replacement( "page.mergeRotatedPage(page2, rotation, expand)", "page2.add_transformation(Transformation().rotate(rotation)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().rotate(rotation) self.mergeTransformedPage(page2, op, expand)
24,085
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mergeTranslatedPage
( self, page2: "PageObject", tx: float, ty: float, expand: bool = False )
mergeTranslatedPage is similar to merge_page, but the stream to be merged is translated by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float tx: The translation on X axis :param float ty: The translation on Y axis :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead.
mergeTranslatedPage is similar to merge_page, but the stream to be merged is translated by applying a transformation matrix.
928
952
def mergeTranslatedPage( self, page2: "PageObject", tx: float, ty: float, expand: bool = False ) -> None: # deprecated """ mergeTranslatedPage is similar to merge_page, but the stream to be merged is translated by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float tx: The translation on X axis :param float ty: The translation on Y axis :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead. """ deprecation_with_replacement( "page.mergeTranslatedPage(page2, tx, ty, expand)", "page2.add_transformation(Transformation().translate(tx, ty)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().translate(tx, ty) self.mergeTransformedPage(page2, op, expand)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L928-L952
39
[]
0
[]
0
false
91.202346
25
1
100
13
def mergeTranslatedPage( self, page2: "PageObject", tx: float, ty: float, expand: bool = False ) -> None: # deprecated deprecation_with_replacement( "page.mergeTranslatedPage(page2, tx, ty, expand)", "page2.add_transformation(Transformation().translate(tx, ty)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().translate(tx, ty) self.mergeTransformedPage(page2, op, expand)
24,086
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mergeRotatedTranslatedPage
( self, page2: "PageObject", rotation: float, tx: float, ty: float, expand: bool = False, )
return self.mergeTransformedPage(page2, op, expand)
mergeRotatedTranslatedPage is similar to merge_page, but the stream to be merged is rotated and translated by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float tx: The translation on X axis :param float ty: The translation on Y axis :param float rotation: The angle of the rotation, in degrees :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead.
mergeRotatedTranslatedPage is similar to merge_page, but the stream to be merged is rotated and translated by applying a transformation matrix.
954
984
def mergeRotatedTranslatedPage( self, page2: "PageObject", rotation: float, tx: float, ty: float, expand: bool = False, ) -> None: # deprecated """ mergeRotatedTranslatedPage is similar to merge_page, but the stream to be merged is rotated and translated by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float tx: The translation on X axis :param float ty: The translation on Y axis :param float rotation: The angle of the rotation, in degrees :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead. """ deprecation_with_replacement( "page.mergeRotatedTranslatedPage(page2, rotation, tx, ty, expand)", "page2.add_transformation(Transformation().rotate(rotation).translate(tx, ty)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().translate(-tx, -ty).rotate(rotation).translate(tx, ty) return self.mergeTransformedPage(page2, op, expand)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L954-L984
39
[]
0
[]
0
false
91.202346
31
1
100
14
def mergeRotatedTranslatedPage( self, page2: "PageObject", rotation: float, tx: float, ty: float, expand: bool = False, ) -> None: # deprecated deprecation_with_replacement( "page.mergeRotatedTranslatedPage(page2, rotation, tx, ty, expand)", "page2.add_transformation(Transformation().rotate(rotation).translate(tx, ty)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().translate(-tx, -ty).rotate(rotation).translate(tx, ty) return self.mergeTransformedPage(page2, op, expand)
24,087
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mergeRotatedScaledPage
( self, page2: "PageObject", rotation: float, scale: float, expand: bool = False )
mergeRotatedScaledPage is similar to merge_page, but the stream to be merged is rotated and scaled by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float rotation: The angle of the rotation, in degrees :param float scale: The scaling factor :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead.
mergeRotatedScaledPage is similar to merge_page, but the stream to be merged is rotated and scaled by applying a transformation matrix.
986
1,010
def mergeRotatedScaledPage( self, page2: "PageObject", rotation: float, scale: float, expand: bool = False ) -> None: # deprecated """ mergeRotatedScaledPage is similar to merge_page, but the stream to be merged is rotated and scaled by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float rotation: The angle of the rotation, in degrees :param float scale: The scaling factor :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead. """ deprecation_with_replacement( "page.mergeRotatedScaledPage(page2, rotation, scale, expand)", "page2.add_transformation(Transformation().rotate(rotation).scale(scale)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().rotate(rotation).scale(scale, scale) self.mergeTransformedPage(page2, op, expand)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L986-L1010
39
[]
0
[]
0
false
91.202346
25
1
100
13
def mergeRotatedScaledPage( self, page2: "PageObject", rotation: float, scale: float, expand: bool = False ) -> None: # deprecated deprecation_with_replacement( "page.mergeRotatedScaledPage(page2, rotation, scale, expand)", "page2.add_transformation(Transformation().rotate(rotation).scale(scale)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().rotate(rotation).scale(scale, scale) self.mergeTransformedPage(page2, op, expand)
24,088
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mergeScaledTranslatedPage
( self, page2: "PageObject", scale: float, tx: float, ty: float, expand: bool = False, )
return self.mergeTransformedPage(page2, op, expand)
mergeScaledTranslatedPage is similar to merge_page, but the stream to be merged is translated and scaled by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float scale: The scaling factor :param float tx: The translation on X axis :param float ty: The translation on Y axis :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead.
mergeScaledTranslatedPage is similar to merge_page, but the stream to be merged is translated and scaled by applying a transformation matrix.
1,012
1,042
def mergeScaledTranslatedPage( self, page2: "PageObject", scale: float, tx: float, ty: float, expand: bool = False, ) -> None: # deprecated """ mergeScaledTranslatedPage is similar to merge_page, but the stream to be merged is translated and scaled by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float scale: The scaling factor :param float tx: The translation on X axis :param float ty: The translation on Y axis :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead. """ deprecation_with_replacement( "page.mergeScaledTranslatedPage(page2, scale, tx, ty, expand)", "page2.add_transformation(Transformation().scale(scale).translate(tx, ty)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().scale(scale, scale).translate(tx, ty) return self.mergeTransformedPage(page2, op, expand)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1012-L1042
39
[]
0
[]
0
false
91.202346
31
1
100
14
def mergeScaledTranslatedPage( self, page2: "PageObject", scale: float, tx: float, ty: float, expand: bool = False, ) -> None: # deprecated deprecation_with_replacement( "page.mergeScaledTranslatedPage(page2, scale, tx, ty, expand)", "page2.add_transformation(Transformation().scale(scale).translate(tx, ty)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().scale(scale, scale).translate(tx, ty) return self.mergeTransformedPage(page2, op, expand)
24,089
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mergeRotatedScaledTranslatedPage
( self, page2: "PageObject", rotation: float, scale: float, tx: float, ty: float, expand: bool = False, )
mergeRotatedScaledTranslatedPage is similar to merge_page, but the stream to be merged is translated, rotated and scaled by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float tx: The translation on X axis :param float ty: The translation on Y axis :param float rotation: The angle of the rotation, in degrees :param float scale: The scaling factor :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead.
mergeRotatedScaledTranslatedPage is similar to merge_page, but the stream to be merged is translated, rotated and scaled by applying a transformation matrix.
1,044
1,077
def mergeRotatedScaledTranslatedPage( self, page2: "PageObject", rotation: float, scale: float, tx: float, ty: float, expand: bool = False, ) -> None: # deprecated """ mergeRotatedScaledTranslatedPage is similar to merge_page, but the stream to be merged is translated, rotated and scaled by applying a transformation matrix. :param PageObject page2: the page to be merged into this one. Should be an instance of :class:`PageObject<PageObject>`. :param float tx: The translation on X axis :param float ty: The translation on Y axis :param float rotation: The angle of the rotation, in degrees :param float scale: The scaling factor :param bool expand: Whether the page should be expanded to fit the dimensions of the page to be merged. .. deprecated:: 1.28.0 Use :meth:`add_transformation` and :meth:`merge_page` instead. """ deprecation_with_replacement( "page.mergeRotatedScaledTranslatedPage(page2, rotation, tx, ty, expand)", "page2.add_transformation(Transformation().rotate(rotation).scale(scale)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().rotate(rotation).scale(scale, scale).translate(tx, ty) self.mergeTransformedPage(page2, op, expand)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1044-L1077
39
[]
0
[]
0
false
91.202346
34
1
100
16
def mergeRotatedScaledTranslatedPage( self, page2: "PageObject", rotation: float, scale: float, tx: float, ty: float, expand: bool = False, ) -> None: # deprecated deprecation_with_replacement( "page.mergeRotatedScaledTranslatedPage(page2, rotation, tx, ty, expand)", "page2.add_transformation(Transformation().rotate(rotation).scale(scale)); page.merge_page(page2, expand)", "3.0.0", ) op = Transformation().rotate(rotation).scale(scale, scale).translate(tx, ty) self.mergeTransformedPage(page2, op, expand)
24,090
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.add_transformation
( self, ctm: Union[Transformation, CompressedTransformationMatrix], expand: bool = False, )
Apply a transformation matrix to the page. Args: ctm: A 6-element tuple containing the operands of the transformation matrix. Alternatively, a :py:class:`Transformation<pypdf.Transformation>` object can be passed. See :doc:`/user/cropping-and-transforming`.
Apply a transformation matrix to the page.
1,079
1,134
def add_transformation( self, ctm: Union[Transformation, CompressedTransformationMatrix], expand: bool = False, ) -> None: """ Apply a transformation matrix to the page. Args: ctm: A 6-element tuple containing the operands of the transformation matrix. Alternatively, a :py:class:`Transformation<pypdf.Transformation>` object can be passed. See :doc:`/user/cropping-and-transforming`. """ if isinstance(ctm, Transformation): ctm = ctm.ctm content = self.get_contents() if content is not None: content = PageObject._add_transformation_matrix(content, self.pdf, ctm) content = PageObject._push_pop_gs(content, self.pdf) self[NameObject(PG.CONTENTS)] = content # if expanding the page to fit a new page, calculate the new media box size if expand: corners = [ self.mediabox.left.as_numeric(), self.mediabox.bottom.as_numeric(), self.mediabox.left.as_numeric(), self.mediabox.top.as_numeric(), self.mediabox.right.as_numeric(), self.mediabox.top.as_numeric(), self.mediabox.right.as_numeric(), self.mediabox.bottom.as_numeric(), ] ctm = tuple(float(x) for x in ctm) # type: ignore[assignment] new_x = [ ctm[0] * corners[i] + ctm[2] * corners[i + 1] + ctm[4] for i in range(0, 8, 2) ] new_y = [ ctm[1] * corners[i] + ctm[3] * corners[i + 1] + ctm[5] for i in range(0, 8, 2) ] lowerleft = (min(new_x), min(new_y)) upperright = (max(new_x), max(new_y)) lowerleft = (min(corners[0], lowerleft[0]), min(corners[1], lowerleft[1])) upperright = ( max(corners[2], upperright[0]), max(corners[3], upperright[1]), ) self.mediabox.lower_left = lowerleft self.mediabox.upper_right = upperright
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1079-L1134
39
[ 0, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55 ]
75
[]
0
false
91.202346
56
6
100
9
def add_transformation( self, ctm: Union[Transformation, CompressedTransformationMatrix], expand: bool = False, ) -> None: if isinstance(ctm, Transformation): ctm = ctm.ctm content = self.get_contents() if content is not None: content = PageObject._add_transformation_matrix(content, self.pdf, ctm) content = PageObject._push_pop_gs(content, self.pdf) self[NameObject(PG.CONTENTS)] = content # if expanding the page to fit a new page, calculate the new media box size if expand: corners = [ self.mediabox.left.as_numeric(), self.mediabox.bottom.as_numeric(), self.mediabox.left.as_numeric(), self.mediabox.top.as_numeric(), self.mediabox.right.as_numeric(), self.mediabox.top.as_numeric(), self.mediabox.right.as_numeric(), self.mediabox.bottom.as_numeric(), ] ctm = tuple(float(x) for x in ctm) # type: ignore[assignment] new_x = [ ctm[0] * corners[i] + ctm[2] * corners[i + 1] + ctm[4] for i in range(0, 8, 2) ] new_y = [ ctm[1] * corners[i] + ctm[3] * corners[i + 1] + ctm[5] for i in range(0, 8, 2) ] lowerleft = (min(new_x), min(new_y)) upperright = (max(new_x), max(new_y)) lowerleft = (min(corners[0], lowerleft[0]), min(corners[1], lowerleft[1])) upperright = ( max(corners[2], upperright[0]), max(corners[3], upperright[1]), ) self.mediabox.lower_left = lowerleft self.mediabox.upper_right = upperright
24,091
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.addTransformation
( self, ctm: CompressedTransformationMatrix )
.. deprecated:: 1.28.0 Use :meth:`add_transformation` instead.
.. deprecated:: 1.28.0
1,136
1,145
def addTransformation( self, ctm: CompressedTransformationMatrix ) -> None: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`add_transformation` instead. """ deprecation_with_replacement("addTransformation", "add_transformation", "3.0.0") self.add_transformation(ctm)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1136-L1145
39
[]
0
[]
0
false
91.202346
10
1
100
3
def addTransformation( self, ctm: CompressedTransformationMatrix ) -> None: # deprecated deprecation_with_replacement("addTransformation", "add_transformation", "3.0.0") self.add_transformation(ctm)
24,092
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.scale
(self, sx: float, sy: float)
Scale a page by the given factors by applying a transformation matrix to its content and updating the page size. This updates the mediabox, the cropbox, and the contents of the page. Args: sx: The scaling factor on horizontal axis. sy: The scaling factor on vertical axis.
Scale a page by the given factors by applying a transformation matrix to its content and updating the page size.
1,147
1,198
def scale(self, sx: float, sy: float) -> None: """ Scale a page by the given factors by applying a transformation matrix to its content and updating the page size. This updates the mediabox, the cropbox, and the contents of the page. Args: sx: The scaling factor on horizontal axis. sy: The scaling factor on vertical axis. """ self.add_transformation((sx, 0, 0, sy, 0, 0)) self.cropbox = self.cropbox.scale(sx, sy) self.artbox = self.artbox.scale(sx, sy) self.bleedbox = self.bleedbox.scale(sx, sy) self.trimbox = self.trimbox.scale(sx, sy) self.mediabox = self.mediabox.scale(sx, sy) if PG.ANNOTS in self: annotations = self[PG.ANNOTS] if isinstance(annotations, ArrayObject): for annotation in annotations: annotation_obj = annotation.get_object() if ADA.Rect in annotation_obj: rectangle = annotation_obj[ADA.Rect] if isinstance(rectangle, ArrayObject): rectangle[0] = FloatObject(float(rectangle[0]) * sx) rectangle[1] = FloatObject(float(rectangle[1]) * sy) rectangle[2] = FloatObject(float(rectangle[2]) * sx) rectangle[3] = FloatObject(float(rectangle[3]) * sy) if PG.VP in self: viewport = self[PG.VP] if isinstance(viewport, ArrayObject): bbox = viewport[0]["/BBox"] else: bbox = viewport["/BBox"] # type: ignore scaled_bbox = RectangleObject( ( float(bbox[0]) * sx, float(bbox[1]) * sy, float(bbox[2]) * sx, float(bbox[3]) * sy, ) ) if isinstance(viewport, ArrayObject): self[NameObject(PG.VP)][NumberObject(0)][ # type: ignore NameObject("/BBox") ] = scaled_bbox else: self[NameObject(PG.VP)][NameObject("/BBox")] = scaled_bbox
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1147-L1198
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 ]
63.461538
[ 33, 34, 35, 37, 38, 46, 47, 51 ]
15.384615
false
91.202346
52
9
84.615385
9
def scale(self, sx: float, sy: float) -> None: self.add_transformation((sx, 0, 0, sy, 0, 0)) self.cropbox = self.cropbox.scale(sx, sy) self.artbox = self.artbox.scale(sx, sy) self.bleedbox = self.bleedbox.scale(sx, sy) self.trimbox = self.trimbox.scale(sx, sy) self.mediabox = self.mediabox.scale(sx, sy) if PG.ANNOTS in self: annotations = self[PG.ANNOTS] if isinstance(annotations, ArrayObject): for annotation in annotations: annotation_obj = annotation.get_object() if ADA.Rect in annotation_obj: rectangle = annotation_obj[ADA.Rect] if isinstance(rectangle, ArrayObject): rectangle[0] = FloatObject(float(rectangle[0]) * sx) rectangle[1] = FloatObject(float(rectangle[1]) * sy) rectangle[2] = FloatObject(float(rectangle[2]) * sx) rectangle[3] = FloatObject(float(rectangle[3]) * sy) if PG.VP in self: viewport = self[PG.VP] if isinstance(viewport, ArrayObject): bbox = viewport[0]["/BBox"] else: bbox = viewport["/BBox"] # type: ignore scaled_bbox = RectangleObject( ( float(bbox[0]) * sx, float(bbox[1]) * sy, float(bbox[2]) * sx, float(bbox[3]) * sy, ) ) if isinstance(viewport, ArrayObject): self[NameObject(PG.VP)][NumberObject(0)][ # type: ignore NameObject("/BBox") ] = scaled_bbox else: self[NameObject(PG.VP)][NameObject("/BBox")] = scaled_bbox
24,093
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.scale_by
(self, factor: float)
Scale a page by the given factor by applying a transformation matrix to its content and updating the page size. Args: factor: The scaling factor (for both X and Y axis).
Scale a page by the given factor by applying a transformation matrix to its content and updating the page size.
1,200
1,208
def scale_by(self, factor: float) -> None: """ Scale a page by the given factor by applying a transformation matrix to its content and updating the page size. Args: factor: The scaling factor (for both X and Y axis). """ self.scale(factor, factor)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1200-L1208
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
91.202346
9
1
100
5
def scale_by(self, factor: float) -> None: self.scale(factor, factor)
24,094
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.scaleBy
(self, factor: float)
.. deprecated:: 1.28.0 Use :meth:`scale_by` instead.
.. deprecated:: 1.28.0
1,210
1,217
def scaleBy(self, factor: float) -> None: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`scale_by` instead. """ deprecation_with_replacement("scaleBy", "scale_by", "3.0.0") self.scale(factor, factor)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1210-L1217
39
[]
0
[]
0
false
91.202346
8
1
100
3
def scaleBy(self, factor: float) -> None: # deprecated deprecation_with_replacement("scaleBy", "scale_by", "3.0.0") self.scale(factor, factor)
24,095
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.scale_to
(self, width: float, height: float)
Scale a page to the specified dimensions by applying a transformation matrix to its content and updating the page size. Args: width: The new width. height: The new height.
Scale a page to the specified dimensions by applying a transformation matrix to its content and updating the page size.
1,219
1,230
def scale_to(self, width: float, height: float) -> None: """ Scale a page to the specified dimensions by applying a transformation matrix to its content and updating the page size. Args: width: The new width. height: The new height. """ sx = width / float(self.mediabox.width) sy = height / float(self.mediabox.height) self.scale(sx, sy)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1219-L1230
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
91.202346
12
1
100
6
def scale_to(self, width: float, height: float) -> None: sx = width / float(self.mediabox.width) sy = height / float(self.mediabox.height) self.scale(sx, sy)
24,096
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.scaleTo
(self, width: float, height: float)
.. deprecated:: 1.28.0 Use :meth:`scale_to` instead.
.. deprecated:: 1.28.0
1,232
1,239
def scaleTo(self, width: float, height: float) -> None: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`scale_to` instead. """ deprecation_with_replacement("scaleTo", "scale_to", "3.0.0") self.scale_to(width, height)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1232-L1239
39
[]
0
[]
0
false
91.202346
8
1
100
3
def scaleTo(self, width: float, height: float) -> None: # deprecated deprecation_with_replacement("scaleTo", "scale_to", "3.0.0") self.scale_to(width, height)
24,097
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.compress_content_streams
(self)
Compress the size of this page by joining all content streams and applying a FlateDecode filter. However, it is possible that this function will perform no action if content stream compression becomes "automatic".
Compress the size of this page by joining all content streams and applying a FlateDecode filter.
1,241
1,253
def compress_content_streams(self) -> None: """ Compress the size of this page by joining all content streams and applying a FlateDecode filter. However, it is possible that this function will perform no action if content stream compression becomes "automatic". """ content = self.get_contents() if content is not None: if not isinstance(content, ContentStream): content = ContentStream(content, self.pdf) self[NameObject(PG.CONTENTS)] = content.flate_encode()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1241-L1253
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
100
[]
0
true
91.202346
13
3
100
5
def compress_content_streams(self) -> None: content = self.get_contents() if content is not None: if not isinstance(content, ContentStream): content = ContentStream(content, self.pdf) self[NameObject(PG.CONTENTS)] = content.flate_encode()
24,098
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.compressContentStreams
(self)
.. deprecated:: 1.28.0 Use :meth:`compress_content_streams` instead.
.. deprecated:: 1.28.0
1,255
1,264
def compressContentStreams(self) -> None: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`compress_content_streams` instead. """ deprecation_with_replacement( "compressContentStreams", "compress_content_streams", "3.0.0" ) self.compress_content_streams()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1255-L1264
39
[]
0
[]
0
false
91.202346
10
1
100
3
def compressContentStreams(self) -> None: # deprecated deprecation_with_replacement( "compressContentStreams", "compress_content_streams", "3.0.0" ) self.compress_content_streams()
24,099
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject._debug_for_extract
(self)
return out
1,266
1,302
def _debug_for_extract(self) -> str: # pragma: no cover out = "" for ope, op in ContentStream( self["/Contents"].get_object(), self.pdf, "bytes" ).operations: if op == b"TJ": s = [x for x in ope[0] if isinstance(x, str)] else: s = [] out += op.decode("utf-8") + " " + "".join(s) + ope.__repr__() + "\n" out += "\n=============================\n" try: for fo in self[PG.RESOURCES]["/Font"]: # type:ignore out += fo + "\n" out += self[PG.RESOURCES]["/Font"][fo].__repr__() + "\n" # type:ignore try: enc_repr = self[PG.RESOURCES]["/Font"][fo][ # type:ignore "/Encoding" ].__repr__() out += enc_repr + "\n" except Exception: pass try: out += ( self[PG.RESOURCES]["/Font"][fo][ # type:ignore "/ToUnicode" ] .get_data() .decode() + "\n" ) except Exception: pass except KeyError: out += "No Font\n" return out
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1266-L1302
39
[]
0
[]
0
false
91.202346
37
8
100
0
def _debug_for_extract(self) -> str: # pragma: no cover out = "" for ope, op in ContentStream( self["/Contents"].get_object(), self.pdf, "bytes" ).operations: if op == b"TJ": s = [x for x in ope[0] if isinstance(x, str)] else: s = [] out += op.decode("utf-8") + " " + "".join(s) + ope.__repr__() + "\n" out += "\n=============================\n" try: for fo in self[PG.RESOURCES]["/Font"]: # type:ignore out += fo + "\n" out += self[PG.RESOURCES]["/Font"][fo].__repr__() + "\n" # type:ignore try: enc_repr = self[PG.RESOURCES]["/Font"][fo][ # type:ignore "/Encoding" ].__repr__() out += enc_repr + "\n" except Exception: pass try: out += ( self[PG.RESOURCES]["/Font"][fo][ # type:ignore "/ToUnicode" ] .get_data() .decode() + "\n" ) except Exception: pass except KeyError: out += "No Font\n" return out
24,100
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject._extract_text
( self, obj: Any, pdf: Any, orientations: Tuple[int, ...] = (0, 90, 180, 270), space_width: float = 200.0, content_key: Optional[str] = PG.CONTENTS, visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_operand_after: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]] = None, )
return output
See extract_text for most arguments. Args: content_key: indicate the default key where to extract data None = the object; this allow to reuse the function on XObject default = "/Content"
See extract_text for most arguments.
1,304
1,763
def _extract_text( self, obj: Any, pdf: Any, orientations: Tuple[int, ...] = (0, 90, 180, 270), space_width: float = 200.0, content_key: Optional[str] = PG.CONTENTS, visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_operand_after: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]] = None, ) -> str: """ See extract_text for most arguments. Args: content_key: indicate the default key where to extract data None = the object; this allow to reuse the function on XObject default = "/Content" """ text: str = "" output: str = "" rtl_dir: bool = False # right-to-left cmaps: Dict[ str, Tuple[ str, float, Union[str, Dict[int, str]], Dict[str, str], DictionaryObject ], ] = {} try: objr = obj while NameObject(PG.RESOURCES) not in objr: # /Resources can be inherited sometimes so we look to parents objr = objr["/Parent"].get_object() # if no parents we will have no /Resources will be available => an exception wil be raised resources_dict = cast(DictionaryObject, objr[PG.RESOURCES]) except Exception: return "" # no resources means no text is possible (no font) we consider the file as not damaged, no need to check for TJ or Tj if "/Font" in resources_dict: for f in cast(DictionaryObject, resources_dict["/Font"]): cmaps[f] = build_char_map(f, space_width, obj) cmap: Tuple[ Union[str, Dict[int, str]], Dict[str, str], str, Optional[DictionaryObject] ] = ( "charmap", {}, "NotInitialized", None, ) # (encoding,CMAP,font resource name,dictionary-object of font) try: content = ( obj[content_key].get_object() if isinstance(content_key, str) else obj ) if not isinstance(content, ContentStream): content = ContentStream(content, pdf, "bytes") except KeyError: # it means no content can be extracted(certainly empty page) return "" # Note: we check all strings are TextStringObjects. ByteStringObjects # are strings where the byte->string encoding was unknown, so adding # them to the text here would be gibberish. cm_matrix: List[float] = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] cm_stack = [] tm_matrix: List[float] = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] tm_prev: List[float] = [ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, ] # will store cm_matrix * tm_matrix char_scale = 1.0 space_scale = 1.0 _space_width: float = 500.0 # will be set correctly at first Tf TL = 0.0 font_size = 12.0 # init just in case of def mult(m: List[float], n: List[float]) -> List[float]: return [ m[0] * n[0] + m[1] * n[2], m[0] * n[1] + m[1] * n[3], m[2] * n[0] + m[3] * n[2], m[2] * n[1] + m[3] * n[3], m[4] * n[0] + m[5] * n[2] + n[4], m[4] * n[1] + m[5] * n[3] + n[5], ] def orient(m: List[float]) -> int: if m[3] > 1e-6: return 0 elif m[3] < -1e-6: return 180 elif m[1] > 0: return 90 else: return 270 def current_spacewidth() -> float: # return space_scale * _space_width * char_scale return _space_width / 1000.0 def process_operation(operator: bytes, operands: List) -> None: nonlocal cm_matrix, cm_stack, tm_matrix, tm_prev, output, text, char_scale, space_scale, _space_width, TL, font_size, cmap, orientations, rtl_dir, visitor_text global CUSTOM_RTL_MIN, CUSTOM_RTL_MAX, CUSTOM_RTL_SPECIAL_CHARS check_crlf_space: bool = False # Table 5.4 page 405 if operator == b"BT": tm_matrix = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] # tm_prev = tm_matrix output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) # based # if output != "" and output[-1]!="\n": # output += "\n" text = "" return None elif operator == b"ET": output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" # table 4.7 "Graphics state operators", page 219 # cm_matrix calculation is a reserved for the moment elif operator == b"q": cm_stack.append( ( cm_matrix, cmap, font_size, char_scale, space_scale, _space_width, TL, ) ) elif operator == b"Q": try: ( cm_matrix, cmap, font_size, char_scale, space_scale, _space_width, TL, ) = cm_stack.pop() except Exception: cm_matrix = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] # rtl_dir = False elif operator == b"cm": output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" cm_matrix = mult( [ float(operands[0]), float(operands[1]), float(operands[2]), float(operands[3]), float(operands[4]), float(operands[5]), ], cm_matrix, ) # rtl_dir = False # Table 5.2 page 398 elif operator == b"Tz": char_scale = float(operands[0]) / 100.0 elif operator == b"Tw": space_scale = 1.0 + float(operands[0]) elif operator == b"TL": TL = float(operands[0]) elif operator == b"Tf": if text != "": output += text # .translate(cmap) if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" # rtl_dir = False try: # charMapTuple: font_type, float(sp_width / 2), encoding, map_dict, font-dictionary charMapTuple = cmaps[operands[0]] _space_width = charMapTuple[1] # current cmap: encoding, map_dict, font resource name (internal name, not the real font-name), # font-dictionary. The font-dictionary describes the font. cmap = ( charMapTuple[2], charMapTuple[3], operands[0], charMapTuple[4], ) except KeyError: # font not found _space_width = unknown_char_map[1] cmap = ( unknown_char_map[2], unknown_char_map[3], "???" + operands[0], None, ) try: font_size = float(operands[1]) except Exception: pass # keep previous size # Table 5.5 page 406 elif operator == b"Td": check_crlf_space = True # A special case is a translating only tm: # tm[0..5] = 1 0 0 1 e f, # i.e. tm[4] += tx, tm[5] += ty. tx = float(operands[0]) ty = float(operands[1]) tm_matrix[4] += tx * tm_matrix[0] + ty * tm_matrix[2] tm_matrix[5] += tx * tm_matrix[1] + ty * tm_matrix[3] elif operator == b"Tm": check_crlf_space = True tm_matrix = [ float(operands[0]), float(operands[1]), float(operands[2]), float(operands[3]), float(operands[4]), float(operands[5]), ] elif operator == b"T*": check_crlf_space = True tm_matrix[5] -= TL elif operator == b"Tj": check_crlf_space = True m = mult(tm_matrix, cm_matrix) orientation = orient(m) if orientation in orientations: if isinstance(operands[0], str): text += operands[0] else: t: str = "" tt: bytes = ( encode_pdfdocencoding(operands[0]) if isinstance(operands[0], str) else operands[0] ) if isinstance(cmap[0], str): try: t = tt.decode( cmap[0], "surrogatepass" ) # apply str encoding except Exception: # the data does not match the expectation, we use the alternative ; text extraction may not be good t = tt.decode( "utf-16-be" if cmap[0] == "charmap" else "charmap", "surrogatepass", ) # apply str encoding else: # apply dict encoding t = "".join( [ cmap[0][x] if x in cmap[0] else bytes((x,)).decode() for x in tt ] ) # "\u0590 - \u08FF \uFB50 - \uFDFF" for x in "".join( [cmap[1][x] if x in cmap[1] else x for x in t] ): xx = ord(x) # fmt: off if ( # cases where the current inserting order is kept (punctuation,...) (xx <= 0x2F) # punctuations but... or (0x3A <= xx and xx <= 0x40) # numbers (x30-39) or (0x2000 <= xx and xx <= 0x206F) # upper punctuations.. or (0x20A0 <= xx and xx <= 0x21FF) # but (numbers) indices/exponents or xx in CUSTOM_RTL_SPECIAL_CHARS # customized.... ): text = x + text if rtl_dir else text + x elif ( # right-to-left characters set (0x0590 <= xx and xx <= 0x08FF) or (0xFB1D <= xx and xx <= 0xFDFF) or (0xFE70 <= xx and xx <= 0xFEFF) or (CUSTOM_RTL_MIN <= xx and xx <= CUSTOM_RTL_MAX) ): # print("<",xx,x) if not rtl_dir: rtl_dir = True # print("RTL",text,"*") output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" text = x + text else: # left-to-right # print(">",xx,x,end="") if rtl_dir: rtl_dir = False # print("LTR",text,"*") output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" text = text + x # fmt: on else: return None if check_crlf_space: m = mult(tm_matrix, cm_matrix) orientation = orient(m) delta_x = m[4] - tm_prev[4] delta_y = m[5] - tm_prev[5] k = math.sqrt(abs(m[0] * m[3]) + abs(m[1] * m[2])) f = font_size * k tm_prev = m if orientation not in orientations: return None try: if orientation == 0: if delta_y < -0.8 * f: if (output + text)[-1] != "\n": output += text + "\n" if visitor_text is not None: visitor_text( text + "\n", cm_matrix, tm_matrix, cmap[3], font_size, ) text = "" elif ( abs(delta_y) < f * 0.3 and abs(delta_x) > current_spacewidth() * f * 15 ): if (output + text)[-1] != " ": text += " " elif orientation == 180: if delta_y > 0.8 * f: if (output + text)[-1] != "\n": output += text + "\n" if visitor_text is not None: visitor_text( text + "\n", cm_matrix, tm_matrix, cmap[3], font_size, ) text = "" elif ( abs(delta_y) < f * 0.3 and abs(delta_x) > current_spacewidth() * f * 15 ): if (output + text)[-1] != " ": text += " " elif orientation == 90: if delta_x > 0.8 * f: if (output + text)[-1] != "\n": output += text + "\n" if visitor_text is not None: visitor_text( text + "\n", cm_matrix, tm_matrix, cmap[3], font_size, ) text = "" elif ( abs(delta_x) < f * 0.3 and abs(delta_y) > current_spacewidth() * f * 15 ): if (output + text)[-1] != " ": text += " " elif orientation == 270: if delta_x < -0.8 * f: if (output + text)[-1] != "\n": output += text + "\n" if visitor_text is not None: visitor_text( text + "\n", cm_matrix, tm_matrix, cmap[3], font_size, ) text = "" elif ( abs(delta_x) < f * 0.3 and abs(delta_y) > current_spacewidth() * f * 15 ): if (output + text)[-1] != " ": text += " " except Exception: pass for operands, operator in content.operations: if visitor_operand_before is not None: visitor_operand_before(operator, operands, cm_matrix, tm_matrix) # multiple operators are defined in here #### if operator == b"'": process_operation(b"T*", []) process_operation(b"Tj", operands) elif operator == b'"': process_operation(b"Tw", [operands[0]]) process_operation(b"Tc", [operands[1]]) process_operation(b"T*", []) process_operation(b"Tj", operands[2:]) elif operator == b"TD": process_operation(b"TL", [-operands[1]]) process_operation(b"Td", operands) elif operator == b"TJ": for op in operands[0]: if isinstance(op, (str, bytes)): process_operation(b"Tj", [op]) if isinstance(op, (int, float, NumberObject, FloatObject)): if ( (abs(float(op)) >= _space_width) and (len(text) > 0) and (text[-1] != " ") ): process_operation(b"Tj", [" "]) elif operator == b"Do": output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) try: if output[-1] != "\n": output += "\n" if visitor_text is not None: visitor_text("\n", cm_matrix, tm_matrix, cmap[3], font_size) except IndexError: pass try: xobj = resources_dict["/XObject"] if xobj[operands[0]]["/Subtype"] != "/Image": # type: ignore # output += text text = self.extract_xform_text( xobj[operands[0]], # type: ignore orientations, space_width, visitor_operand_before, visitor_operand_after, visitor_text, ) output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) except Exception: logger_warning( f" impossible to decode XFormObject {operands[0]}", __name__, ) finally: text = "" else: process_operation(operator, operands) if visitor_operand_after is not None: visitor_operand_after(operator, operands, cm_matrix, tm_matrix) output += text # just in case of if text != "" and visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) return output
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1304-L1763
39
[ 0, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 150, 151, 152, 153, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 288, 289, 290, 291, 292, 293, 294, 295, 296, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 423, 424, 425, 426, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 459 ]
89.782609
[ 148, 149, 154, 179, 204, 205, 287, 297, 338, 357, 376, 422, 427, 444, 458 ]
3.26087
false
91.202346
460
116
96.73913
6
def _extract_text( self, obj: Any, pdf: Any, orientations: Tuple[int, ...] = (0, 90, 180, 270), space_width: float = 200.0, content_key: Optional[str] = PG.CONTENTS, visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_operand_after: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]] = None, ) -> str: text: str = "" output: str = "" rtl_dir: bool = False # right-to-left cmaps: Dict[ str, Tuple[ str, float, Union[str, Dict[int, str]], Dict[str, str], DictionaryObject ], ] = {} try: objr = obj while NameObject(PG.RESOURCES) not in objr: # /Resources can be inherited sometimes so we look to parents objr = objr["/Parent"].get_object() # if no parents we will have no /Resources will be available => an exception wil be raised resources_dict = cast(DictionaryObject, objr[PG.RESOURCES]) except Exception: return "" # no resources means no text is possible (no font) we consider the file as not damaged, no need to check for TJ or Tj if "/Font" in resources_dict: for f in cast(DictionaryObject, resources_dict["/Font"]): cmaps[f] = build_char_map(f, space_width, obj) cmap: Tuple[ Union[str, Dict[int, str]], Dict[str, str], str, Optional[DictionaryObject] ] = ( "charmap", {}, "NotInitialized", None, ) # (encoding,CMAP,font resource name,dictionary-object of font) try: content = ( obj[content_key].get_object() if isinstance(content_key, str) else obj ) if not isinstance(content, ContentStream): content = ContentStream(content, pdf, "bytes") except KeyError: # it means no content can be extracted(certainly empty page) return "" # Note: we check all strings are TextStringObjects. ByteStringObjects # are strings where the byte->string encoding was unknown, so adding # them to the text here would be gibberish. cm_matrix: List[float] = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] cm_stack = [] tm_matrix: List[float] = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] tm_prev: List[float] = [ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, ] # will store cm_matrix * tm_matrix char_scale = 1.0 space_scale = 1.0 _space_width: float = 500.0 # will be set correctly at first Tf TL = 0.0 font_size = 12.0 # init just in case of def mult(m: List[float], n: List[float]) -> List[float]: return [ m[0] * n[0] + m[1] * n[2], m[0] * n[1] + m[1] * n[3], m[2] * n[0] + m[3] * n[2], m[2] * n[1] + m[3] * n[3], m[4] * n[0] + m[5] * n[2] + n[4], m[4] * n[1] + m[5] * n[3] + n[5], ] def orient(m: List[float]) -> int: if m[3] > 1e-6: return 0 elif m[3] < -1e-6: return 180 elif m[1] > 0: return 90 else: return 270 def current_spacewidth() -> float: # return space_scale * _space_width * char_scale return _space_width / 1000.0 def process_operation(operator: bytes, operands: List) -> None: nonlocal cm_matrix, cm_stack, tm_matrix, tm_prev, output, text, char_scale, space_scale, _space_width, TL, font_size, cmap, orientations, rtl_dir, visitor_text global CUSTOM_RTL_MIN, CUSTOM_RTL_MAX, CUSTOM_RTL_SPECIAL_CHARS check_crlf_space: bool = False # Table 5.4 page 405 if operator == b"BT": tm_matrix = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] # tm_prev = tm_matrix output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) # based # if output != "" and output[-1]!="\n": # output += "\n" text = "" return None elif operator == b"ET": output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" # table 4.7 "Graphics state operators", page 219 # cm_matrix calculation is a reserved for the moment elif operator == b"q": cm_stack.append( ( cm_matrix, cmap, font_size, char_scale, space_scale, _space_width, TL, ) ) elif operator == b"Q": try: ( cm_matrix, cmap, font_size, char_scale, space_scale, _space_width, TL, ) = cm_stack.pop() except Exception: cm_matrix = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] # rtl_dir = False elif operator == b"cm": output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" cm_matrix = mult( [ float(operands[0]), float(operands[1]), float(operands[2]), float(operands[3]), float(operands[4]), float(operands[5]), ], cm_matrix, ) # rtl_dir = False # Table 5.2 page 398 elif operator == b"Tz": char_scale = float(operands[0]) / 100.0 elif operator == b"Tw": space_scale = 1.0 + float(operands[0]) elif operator == b"TL": TL = float(operands[0]) elif operator == b"Tf": if text != "": output += text # .translate(cmap) if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" # rtl_dir = False try: # charMapTuple: font_type, float(sp_width / 2), encoding, map_dict, font-dictionary charMapTuple = cmaps[operands[0]] _space_width = charMapTuple[1] # current cmap: encoding, map_dict, font resource name (internal name, not the real font-name), # font-dictionary. The font-dictionary describes the font. cmap = ( charMapTuple[2], charMapTuple[3], operands[0], charMapTuple[4], ) except KeyError: # font not found _space_width = unknown_char_map[1] cmap = ( unknown_char_map[2], unknown_char_map[3], "???" + operands[0], None, ) try: font_size = float(operands[1]) except Exception: pass # keep previous size # Table 5.5 page 406 elif operator == b"Td": check_crlf_space = True # A special case is a translating only tm: # tm[0..5] = 1 0 0 1 e f, # i.e. tm[4] += tx, tm[5] += ty. tx = float(operands[0]) ty = float(operands[1]) tm_matrix[4] += tx * tm_matrix[0] + ty * tm_matrix[2] tm_matrix[5] += tx * tm_matrix[1] + ty * tm_matrix[3] elif operator == b"Tm": check_crlf_space = True tm_matrix = [ float(operands[0]), float(operands[1]), float(operands[2]), float(operands[3]), float(operands[4]), float(operands[5]), ] elif operator == b"T*": check_crlf_space = True tm_matrix[5] -= TL elif operator == b"Tj": check_crlf_space = True m = mult(tm_matrix, cm_matrix) orientation = orient(m) if orientation in orientations: if isinstance(operands[0], str): text += operands[0] else: t: str = "" tt: bytes = ( encode_pdfdocencoding(operands[0]) if isinstance(operands[0], str) else operands[0] ) if isinstance(cmap[0], str): try: t = tt.decode( cmap[0], "surrogatepass" ) # apply str encoding except Exception: # the data does not match the expectation, we use the alternative ; text extraction may not be good t = tt.decode( "utf-16-be" if cmap[0] == "charmap" else "charmap", "surrogatepass", ) # apply str encoding else: # apply dict encoding t = "".join( [ cmap[0][x] if x in cmap[0] else bytes((x,)).decode() for x in tt ] ) # "\u0590 - \u08FF \uFB50 - \uFDFF" for x in "".join( [cmap[1][x] if x in cmap[1] else x for x in t] ): xx = ord(x) # fmt: off if ( # cases where the current inserting order is kept (punctuation,...) (xx <= 0x2F) # punctuations but... or (0x3A <= xx and xx <= 0x40) # numbers (x30-39) or (0x2000 <= xx and xx <= 0x206F) # upper punctuations.. or (0x20A0 <= xx and xx <= 0x21FF) # but (numbers) indices/exponents or xx in CUSTOM_RTL_SPECIAL_CHARS # customized.... ): text = x + text if rtl_dir else text + x elif ( # right-to-left characters set (0x0590 <= xx and xx <= 0x08FF) or (0xFB1D <= xx and xx <= 0xFDFF) or (0xFE70 <= xx and xx <= 0xFEFF) or (CUSTOM_RTL_MIN <= xx and xx <= CUSTOM_RTL_MAX) ): # print("<",xx,x) if not rtl_dir: rtl_dir = True # print("RTL",text,"*") output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" text = x + text else: # left-to-right # print(">",xx,x,end="") if rtl_dir: rtl_dir = False # print("LTR",text,"*") output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) text = "" text = text + x # fmt: on else: return None if check_crlf_space: m = mult(tm_matrix, cm_matrix) orientation = orient(m) delta_x = m[4] - tm_prev[4] delta_y = m[5] - tm_prev[5] k = math.sqrt(abs(m[0] * m[3]) + abs(m[1] * m[2])) f = font_size * k tm_prev = m if orientation not in orientations: return None try: if orientation == 0: if delta_y < -0.8 * f: if (output + text)[-1] != "\n": output += text + "\n" if visitor_text is not None: visitor_text( text + "\n", cm_matrix, tm_matrix, cmap[3], font_size, ) text = "" elif ( abs(delta_y) < f * 0.3 and abs(delta_x) > current_spacewidth() * f * 15 ): if (output + text)[-1] != " ": text += " " elif orientation == 180: if delta_y > 0.8 * f: if (output + text)[-1] != "\n": output += text + "\n" if visitor_text is not None: visitor_text( text + "\n", cm_matrix, tm_matrix, cmap[3], font_size, ) text = "" elif ( abs(delta_y) < f * 0.3 and abs(delta_x) > current_spacewidth() * f * 15 ): if (output + text)[-1] != " ": text += " " elif orientation == 90: if delta_x > 0.8 * f: if (output + text)[-1] != "\n": output += text + "\n" if visitor_text is not None: visitor_text( text + "\n", cm_matrix, tm_matrix, cmap[3], font_size, ) text = "" elif ( abs(delta_x) < f * 0.3 and abs(delta_y) > current_spacewidth() * f * 15 ): if (output + text)[-1] != " ": text += " " elif orientation == 270: if delta_x < -0.8 * f: if (output + text)[-1] != "\n": output += text + "\n" if visitor_text is not None: visitor_text( text + "\n", cm_matrix, tm_matrix, cmap[3], font_size, ) text = "" elif ( abs(delta_x) < f * 0.3 and abs(delta_y) > current_spacewidth() * f * 15 ): if (output + text)[-1] != " ": text += " " except Exception: pass for operands, operator in content.operations: if visitor_operand_before is not None: visitor_operand_before(operator, operands, cm_matrix, tm_matrix) # multiple operators are defined in here #### if operator == b"'": process_operation(b"T*", []) process_operation(b"Tj", operands) elif operator == b'"': process_operation(b"Tw", [operands[0]]) process_operation(b"Tc", [operands[1]]) process_operation(b"T*", []) process_operation(b"Tj", operands[2:]) elif operator == b"TD": process_operation(b"TL", [-operands[1]]) process_operation(b"Td", operands) elif operator == b"TJ": for op in operands[0]: if isinstance(op, (str, bytes)): process_operation(b"Tj", [op]) if isinstance(op, (int, float, NumberObject, FloatObject)): if ( (abs(float(op)) >= _space_width) and (len(text) > 0) and (text[-1] != " ") ): process_operation(b"Tj", [" "]) elif operator == b"Do": output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) try: if output[-1] != "\n": output += "\n" if visitor_text is not None: visitor_text("\n", cm_matrix, tm_matrix, cmap[3], font_size) except IndexError: pass try: xobj = resources_dict["/XObject"] if xobj[operands[0]]["/Subtype"] != "/Image": # type: ignore # output += text text = self.extract_xform_text( xobj[operands[0]], # type: ignore orientations, space_width, visitor_operand_before, visitor_operand_after, visitor_text, ) output += text if visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) except Exception: logger_warning( f" impossible to decode XFormObject {operands[0]}", __name__, ) finally: text = "" else: process_operation(operator, operands) if visitor_operand_after is not None: visitor_operand_after(operator, operands, cm_matrix, tm_matrix) output += text # just in case of if text != "" and visitor_text is not None: visitor_text(text, cm_matrix, tm_matrix, cmap[3], font_size) return output
24,101
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.extract_text
( self, *args: Any, Tj_sep: Optional[str] = None, TJ_sep: Optional[str] = None, orientations: Union[int, Tuple[int, ...]] = (0, 90, 180, 270), space_width: float = 200.0, visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_operand_after: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]] = None, )
return self._extract_text( self, self.pdf, orientations, space_width, PG.CONTENTS, visitor_operand_before, visitor_operand_after, visitor_text, )
Locate all text drawing commands, in the order they are provided in the content stream, and extract the text. This works well for some PDF files, but poorly for others, depending on the generator used. This will be refined in the future. Do not rely on the order of text coming out of this function, as it will change if this function is made more sophisticated. Arabic, Hebrew,... are extracted in the good order. If required an custom RTL range of characters can be defined; see function set_custom_rtl Additionally you can provide visitor-methods to get informed on all operands and all text-objects. For example in some PDF files this can be useful to parse tables. Args: Tj_sep: Deprecated. Kept for compatibility until pypdf 4.0.0 TJ_sep: Deprecated. Kept for compatibility until pypdf 4.0.0 orientations: list of orientations text_extraction will look for default = (0, 90, 180, 270) note: currently only 0(Up),90(turned Left), 180(upside Down), 270 (turned Right) space_width: force default space width if not extracted from font (default: 200) visitor_operand_before: function to be called before processing an operand. It has four arguments: operand, operand-arguments, current transformation matrix and text matrix. visitor_operand_after: function to be called after processing an operand. It has four arguments: operand, operand-arguments, current transformation matrix and text matrix. visitor_text: function to be called when extracting some text at some position. It has five arguments: text, current transformation matrix, text matrix, font-dictionary and font-size. The font-dictionary may be None in case of unknown fonts. If not None it may e.g. contain key "/BaseFont" with value "/Arial,Bold". Returns: The extracted text
Locate all text drawing commands, in the order they are provided in the content stream, and extract the text.
1,765
1,861
def extract_text( self, *args: Any, Tj_sep: Optional[str] = None, TJ_sep: Optional[str] = None, orientations: Union[int, Tuple[int, ...]] = (0, 90, 180, 270), space_width: float = 200.0, visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_operand_after: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]] = None, ) -> str: """ Locate all text drawing commands, in the order they are provided in the content stream, and extract the text. This works well for some PDF files, but poorly for others, depending on the generator used. This will be refined in the future. Do not rely on the order of text coming out of this function, as it will change if this function is made more sophisticated. Arabic, Hebrew,... are extracted in the good order. If required an custom RTL range of characters can be defined; see function set_custom_rtl Additionally you can provide visitor-methods to get informed on all operands and all text-objects. For example in some PDF files this can be useful to parse tables. Args: Tj_sep: Deprecated. Kept for compatibility until pypdf 4.0.0 TJ_sep: Deprecated. Kept for compatibility until pypdf 4.0.0 orientations: list of orientations text_extraction will look for default = (0, 90, 180, 270) note: currently only 0(Up),90(turned Left), 180(upside Down), 270 (turned Right) space_width: force default space width if not extracted from font (default: 200) visitor_operand_before: function to be called before processing an operand. It has four arguments: operand, operand-arguments, current transformation matrix and text matrix. visitor_operand_after: function to be called after processing an operand. It has four arguments: operand, operand-arguments, current transformation matrix and text matrix. visitor_text: function to be called when extracting some text at some position. It has five arguments: text, current transformation matrix, text matrix, font-dictionary and font-size. The font-dictionary may be None in case of unknown fonts. If not None it may e.g. contain key "/BaseFont" with value "/Arial,Bold". Returns: The extracted text """ if len(args) >= 1: if isinstance(args[0], str): Tj_sep = args[0] if len(args) >= 2: if isinstance(args[1], str): TJ_sep = args[1] else: raise TypeError(f"Invalid positional parameter {args[1]}") if len(args) >= 3: if isinstance(args[2], (tuple, int)): orientations = args[2] else: raise TypeError(f"Invalid positional parameter {args[2]}") if len(args) >= 4: if isinstance(args[3], (float, int)): space_width = args[3] else: raise TypeError(f"Invalid positional parameter {args[3]}") elif isinstance(args[0], (tuple, int)): orientations = args[0] if len(args) >= 2: if isinstance(args[1], (float, int)): space_width = args[1] else: raise TypeError(f"Invalid positional parameter {args[1]}") else: raise TypeError(f"Invalid positional parameter {args[0]}") if Tj_sep is not None or TJ_sep is not None: warnings.warn( "parameters Tj_Sep, TJ_sep depreciated, and will be removed in pypdf 4.0.0.", DeprecationWarning, ) if isinstance(orientations, int): orientations = (orientations,) return self._extract_text( self, self.pdf, orientations, space_width, PG.CONTENTS, visitor_operand_before, visitor_operand_after, visitor_text, )
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1765-L1861
39
[ 0, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 ]
49.484536
[]
0
false
91.202346
97
15
100
38
def extract_text( self, *args: Any, Tj_sep: Optional[str] = None, TJ_sep: Optional[str] = None, orientations: Union[int, Tuple[int, ...]] = (0, 90, 180, 270), space_width: float = 200.0, visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_operand_after: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]] = None, ) -> str: if len(args) >= 1: if isinstance(args[0], str): Tj_sep = args[0] if len(args) >= 2: if isinstance(args[1], str): TJ_sep = args[1] else: raise TypeError(f"Invalid positional parameter {args[1]}") if len(args) >= 3: if isinstance(args[2], (tuple, int)): orientations = args[2] else: raise TypeError(f"Invalid positional parameter {args[2]}") if len(args) >= 4: if isinstance(args[3], (float, int)): space_width = args[3] else: raise TypeError(f"Invalid positional parameter {args[3]}") elif isinstance(args[0], (tuple, int)): orientations = args[0] if len(args) >= 2: if isinstance(args[1], (float, int)): space_width = args[1] else: raise TypeError(f"Invalid positional parameter {args[1]}") else: raise TypeError(f"Invalid positional parameter {args[0]}") if Tj_sep is not None or TJ_sep is not None: warnings.warn( "parameters Tj_Sep, TJ_sep depreciated, and will be removed in pypdf 4.0.0.", DeprecationWarning, ) if isinstance(orientations, int): orientations = (orientations,) return self._extract_text( self, self.pdf, orientations, space_width, PG.CONTENTS, visitor_operand_before, visitor_operand_after, visitor_text, )
24,102
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.extract_xform_text
( self, xform: EncodedStreamObject, orientations: Tuple[int, ...] = (0, 90, 270, 360), space_width: float = 200.0, visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_operand_after: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]] = None, )
return self._extract_text( xform, self.pdf, orientations, space_width, None, visitor_operand_before, visitor_operand_after, visitor_text, )
Extract text from an XObject. Args: space_width: force default space width (if not extracted from font (default 200) Returns: The extracted text
Extract text from an XObject.
1,863
1,890
def extract_xform_text( self, xform: EncodedStreamObject, orientations: Tuple[int, ...] = (0, 90, 270, 360), space_width: float = 200.0, visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_operand_after: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]] = None, ) -> str: """ Extract text from an XObject. Args: space_width: force default space width (if not extracted from font (default 200) Returns: The extracted text """ return self._extract_text( xform, self.pdf, orientations, space_width, None, visitor_operand_before, visitor_operand_after, visitor_text, )
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1863-L1890
39
[ 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ]
42.857143
[]
0
false
91.202346
28
1
100
7
def extract_xform_text( self, xform: EncodedStreamObject, orientations: Tuple[int, ...] = (0, 90, 270, 360), space_width: float = 200.0, visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_operand_after: Optional[Callable[[Any, Any, Any, Any], None]] = None, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]] = None, ) -> str: return self._extract_text( xform, self.pdf, orientations, space_width, None, visitor_operand_before, visitor_operand_after, visitor_text, )
24,103
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.extractText
(self, Tj_sep: str = "", TJ_sep: str = "")
return self.extract_text()
.. deprecated:: 1.28.0 Use :meth:`extract_text` instead.
.. deprecated:: 1.28.0
1,892
1,899
def extractText(self, Tj_sep: str = "", TJ_sep: str = "") -> str: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`extract_text` instead. """ deprecation_with_replacement("extractText", "extract_text", "3.0.0") return self.extract_text()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1892-L1899
39
[]
0
[]
0
false
91.202346
8
1
100
3
def extractText(self, Tj_sep: str = "", TJ_sep: str = "") -> str: # deprecated deprecation_with_replacement("extractText", "extract_text", "3.0.0") return self.extract_text()
24,104
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject._get_fonts
(self)
return embedded, unembedded
Get the names of embedded fonts and unembedded fonts. Returns: A tuple (Set of embedded fonts, set of unembedded fonts)
Get the names of embedded fonts and unembedded fonts.
1,901
1,912
def _get_fonts(self) -> Tuple[Set[str], Set[str]]: """ Get the names of embedded fonts and unembedded fonts. Returns: A tuple (Set of embedded fonts, set of unembedded fonts) """ obj = self.get_object() assert isinstance(obj, DictionaryObject) fonts, embedded = _get_fonts_walk(cast(DictionaryObject, obj[PG.RESOURCES])) unembedded = fonts - embedded return embedded, unembedded
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1901-L1912
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
91.202346
12
2
100
4
def _get_fonts(self) -> Tuple[Set[str], Set[str]]: obj = self.get_object() assert isinstance(obj, DictionaryObject) fonts, embedded = _get_fonts_walk(cast(DictionaryObject, obj[PG.RESOURCES])) unembedded = fonts - embedded return embedded, unembedded
24,105
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mediaBox
(self)
return self.mediabox
.. deprecated:: 1.28.0 Use :py:attr:`mediabox` instead.
.. deprecated:: 1.28.0
1,922
1,929
def mediaBox(self) -> RectangleObject: # deprecated """ .. deprecated:: 1.28.0 Use :py:attr:`mediabox` instead. """ deprecation_with_replacement("mediaBox", "mediabox", "3.0.0") return self.mediabox
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1922-L1929
39
[]
0
[]
0
false
91.202346
8
1
100
3
def mediaBox(self) -> RectangleObject: # deprecated deprecation_with_replacement("mediaBox", "mediabox", "3.0.0") return self.mediabox
24,106
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.mediaBox
(self, value: RectangleObject)
.. deprecated:: 1.28.0 Use :py:attr:`mediabox` instead.
.. deprecated:: 1.28.0
1,932
1,939
def mediaBox(self, value: RectangleObject) -> None: # deprecated """ .. deprecated:: 1.28.0 Use :py:attr:`mediabox` instead. """ deprecation_with_replacement("mediaBox", "mediabox", "3.0.0") self.mediabox = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1932-L1939
39
[]
0
[]
0
false
91.202346
8
1
100
3
def mediaBox(self, value: RectangleObject) -> None: # deprecated deprecation_with_replacement("mediaBox", "mediabox", "3.0.0") self.mediabox = value
24,107
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.cropBox
(self)
return self.cropbox
.. deprecated:: 1.28.0 Use :py:attr:`cropbox` instead.
.. deprecated:: 1.28.0
1,951
1,958
def cropBox(self) -> RectangleObject: # deprecated """ .. deprecated:: 1.28.0 Use :py:attr:`cropbox` instead. """ deprecation_with_replacement("cropBox", "cropbox", "3.0.0") return self.cropbox
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1951-L1958
39
[]
0
[]
0
false
91.202346
8
1
100
3
def cropBox(self) -> RectangleObject: # deprecated deprecation_with_replacement("cropBox", "cropbox", "3.0.0") return self.cropbox
24,108
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.cropBox
(self, value: RectangleObject)
1,961
1,963
def cropBox(self, value: RectangleObject) -> None: # deprecated deprecation_with_replacement("cropBox", "cropbox", "3.0.0") self.cropbox = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1961-L1963
39
[]
0
[]
0
false
91.202346
3
1
100
0
def cropBox(self, value: RectangleObject) -> None: # deprecated deprecation_with_replacement("cropBox", "cropbox", "3.0.0") self.cropbox = value
24,109
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.bleedBox
(self)
return self.bleedbox
.. deprecated:: 1.28.0 Use :py:attr:`bleedbox` instead.
.. deprecated:: 1.28.0
1,973
1,980
def bleedBox(self) -> RectangleObject: # deprecated """ .. deprecated:: 1.28.0 Use :py:attr:`bleedbox` instead. """ deprecation_with_replacement("bleedBox", "bleedbox", "3.0.0") return self.bleedbox
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1973-L1980
39
[]
0
[]
0
false
91.202346
8
1
100
3
def bleedBox(self) -> RectangleObject: # deprecated deprecation_with_replacement("bleedBox", "bleedbox", "3.0.0") return self.bleedbox
24,110
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.bleedBox
(self, value: RectangleObject)
1,983
1,985
def bleedBox(self, value: RectangleObject) -> None: # deprecated deprecation_with_replacement("bleedBox", "bleedbox", "3.0.0") self.bleedbox = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1983-L1985
39
[]
0
[]
0
false
91.202346
3
1
100
0
def bleedBox(self, value: RectangleObject) -> None: # deprecated deprecation_with_replacement("bleedBox", "bleedbox", "3.0.0") self.bleedbox = value
24,111
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.trimBox
(self)
return self.trimbox
.. deprecated:: 1.28.0 Use :py:attr:`trimbox` instead.
.. deprecated:: 1.28.0
1,994
2,001
def trimBox(self) -> RectangleObject: # deprecated """ .. deprecated:: 1.28.0 Use :py:attr:`trimbox` instead. """ deprecation_with_replacement("trimBox", "trimbox", "3.0.0") return self.trimbox
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L1994-L2001
39
[]
0
[]
0
false
91.202346
8
1
100
3
def trimBox(self) -> RectangleObject: # deprecated deprecation_with_replacement("trimBox", "trimbox", "3.0.0") return self.trimbox
24,112
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.trimBox
(self, value: RectangleObject)
2,004
2,006
def trimBox(self, value: RectangleObject) -> None: # deprecated deprecation_with_replacement("trimBox", "trimbox", "3.0.0") self.trimbox = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L2004-L2006
39
[]
0
[]
0
false
91.202346
3
1
100
0
def trimBox(self, value: RectangleObject) -> None: # deprecated deprecation_with_replacement("trimBox", "trimbox", "3.0.0") self.trimbox = value
24,113
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.artBox
(self)
return self.artbox
.. deprecated:: 1.28.0 Use :py:attr:`artbox` instead.
.. deprecated:: 1.28.0
2,016
2,023
def artBox(self) -> RectangleObject: # deprecated """ .. deprecated:: 1.28.0 Use :py:attr:`artbox` instead. """ deprecation_with_replacement("artBox", "artbox", "3.0.0") return self.artbox
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L2016-L2023
39
[]
0
[]
0
false
91.202346
8
1
100
3
def artBox(self) -> RectangleObject: # deprecated deprecation_with_replacement("artBox", "artbox", "3.0.0") return self.artbox
24,114
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.artBox
(self, value: RectangleObject)
2,026
2,028
def artBox(self, value: RectangleObject) -> None: # deprecated deprecation_with_replacement("artBox", "artbox", "3.0.0") self.artbox = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L2026-L2028
39
[]
0
[]
0
false
91.202346
3
1
100
0
def artBox(self, value: RectangleObject) -> None: # deprecated deprecation_with_replacement("artBox", "artbox", "3.0.0") self.artbox = value
24,115
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.annotations
(self)
2,031
2,035
def annotations(self) -> Optional[ArrayObject]: if "/Annots" not in self: return None else: return cast(ArrayObject, self["/Annots"])
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L2031-L2035
39
[ 0, 1, 2, 4 ]
80
[]
0
false
91.202346
5
2
100
0
def annotations(self) -> Optional[ArrayObject]: if "/Annots" not in self: return None else: return cast(ArrayObject, self["/Annots"])
24,116
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
PageObject.annotations
(self, value: Optional[ArrayObject])
Set the annotations array of the page. Typically you don't want to set this value, but append to it. If you append to it, don't forget to add the object first to the writer and only add the indirect object.
Set the annotations array of the page.
2,038
2,049
def annotations(self, value: Optional[ArrayObject]) -> None: """ Set the annotations array of the page. Typically you don't want to set this value, but append to it. If you append to it, don't forget to add the object first to the writer and only add the indirect object. """ if value is None: del self[NameObject("/Annots")] else: self[NameObject("/Annots")] = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L2038-L2049
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
91.202346
12
2
100
5
def annotations(self, value: Optional[ArrayObject]) -> None: if value is None: del self[NameObject("/Annots")] else: self[NameObject("/Annots")] = value
24,117
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
_VirtualList.__init__
( self, length_function: Callable[[], int], get_function: Callable[[int], PageObject], )
2,053
2,060
def __init__( self, length_function: Callable[[], int], get_function: Callable[[int], PageObject], ) -> None: self.length_function = length_function self.get_function = get_function self.current = -1
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L2053-L2060
39
[ 0, 5, 6, 7 ]
50
[]
0
false
91.202346
8
1
100
0
def __init__( self, length_function: Callable[[], int], get_function: Callable[[int], PageObject], ) -> None: self.length_function = length_function self.get_function = get_function self.current = -1
24,118
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
_VirtualList.__len__
(self)
return self.length_function()
2,062
2,063
def __len__(self) -> int: return self.length_function()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L2062-L2063
39
[ 0, 1 ]
100
[]
0
true
91.202346
2
1
100
0
def __len__(self) -> int: return self.length_function()
24,119
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
_VirtualList.__getitem__
(self, index: int)
return self.get_function(index)
2,065
2,078
def __getitem__(self, index: int) -> PageObject: if isinstance(index, slice): indices = range(*index.indices(len(self))) cls = type(self) return cls(indices.__len__, lambda idx: self[indices[idx]]) # type: ignore if not isinstance(index, int): raise TypeError("sequence indices must be integers") len_self = len(self) if index < 0: # support negative indexes index = len_self + index if index < 0 or index >= len_self: raise IndexError("sequence index out of range") return self.get_function(index)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L2065-L2078
39
[ 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13 ]
92.857143
[ 6 ]
7.142857
false
91.202346
14
6
92.857143
0
def __getitem__(self, index: int) -> PageObject: if isinstance(index, slice): indices = range(*index.indices(len(self))) cls = type(self) return cls(indices.__len__, lambda idx: self[indices[idx]]) # type: ignore if not isinstance(index, int): raise TypeError("sequence indices must be integers") len_self = len(self) if index < 0: # support negative indexes index = len_self + index if index < 0 or index >= len_self: raise IndexError("sequence index out of range") return self.get_function(index)
24,120
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page.py
_VirtualList.__iter__
(self)
2,080
2,082
def __iter__(self) -> Iterator[PageObject]: for i in range(len(self)): yield self[i]
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page.py#L2080-L2082
39
[ 0, 1, 2 ]
100
[]
0
true
91.202346
3
2
100
0
def __iter__(self) -> Iterator[PageObject]: for i in range(len(self)): yield self[i]
24,121
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page_labels.py
number2uppercase_roman_numeral
(num: int)
return "".join([a for a in roman_num(num)])
66
91
def number2uppercase_roman_numeral(num: int) -> str: roman = [ (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"), (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"), ] def roman_num(num: int) -> Iterator[str]: for decimal, roman_repr in roman: x, _ = divmod(num, decimal) yield roman_repr * x num -= decimal * x if num <= 0: break return "".join([a for a in roman_num(num)])
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page_labels.py#L66-L91
39
[ 0, 1, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ]
46.153846
[]
0
false
46.153846
26
5
100
0
def number2uppercase_roman_numeral(num: int) -> str: roman = [ (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"), (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"), ] def roman_num(num: int) -> Iterator[str]: for decimal, roman_repr in roman: x, _ = divmod(num, decimal) yield roman_repr * x num -= decimal * x if num <= 0: break return "".join([a for a in roman_num(num)])
24,122
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page_labels.py
number2lowercase_roman_numeral
(number: int)
return number2uppercase_roman_numeral(number).lower()
94
95
def number2lowercase_roman_numeral(number: int) -> str: return number2uppercase_roman_numeral(number).lower()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page_labels.py#L94-L95
39
[ 0, 1 ]
100
[]
0
true
46.153846
2
1
100
0
def number2lowercase_roman_numeral(number: int) -> str: return number2uppercase_roman_numeral(number).lower()
24,123
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page_labels.py
number2uppercase_letter
(number: int)
return rep
98
111
def number2uppercase_letter(number: int) -> str: if number <= 0: raise ValueError("Expecting a positive number") alphabet = [chr(i) for i in range(ord("A"), ord("Z") + 1)] rep = "" while number > 0: remainder = number % 26 if remainder == 0: remainder = 26 rep = alphabet[remainder - 1] + rep # update number -= remainder number = number // 26 return rep
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page_labels.py#L98-L111
39
[ 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
92.857143
[ 2 ]
7.142857
false
46.153846
14
5
92.857143
0
def number2uppercase_letter(number: int) -> str: if number <= 0: raise ValueError("Expecting a positive number") alphabet = [chr(i) for i in range(ord("A"), ord("Z") + 1)] rep = "" while number > 0: remainder = number % 26 if remainder == 0: remainder = 26 rep = alphabet[remainder - 1] + rep # update number -= remainder number = number // 26 return rep
24,124
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page_labels.py
number2lowercase_letter
(number: int)
return number2uppercase_letter(number).lower()
114
115
def number2lowercase_letter(number: int) -> str: return number2uppercase_letter(number).lower()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page_labels.py#L114-L115
39
[ 0, 1 ]
100
[]
0
true
46.153846
2
1
100
0
def number2lowercase_letter(number: int) -> str: return number2uppercase_letter(number).lower()
24,125
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/_page_labels.py
index2label
(reader: PdfReaderProtocol, index: int)
return str(index + 1)
See 7.9.7 "Number Trees". Args: reader: The PdfReader index: The index of the page Returns: The label of the page, e.g. "iv" or "4".
See 7.9.7 "Number Trees".
118
178
def index2label(reader: PdfReaderProtocol, index: int) -> str: """ See 7.9.7 "Number Trees". Args: reader: The PdfReader index: The index of the page Returns: The label of the page, e.g. "iv" or "4". """ root = reader.trailer["/Root"] if "/PageLabels" not in root: return str(index + 1) # Fallback number_tree = root["/PageLabels"] if "/Nums" in number_tree: # [Nums] shall be an array of the form # [ key 1 value 1 key 2 value 2 ... key n value n ] # where each key_i is an integer and the corresponding # value_i shall be the object associated with that key. # The keys shall be sorted in numerical order, # analogously to the arrangement of keys in a name tree # as described in 7.9.6, "Name Trees." nums = number_tree["/Nums"] i = 0 value = None start_index = 0 while i < len(nums): start_index = nums[i] value = nums[i + 1] if i + 2 == len(nums): break if nums[i + 2] > index: break i += 2 m = { None: lambda n: "", "/D": lambda n: str(n), "/R": number2uppercase_roman_numeral, "/r": number2lowercase_roman_numeral, "/A": number2uppercase_letter, "/a": number2lowercase_letter, } if not isinstance(value, dict): value = reader.get_object(value) if not isinstance(value, dict): return str(index + 1) # Fallback start = value.get("/St", 1) prefix = value.get("/P", "") return prefix + m[value.get("/S")](index - start_index + start) if "/Kids" in number_tree or "/Limits" in number_tree: logger_warning( ( "/Kids or /Limits found in PageLabels. " "Please share this PDF with pypdf: " "https://github.com/py-pdf/pypdf/pull/1519" ), __name__, ) # TODO: Implement /Kids and /Limits for number tree return str(index + 1)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/_page_labels.py#L118-L178
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
18.032787
[ 11, 12, 13, 14, 15, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 43, 44, 45, 46, 47, 48, 49, 50, 51, 60 ]
45.901639
false
46.153846
61
10
54.098361
8
def index2label(reader: PdfReaderProtocol, index: int) -> str: root = reader.trailer["/Root"] if "/PageLabels" not in root: return str(index + 1) # Fallback number_tree = root["/PageLabels"] if "/Nums" in number_tree: # [Nums] shall be an array of the form # [ key 1 value 1 key 2 value 2 ... key n value n ] # where each key_i is an integer and the corresponding # value_i shall be the object associated with that key. # The keys shall be sorted in numerical order, # analogously to the arrangement of keys in a name tree # as described in 7.9.6, "Name Trees." nums = number_tree["/Nums"] i = 0 value = None start_index = 0 while i < len(nums): start_index = nums[i] value = nums[i + 1] if i + 2 == len(nums): break if nums[i + 2] > index: break i += 2 m = { None: lambda n: "", "/D": lambda n: str(n), "/R": number2uppercase_roman_numeral, "/r": number2lowercase_roman_numeral, "/A": number2uppercase_letter, "/a": number2lowercase_letter, } if not isinstance(value, dict): value = reader.get_object(value) if not isinstance(value, dict): return str(index + 1) # Fallback start = value.get("/St", 1) prefix = value.get("/P", "") return prefix + m[value.get("/S")](index - start_index + start) if "/Kids" in number_tree or "/Limits" in number_tree: logger_warning( ( "/Kids or /Limits found in PageLabels. " "Please share this PDF with pypdf: " "https://github.com/py-pdf/pypdf/pull/1519" ), __name__, ) # TODO: Implement /Kids and /Limits for number tree return str(index + 1)
24,126
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
_identity
(value: K)
return value
85
86
def _identity(value: K) -> K: return value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L85-L86
39
[ 0, 1 ]
100
[]
0
true
94.078947
2
1
100
0
def _identity(value: K) -> K: return value
24,127
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
_converter_date
(value: str)
return dt
89
113
def _converter_date(value: str) -> datetime.datetime: matches = iso8601.match(value) if matches is None: raise ValueError(f"Invalid date format: {value}") year = int(matches.group("year")) month = int(matches.group("month") or "1") day = int(matches.group("day") or "1") hour = int(matches.group("hour") or "0") minute = int(matches.group("minute") or "0") second = decimal.Decimal(matches.group("second") or "0") seconds_dec = second.to_integral(decimal.ROUND_FLOOR) milliseconds_dec = (second - seconds_dec) * 1_000_000 seconds = int(seconds_dec) milliseconds = int(milliseconds_dec) tzd = matches.group("tzd") or "Z" dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds) if tzd != "Z": tzd_hours, tzd_minutes = (int(x) for x in tzd.split(":")) tzd_hours *= -1 if tzd_hours < 0: tzd_minutes *= -1 dt = dt + datetime.timedelta(hours=tzd_hours, minutes=tzd_minutes) return dt
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L89-L113
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 ]
100
[]
0
true
94.078947
25
10
100
0
def _converter_date(value: str) -> datetime.datetime: matches = iso8601.match(value) if matches is None: raise ValueError(f"Invalid date format: {value}") year = int(matches.group("year")) month = int(matches.group("month") or "1") day = int(matches.group("day") or "1") hour = int(matches.group("hour") or "0") minute = int(matches.group("minute") or "0") second = decimal.Decimal(matches.group("second") or "0") seconds_dec = second.to_integral(decimal.ROUND_FLOOR) milliseconds_dec = (second - seconds_dec) * 1_000_000 seconds = int(seconds_dec) milliseconds = int(milliseconds_dec) tzd = matches.group("tzd") or "Z" dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds) if tzd != "Z": tzd_hours, tzd_minutes = (int(x) for x in tzd.split(":")) tzd_hours *= -1 if tzd_hours < 0: tzd_minutes *= -1 dt = dt + datetime.timedelta(hours=tzd_hours, minutes=tzd_minutes) return dt
24,128
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
_getter_bag
( namespace: str, name: str )
return get
116
135
def _getter_bag( namespace: str, name: str ) -> Callable[["XmpInformation"], Optional[List[str]]]: def get(self: "XmpInformation") -> Optional[List[str]]: cached = self.cache.get(namespace, {}).get(name) if cached: return cached retval = [] for element in self.get_element("", namespace, name): bags = element.getElementsByTagNameNS(RDF_NAMESPACE, "Bag") if len(bags): for bag in bags: for item in bag.getElementsByTagNameNS(RDF_NAMESPACE, "li"): value = self._get_text(item) retval.append(value) ns_cache = self.cache.setdefault(namespace, {}) ns_cache[name] = retval return retval return get
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L116-L135
39
[ 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
90
[]
0
false
94.078947
20
7
100
0
def _getter_bag( namespace: str, name: str ) -> Callable[["XmpInformation"], Optional[List[str]]]: def get(self: "XmpInformation") -> Optional[List[str]]: cached = self.cache.get(namespace, {}).get(name) if cached: return cached retval = [] for element in self.get_element("", namespace, name): bags = element.getElementsByTagNameNS(RDF_NAMESPACE, "Bag") if len(bags): for bag in bags: for item in bag.getElementsByTagNameNS(RDF_NAMESPACE, "li"): value = self._get_text(item) retval.append(value) ns_cache = self.cache.setdefault(namespace, {}) ns_cache[name] = retval return retval return get
24,129
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
_getter_seq
( namespace: str, name: str, converter: Callable[[Any], Any] = _identity )
return get
138
161
def _getter_seq( namespace: str, name: str, converter: Callable[[Any], Any] = _identity ) -> Callable[["XmpInformation"], Optional[List[Any]]]: def get(self: "XmpInformation") -> Optional[List[Any]]: cached = self.cache.get(namespace, {}).get(name) if cached: return cached retval = [] for element in self.get_element("", namespace, name): seqs = element.getElementsByTagNameNS(RDF_NAMESPACE, "Seq") if len(seqs): for seq in seqs: for item in seq.getElementsByTagNameNS(RDF_NAMESPACE, "li"): value = self._get_text(item) value = converter(value) retval.append(value) else: value = converter(self._get_text(element)) retval.append(value) ns_cache = self.cache.setdefault(namespace, {}) ns_cache[name] = retval return retval return get
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L138-L161
39
[ 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 19, 20, 21, 22, 23 ]
79.166667
[ 17, 18 ]
8.333333
false
94.078947
24
7
91.666667
0
def _getter_seq( namespace: str, name: str, converter: Callable[[Any], Any] = _identity ) -> Callable[["XmpInformation"], Optional[List[Any]]]: def get(self: "XmpInformation") -> Optional[List[Any]]: cached = self.cache.get(namespace, {}).get(name) if cached: return cached retval = [] for element in self.get_element("", namespace, name): seqs = element.getElementsByTagNameNS(RDF_NAMESPACE, "Seq") if len(seqs): for seq in seqs: for item in seq.getElementsByTagNameNS(RDF_NAMESPACE, "li"): value = self._get_text(item) value = converter(value) retval.append(value) else: value = converter(self._get_text(element)) retval.append(value) ns_cache = self.cache.setdefault(namespace, {}) ns_cache[name] = retval return retval return get
24,130
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
_getter_langalt
( namespace: str, name: str )
return get
164
185
def _getter_langalt( namespace: str, name: str ) -> Callable[["XmpInformation"], Optional[Dict[Any, Any]]]: def get(self: "XmpInformation") -> Optional[Dict[Any, Any]]: cached = self.cache.get(namespace, {}).get(name) if cached: return cached retval = {} for element in self.get_element("", namespace, name): alts = element.getElementsByTagNameNS(RDF_NAMESPACE, "Alt") if len(alts): for alt in alts: for item in alt.getElementsByTagNameNS(RDF_NAMESPACE, "li"): value = self._get_text(item) retval[item.getAttribute("xml:lang")] = value else: retval["x-default"] = self._get_text(element) ns_cache = self.cache.setdefault(namespace, {}) ns_cache[name] = retval return retval return get
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L164-L185
39
[ 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21 ]
81.818182
[ 16 ]
4.545455
false
94.078947
22
7
95.454545
0
def _getter_langalt( namespace: str, name: str ) -> Callable[["XmpInformation"], Optional[Dict[Any, Any]]]: def get(self: "XmpInformation") -> Optional[Dict[Any, Any]]: cached = self.cache.get(namespace, {}).get(name) if cached: return cached retval = {} for element in self.get_element("", namespace, name): alts = element.getElementsByTagNameNS(RDF_NAMESPACE, "Alt") if len(alts): for alt in alts: for item in alt.getElementsByTagNameNS(RDF_NAMESPACE, "li"): value = self._get_text(item) retval[item.getAttribute("xml:lang")] = value else: retval["x-default"] = self._get_text(element) ns_cache = self.cache.setdefault(namespace, {}) ns_cache[name] = retval return retval return get
24,131
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
_getter_single
( namespace: str, name: str, converter: Callable[[str], Any] = _identity )
return get
188
208
def _getter_single( namespace: str, name: str, converter: Callable[[str], Any] = _identity ) -> Callable[["XmpInformation"], Optional[Any]]: def get(self: "XmpInformation") -> Optional[Any]: cached = self.cache.get(namespace, {}).get(name) if cached: return cached value = None for element in self.get_element("", namespace, name): if element.nodeType == element.ATTRIBUTE_NODE: value = element.nodeValue else: value = self._get_text(element) break if value is not None: value = converter(value) ns_cache = self.cache.setdefault(namespace, {}) ns_cache[name] = value return value return get
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L188-L208
39
[ 0, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
80.952381
[ 10 ]
4.761905
false
94.078947
21
6
95.238095
0
def _getter_single( namespace: str, name: str, converter: Callable[[str], Any] = _identity ) -> Callable[["XmpInformation"], Optional[Any]]: def get(self: "XmpInformation") -> Optional[Any]: cached = self.cache.get(namespace, {}).get(name) if cached: return cached value = None for element in self.get_element("", namespace, name): if element.nodeType == element.ATTRIBUTE_NODE: value = element.nodeValue else: value = self._get_text(element) break if value is not None: value = converter(value) ns_cache = self.cache.setdefault(namespace, {}) ns_cache[name] = value return value return get
24,132
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.__init__
(self, stream: ContentStream)
221
231
def __init__(self, stream: ContentStream) -> None: self.stream = stream try: data = self.stream.get_data() doc_root: Document = parseString(data) except ExpatError as e: raise PdfReadError(f"XML in XmpInformation was invalid: {e}") self.rdf_root: XmlElement = doc_root.getElementsByTagNameNS( RDF_NAMESPACE, "RDF" )[0] self.cache: Dict[Any, Any] = {}
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L221-L231
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 10 ]
81.818182
[]
0
false
94.078947
11
2
100
0
def __init__(self, stream: ContentStream) -> None: self.stream = stream try: data = self.stream.get_data() doc_root: Document = parseString(data) except ExpatError as e: raise PdfReadError(f"XML in XmpInformation was invalid: {e}") self.rdf_root: XmlElement = doc_root.getElementsByTagNameNS( RDF_NAMESPACE, "RDF" )[0] self.cache: Dict[Any, Any] = {}
24,133
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.rdfRoot
(self)
return self.rdf_root
234
236
def rdfRoot(self) -> XmlElement: # deprecated deprecate_with_replacement("rdfRoot", "rdf_root", "4.0.0") return self.rdf_root
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L234-L236
39
[]
0
[]
0
false
94.078947
3
1
100
0
def rdfRoot(self) -> XmlElement: # deprecated deprecate_with_replacement("rdfRoot", "rdf_root", "4.0.0") return self.rdf_root
24,134
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.write_to_stream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
238
241
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: self.stream.write_to_stream(stream, encryption_key)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L238-L241
39
[ 0 ]
25
[ 3 ]
25
false
94.078947
4
1
75
0
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: self.stream.write_to_stream(stream, encryption_key)
24,135
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.writeToStream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
.. deprecated:: 1.28.0 Use :meth:`write_to_stream` instead.
.. deprecated:: 1.28.0
243
252
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`write_to_stream` instead. """ deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L243-L252
39
[]
0
[]
0
false
94.078947
10
1
100
3
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
24,136
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.get_element
(self, about_uri: str, namespace: str, name: str)
254
260
def get_element(self, about_uri: str, namespace: str, name: str) -> Iterator[Any]: for desc in self.rdf_root.getElementsByTagNameNS(RDF_NAMESPACE, "Description"): if desc.getAttributeNS(RDF_NAMESPACE, "about") == about_uri: attr = desc.getAttributeNodeNS(namespace, name) if attr is not None: yield attr yield from desc.getElementsByTagNameNS(namespace, name)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L254-L260
39
[ 0, 1, 2, 3, 4, 6 ]
85.714286
[ 5 ]
14.285714
false
94.078947
7
4
85.714286
0
def get_element(self, about_uri: str, namespace: str, name: str) -> Iterator[Any]: for desc in self.rdf_root.getElementsByTagNameNS(RDF_NAMESPACE, "Description"): if desc.getAttributeNS(RDF_NAMESPACE, "about") == about_uri: attr = desc.getAttributeNodeNS(namespace, name) if attr is not None: yield attr yield from desc.getElementsByTagNameNS(namespace, name)
24,137
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.getElement
( self, aboutUri: str, namespace: str, name: str )
return self.get_element(aboutUri, namespace, name)
.. deprecated:: 1.28.0 Use :meth:`get_element` instead.
.. deprecated:: 1.28.0
262
271
def getElement( self, aboutUri: str, namespace: str, name: str ) -> Iterator[Any]: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`get_element` instead. """ deprecation_with_replacement("getElement", "get_element", "3.0.0") return self.get_element(aboutUri, namespace, name)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L262-L271
39
[]
0
[]
0
false
94.078947
10
1
100
3
def getElement( self, aboutUri: str, namespace: str, name: str ) -> Iterator[Any]: # deprecated deprecation_with_replacement("getElement", "get_element", "3.0.0") return self.get_element(aboutUri, namespace, name)
24,138
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.get_nodes_in_namespace
(self, about_uri: str, namespace: str)
273
282
def get_nodes_in_namespace(self, about_uri: str, namespace: str) -> Iterator[Any]: for desc in self.rdf_root.getElementsByTagNameNS(RDF_NAMESPACE, "Description"): if desc.getAttributeNS(RDF_NAMESPACE, "about") == about_uri: for i in range(desc.attributes.length): attr = desc.attributes.item(i) if attr.namespaceURI == namespace: yield attr for child in desc.childNodes: if child.namespaceURI == namespace: yield child
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L273-L282
39
[ 0, 1, 2, 3, 4, 5, 7, 8, 9 ]
90
[ 6 ]
10
false
94.078947
10
7
90
0
def get_nodes_in_namespace(self, about_uri: str, namespace: str) -> Iterator[Any]: for desc in self.rdf_root.getElementsByTagNameNS(RDF_NAMESPACE, "Description"): if desc.getAttributeNS(RDF_NAMESPACE, "about") == about_uri: for i in range(desc.attributes.length): attr = desc.attributes.item(i) if attr.namespaceURI == namespace: yield attr for child in desc.childNodes: if child.namespaceURI == namespace: yield child
24,139
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.getNodesInNamespace
( self, aboutUri: str, namespace: str )
return self.get_nodes_in_namespace(aboutUri, namespace)
.. deprecated:: 1.28.0 Use :meth:`get_nodes_in_namespace` instead.
.. deprecated:: 1.28.0
284
295
def getNodesInNamespace( self, aboutUri: str, namespace: str ) -> Iterator[Any]: # deprecated """ .. deprecated:: 1.28.0 Use :meth:`get_nodes_in_namespace` instead. """ deprecation_with_replacement( "getNodesInNamespace", "get_nodes_in_namespace", "3.0.0" ) return self.get_nodes_in_namespace(aboutUri, namespace)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L284-L295
39
[]
0
[]
0
false
94.078947
12
1
100
3
def getNodesInNamespace( self, aboutUri: str, namespace: str ) -> Iterator[Any]: # deprecated deprecation_with_replacement( "getNodesInNamespace", "get_nodes_in_namespace", "3.0.0" ) return self.get_nodes_in_namespace(aboutUri, namespace)
24,140
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation._get_text
(self, element: XmlElement)
return text
297
302
def _get_text(self, element: XmlElement) -> str: text = "" for child in element.childNodes: if child.nodeType == child.TEXT_NODE: text += child.data return text
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L297-L302
39
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
94.078947
6
3
100
0
def _get_text(self, element: XmlElement) -> str: text = "" for child in element.childNodes: if child.nodeType == child.TEXT_NODE: text += child.data return text
24,141
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmp_createDate
(self)
return self.xmp_create_date
410
412
def xmp_createDate(self) -> datetime.datetime: # deprecated deprecate_with_replacement("xmp_createDate", "xmp_create_date", "4.0.0") return self.xmp_create_date
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L410-L412
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmp_createDate(self) -> datetime.datetime: # deprecated deprecate_with_replacement("xmp_createDate", "xmp_create_date", "4.0.0") return self.xmp_create_date
24,142
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmp_createDate
(self, value: datetime.datetime)
415
417
def xmp_createDate(self, value: datetime.datetime) -> None: # deprecated deprecate_with_replacement("xmp_createDate", "xmp_create_date", "4.0.0") self.xmp_create_date = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L415-L417
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmp_createDate(self, value: datetime.datetime) -> None: # deprecated deprecate_with_replacement("xmp_createDate", "xmp_create_date", "4.0.0") self.xmp_create_date = value
24,143
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmp_modifyDate
(self)
return self.xmp_modify_date
428
430
def xmp_modifyDate(self) -> datetime.datetime: # deprecated deprecate_with_replacement("xmp_modifyDate", "xmp_modify_date", "4.0.0") return self.xmp_modify_date
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L428-L430
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmp_modifyDate(self) -> datetime.datetime: # deprecated deprecate_with_replacement("xmp_modifyDate", "xmp_modify_date", "4.0.0") return self.xmp_modify_date
24,144
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmp_modifyDate
(self, value: datetime.datetime)
433
435
def xmp_modifyDate(self, value: datetime.datetime) -> None: # deprecated deprecate_with_replacement("xmp_modifyDate", "xmp_modify_date", "4.0.0") self.xmp_modify_date = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L433-L435
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmp_modifyDate(self, value: datetime.datetime) -> None: # deprecated deprecate_with_replacement("xmp_modifyDate", "xmp_modify_date", "4.0.0") self.xmp_modify_date = value
24,145
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmp_metadataDate
(self)
return self.xmp_metadata_date
447
449
def xmp_metadataDate(self) -> datetime.datetime: # deprecated deprecate_with_replacement("xmp_metadataDate", "xmp_metadata_date", "4.0.0") return self.xmp_metadata_date
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L447-L449
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmp_metadataDate(self) -> datetime.datetime: # deprecated deprecate_with_replacement("xmp_metadataDate", "xmp_metadata_date", "4.0.0") return self.xmp_metadata_date
24,146
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmp_metadataDate
(self, value: datetime.datetime)
452
454
def xmp_metadataDate(self, value: datetime.datetime) -> None: # deprecated deprecate_with_replacement("xmp_metadataDate", "xmp_metadata_date", "4.0.0") self.xmp_metadata_date = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L452-L454
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmp_metadataDate(self, value: datetime.datetime) -> None: # deprecated deprecate_with_replacement("xmp_metadataDate", "xmp_metadata_date", "4.0.0") self.xmp_metadata_date = value
24,147
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmp_creatorTool
(self)
return self.xmp_creator_tool
460
462
def xmp_creatorTool(self) -> str: # deprecated deprecation_with_replacement("xmp_creatorTool", "xmp_creator_tool", "3.0.0") return self.xmp_creator_tool
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L460-L462
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmp_creatorTool(self) -> str: # deprecated deprecation_with_replacement("xmp_creatorTool", "xmp_creator_tool", "3.0.0") return self.xmp_creator_tool
24,148
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmp_creatorTool
(self, value: str)
465
467
def xmp_creatorTool(self, value: str) -> None: # deprecated deprecation_with_replacement("xmp_creatorTool", "xmp_creator_tool", "3.0.0") self.xmp_creator_tool = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L465-L467
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmp_creatorTool(self, value: str) -> None: # deprecated deprecation_with_replacement("xmp_creatorTool", "xmp_creator_tool", "3.0.0") self.xmp_creator_tool = value
24,149
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmpmm_documentId
(self)
return self.xmpmm_document_id
475
477
def xmpmm_documentId(self) -> str: # deprecated deprecation_with_replacement("xmpmm_documentId", "xmpmm_document_id", "3.0.0") return self.xmpmm_document_id
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L475-L477
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmpmm_documentId(self) -> str: # deprecated deprecation_with_replacement("xmpmm_documentId", "xmpmm_document_id", "3.0.0") return self.xmpmm_document_id
24,150
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmpmm_documentId
(self, value: str)
480
482
def xmpmm_documentId(self, value: str) -> None: # deprecated deprecation_with_replacement("xmpmm_documentId", "xmpmm_document_id", "3.0.0") self.xmpmm_document_id = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L480-L482
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmpmm_documentId(self, value: str) -> None: # deprecated deprecation_with_replacement("xmpmm_documentId", "xmpmm_document_id", "3.0.0") self.xmpmm_document_id = value
24,151
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmpmm_instanceId
(self)
return cast(str, self.xmpmm_instance_id)
491
493
def xmpmm_instanceId(self) -> str: # deprecated deprecation_with_replacement("xmpmm_instanceId", "xmpmm_instance_id", "3.0.0") return cast(str, self.xmpmm_instance_id)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L491-L493
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmpmm_instanceId(self) -> str: # deprecated deprecation_with_replacement("xmpmm_instanceId", "xmpmm_instance_id", "3.0.0") return cast(str, self.xmpmm_instance_id)
24,152
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/xmp.py
XmpInformation.xmpmm_instanceId
(self, value: str)
496
498
def xmpmm_instanceId(self, value: str) -> None: # deprecated deprecation_with_replacement("xmpmm_instanceId", "xmpmm_instance_id", "3.0.0") self.xmpmm_instance_id = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/xmp.py#L496-L498
39
[]
0
[]
0
false
94.078947
3
1
100
0
def xmpmm_instanceId(self, value: str) -> None: # deprecated deprecation_with_replacement("xmpmm_instanceId", "xmpmm_instance_id", "3.0.0") self.xmpmm_instance_id = value
24,153