Skip to content

Commit

Permalink
Handle first_page greater than last_page (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Belval authored Apr 30, 2019
1 parent 6474a65 commit 48ea7ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pdf2image/pdf2image.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def convert_from_path(pdf_path, dpi=200, output_folder=None, first_page=None, la
if last_page is None or last_page > page_count:
last_page = page_count

if first_page > last_page:
return []

auto_temp_dir = False
if output_folder is None and use_pdfcairo:
auto_temp_dir = True
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
setup(
name='pdf2image',

version='1.5.3',
version='1.5.4',

description='A wrapper around the pdftoppm and pdftocairo command line tools to convert PDF to a PIL Image list.',
long_description=long_description,
Expand Down
18 changes: 18 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,5 +721,23 @@ def test_use_poppler_path_with_trailing_slash(self):
[im.close() for im in images_from_path]
print('test_conversion_from_path_using_poppler_path_with_trailing_slash: {} sec'.format((time.time() - start_time)))

## Test first page greater or equal to last_page

@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_14_first_page_1_last_page_1(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test_14.pdf', first_page=1, last_page=1)
self.assertTrue(len(images_from_path) == 1)
print('test_conversion_from_path_14: {} sec'.format((time.time() - start_time) / 14.))

@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_14_first_page_12_last_page_1(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test_14.pdf', first_page=12, last_page=1)
self.assertTrue(len(images_from_path) == 0)
print('test_conversion_from_path_14: {} sec'.format((time.time() - start_time) / 14.))

if __name__=='__main__':
unittest.main()

0 comments on commit 48ea7ac

Please sign in to comment.