Skip to content

Commit 9cde8dd

Browse files
authored
Add first and last page parameters to pdfinfo
1 parent 579a57c commit 9cde8dd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pdf2image/pdf2image.py

+20
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ def pdfinfo_from_path(
528528
poppler_path: str = None,
529529
rawdates: bool = False,
530530
timeout: int = None,
531+
first_page: int = None,
532+
last_page: int = None,
531533
) -> Dict:
532534
"""Function wrapping poppler's pdfinfo utility and returns the result as a dictionary.
533535
@@ -543,6 +545,10 @@ def pdfinfo_from_path(
543545
:type rawdates: bool, optional
544546
:param timeout: Raise PDFPopplerTimeoutError after the given time, defaults to None
545547
:type timeout: int, optional
548+
:param first_page: First page to process, defaults to None
549+
:type first_page: int, optional
550+
:param last_page: Last page to process before stopping, defaults to None
551+
:type last_page: int, optional
546552
:raises PDFPopplerTimeoutError: Raised after the timeout for the image processing is exceeded
547553
:raises PDFInfoNotInstalledError: Raised if pdfinfo is not installed
548554
:raises PDFPageCountError: Raised if the output could not be parsed
@@ -561,6 +567,12 @@ def pdfinfo_from_path(
561567
if rawdates:
562568
command.extend(["-rawdates"])
563569

570+
if first_page:
571+
command.extend(["-f", str(first_page)])
572+
573+
if last_page:
574+
command.extend(["-l", str(last_page)])
575+
564576
# Add poppler path to LD_LIBRARY_PATH
565577
env = os.environ.copy()
566578
if poppler_path is not None:
@@ -607,6 +619,8 @@ def pdfinfo_from_bytes(
607619
poppler_path: str = None,
608620
rawdates: bool = False,
609621
timeout: int = None,
622+
first_page: int = None,
623+
last_page: int = None,
610624
) -> Dict:
611625
"""Function wrapping poppler's pdfinfo utility and returns the result as a dictionary.
612626
@@ -622,6 +636,10 @@ def pdfinfo_from_bytes(
622636
:type rawdates: bool, optional
623637
:param timeout: Raise PDFPopplerTimeoutError after the given time, defaults to None
624638
:type timeout: int, optional
639+
:param first_page: First page to process, defaults to None
640+
:type first_page: int, optional
641+
:param last_page: Last page to process before stopping, defaults to None
642+
:type last_page: int, optional
625643
:return: Dictionary containing various information on the PDF
626644
:rtype: Dict
627645
"""
@@ -637,6 +655,8 @@ def pdfinfo_from_bytes(
637655
poppler_path=poppler_path,
638656
rawdates=rawdates,
639657
timeout=timeout,
658+
first_page=first_page,
659+
last_page=last_page,
640660
)
641661
finally:
642662
os.close(fh)

0 commit comments

Comments
 (0)