Ejemplo n.º 1
0
 def test_render_page(self):
     doc = PDFDocument.open('tests/assets/gre_research_validity_data.pdf')
     self.assertEqual(len(doc), 4)
     page = doc.render_page(0)
     self.assertIsInstance(page, Image.Image)
     self.assertEqual(page.size, (614, 793))
     self.assertEqual(page.mode, 'RGBA')
     self.assertEqual(page.getpixel((613, 792)), (249, 178, 10, 255))
     self.assertEqual(page.info['dpi'], (72, 72))
     self.assertFalse(doc.closed)
     doc.close()
     self.assertTrue(doc.closed)
Ejemplo n.º 2
0
 def test_open_from_file(self):
     with PDFDocument.open('tests/assets/1page.pdf') as doc:
         self.assertIsNotNone(doc)
         self.assertEqual(len(doc), 1)
         self.assertFalse(doc.closed)
     self.assertTrue(doc.closed)
Ejemplo n.º 3
0
 def test_render_page_invalid_index(self):
     doc = PDFDocument.open('tests/assets/gre_research_validity_data.pdf')
     with self.assertRaisesRegexp(ValueError, 'page index out of range'):
         doc.render_page(-1)
     with self.assertRaisesRegexp(ValueError, 'page index out of range'):
         doc.render_page(5)
Ejemplo n.º 4
0
 def test_render_page_higher_dpi(self):
     doc = PDFDocument.open('tests/assets/gre_research_validity_data.pdf')
     page = doc.render_page(0, dpi=150)
     self.assertEqual(page.size, (1279, 1653))
     doc.close()
Ejemplo n.º 5
0
 def test_open_password_protected_file_fails_throws_error(self):
     with self.assertRaisesRegexp(ValueError, 'invalid pdf file'):
         PDFDocument.open('tests/assets/password_locked.pdf')
Ejemplo n.º 6
0
 def test_open_from_corrupted_bytes_throws_error(self):
     with self.assertRaisesRegexp(ValueError, 'invalid pdf file'):
         PDFDocument.frombytes(b'foo')
Ejemplo n.º 7
0
 def test_open_from_buffer(self):
     with open('tests/assets/1page.pdf', 'rb') as f:
         doc = PDFDocument.frombytes(f.read())
         self.assertIsNotNone(doc)
         self.assertEqual(len(doc), 1)
Ejemplo n.º 8
0
 def test_open_corrupted_file_throws_error(self):
     with self.assertRaisesRegexp(ValueError, 'invalid pdf file'):
         PDFDocument.open('tests/assets/corrupted.pdf')
Ejemplo n.º 9
0
 def test_open_nonexisting_file_throws_error(self):
     with self.assertRaisesRegexp(ValueError, 'invalid pdf file'):
         PDFDocument.open('tests/assets/missing.pdf')