Skip to content

Commit 48ea7ac

Browse files
authored
Handle first_page greater than last_page (#66)
1 parent 6474a65 commit 48ea7ac

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

pdf2image/pdf2image.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def convert_from_path(pdf_path, dpi=200, output_folder=None, first_page=None, la
6767
if last_page is None or last_page > page_count:
6868
last_page = page_count
6969

70+
if first_page > last_page:
71+
return []
72+
7073
auto_temp_dir = False
7174
if output_folder is None and use_pdfcairo:
7275
auto_temp_dir = True

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
setup(
1313
name='pdf2image',
1414

15-
version='1.5.3',
15+
version='1.5.4',
1616

1717
description='A wrapper around the pdftoppm and pdftocairo command line tools to convert PDF to a PIL Image list.',
1818
long_description=long_description,

tests.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,5 +721,23 @@ def test_use_poppler_path_with_trailing_slash(self):
721721
[im.close() for im in images_from_path]
722722
print('test_conversion_from_path_using_poppler_path_with_trailing_slash: {} sec'.format((time.time() - start_time)))
723723

724+
## Test first page greater or equal to last_page
725+
726+
@profile
727+
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
728+
def test_conversion_from_path_14_first_page_1_last_page_1(self):
729+
start_time = time.time()
730+
images_from_path = convert_from_path('./tests/test_14.pdf', first_page=1, last_page=1)
731+
self.assertTrue(len(images_from_path) == 1)
732+
print('test_conversion_from_path_14: {} sec'.format((time.time() - start_time) / 14.))
733+
734+
@profile
735+
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
736+
def test_conversion_from_path_14_first_page_12_last_page_1(self):
737+
start_time = time.time()
738+
images_from_path = convert_from_path('./tests/test_14.pdf', first_page=12, last_page=1)
739+
self.assertTrue(len(images_from_path) == 0)
740+
print('test_conversion_from_path_14: {} sec'.format((time.time() - start_time) / 14.))
741+
724742
if __name__=='__main__':
725743
unittest.main()

0 commit comments

Comments
 (0)