Skip to content

Commit a584fb5

Browse files
j-t-1stefan6419846
andauthored
DOC: Slightly improve the wording of PageObject (#2625)
* DOC: Slightly improve the wording of PageObject Also make metadata examples more concise * DOC: Slightly improve the wording of PageObject Also make metadata examples more concise --------- Co-authored-by: Stefan <[email protected]>
1 parent 99daf8e commit a584fb5

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

docs/user/metadata.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ reader = PdfReader("example.pdf")
99

1010
meta = reader.metadata
1111

12-
print(len(reader.pages))
13-
1412
# All of the following could be None!
1513
print(meta.title)
1614
print(meta.author)
@@ -34,9 +32,9 @@ writer = PdfWriter()
3432
for page in reader.pages:
3533
writer.add_page(page)
3634

37-
# If you want to add the old metadata, include this line
38-
metadata = reader.metadata
39-
writer.add_metadata(metadata)
35+
# If you want to add the old metadata, include these two lines
36+
if reader.metadata is not None:
37+
writer.add_metadata(reader.metadata)
4038

4139
# Format the current date and time for the metadata
4240
utc_time = "-05'00'" # UTC time optional

pypdf/_page.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def create_blank_page(
367367
from the last page of *pdf*.
368368
369369
Args:
370-
pdf: PDF file the page belongs to
370+
pdf: PDF file the page is within.
371371
width: The width of the new page expressed in default user
372372
space units.
373373
height: The height of the new page expressed in default user
@@ -651,7 +651,7 @@ def _get_inline_images(self) -> Dict[str, ImageFile]:
651651
@property
652652
def rotation(self) -> int:
653653
"""
654-
The VISUAL rotation of the page.
654+
The visual rotation of the page.
655655
656656
This number has to be a multiple of 90 degrees: 0, 90, 180, or 270 are
657657
valid values. This property does not affect ``/Contents``.
@@ -668,7 +668,7 @@ def transfer_rotation_to_content(self) -> None:
668668
Apply the rotation of the page to the content and the media/crop/...
669669
boxes.
670670
671-
It's recommended to apply this function before page merging.
671+
It is recommended to apply this function before page merging.
672672
"""
673673
r = -self.rotation # rotation to apply is in the otherway
674674
self.rotation = 0
@@ -862,8 +862,8 @@ def get_contents(self) -> Optional[ContentStream]:
862862
Access the page contents.
863863
864864
Returns:
865-
The ``/Contents`` object, or ``None`` if it doesn't exist.
866-
``/Contents`` is optional, as described in PDF Reference 7.7.3.3
865+
The ``/Contents`` object, or ``None`` if it does not exist.
866+
``/Contents`` is optional, as described in §7.7.3.3 of the PDF Reference.
867867
"""
868868
if PG.CONTENTS in self:
869869
try:
@@ -884,7 +884,7 @@ def replace_contents(
884884
"""
885885
Replace the page contents with the new content and nullify old objects
886886
Args:
887-
content : new content. if None delete the content field.
887+
content : new content; if None delete the content field.
888888
"""
889889
if not hasattr(self, "indirect_reference") or self.indirect_reference is None:
890890
# the page is not attached : the content is directly attached.
@@ -1077,7 +1077,7 @@ def _merge_page_writer(
10771077
expand: bool = False,
10781078
) -> None:
10791079
# First we work on merging the resource dictionaries. This allows us
1080-
# to find out what symbols in the content streams we might need to
1080+
# to find which symbols in the content streams we might need to
10811081
# rename.
10821082
assert isinstance(self.indirect_reference, IndirectObject)
10831083
pdf = self.indirect_reference.pdf
@@ -1496,10 +1496,10 @@ def compress_content_streams(self, level: int = -1) -> None:
14961496
@property
14971497
def page_number(self) -> Optional[int]:
14981498
"""
1499-
Read-only property which return the page number with the pdf file.
1499+
Read-only property which return the page number within the PDF file.
15001500
15011501
Returns:
1502-
int : page number ; None if the page is not attached to a pdf
1502+
int : page number; None if the page is not attached to a PDF
15031503
"""
15041504
if self.indirect_reference is None:
15051505
return None
@@ -1995,7 +1995,7 @@ def extract_text(
19951995
Do not rely on the order of text coming out of this function, as it
19961996
will change if this function is made more sophisticated.
19971997
1998-
Arabic, Hebrew,... are extracted in the good order.
1998+
Arabic and Hebrew are extracted in the correct order.
19991999
If required an custom RTL range of characters can be defined;
20002000
see function set_custom_rtl
20012001
@@ -2004,10 +2004,10 @@ def extract_text(
20042004
For example in some PDF files this can be useful to parse tables.
20052005
20062006
Args:
2007-
orientations: list of orientations text_extraction will look for
2007+
orientations: list of orientations extract_text will look for
20082008
default = (0, 90, 180, 270)
2009-
note: currently only 0(Up),90(turned Left), 180(upside Down),
2010-
270 (turned Right)
2009+
note: currently only 0 (up),90 (turned left), 180 (upside down),
2010+
270 (turned right)
20112011
space_width: force default space width
20122012
if not extracted from font (default: 200)
20132013
visitor_operand_before: function to be called before processing an operation.
@@ -2026,7 +2026,7 @@ def extract_text(
20262026
NOTE: orientations, space_width, and visitor_* parameters are NOT respected
20272027
in "layout" mode.
20282028
2029-
KwArgs:
2029+
kwargs:
20302030
layout_mode_space_vertically (bool): include blank lines inferred from
20312031
y distance + font height. Defaults to True.
20322032
layout_mode_scale_weight (float): multiplier for string length when calculating
@@ -2184,8 +2184,8 @@ def annotations(self, value: Optional[ArrayObject]) -> None:
21842184
"""
21852185
Set the annotations array of the page.
21862186
2187-
Typically you don't want to set this value, but append to it.
2188-
If you append to it, don't forget to add the object first to the writer
2187+
Typically you do not want to set this value, but append to it.
2188+
If you append to it, remember to add the object first to the writer
21892189
and only add the indirect object.
21902190
"""
21912191
if value is None:

0 commit comments

Comments
 (0)