Use img2pdf in test case because it does a better job

This commit is contained in:
James R. Barlow
2015-07-30 03:35:56 -07:00
parent 3d6264e1b8
commit 9918c4020e
2 changed files with 11 additions and 6 deletions
+7 -6
View File
@@ -10,6 +10,7 @@ import os
import sys
import shutil
import pytest
import img2pdf
from pkg_resources import Requirement, resource_filename
req = Requirement.parse('ocrmypdf')
@@ -47,16 +48,16 @@ def test_single_page_text():
def test_single_page_image():
filename = os.path.join(TEST_OUTPUT, 'image-mono.pdf')
pdf = Canvas(filename, pagesize=(72, 72))
with NamedTemporaryFile() as im_tmp:
im = Image.new('1', (8, 8), 0)
for n in range(8):
im.putpixel((n, n), 1)
im.save(im_tmp.name, format='PNG')
# Draw image in a 72x72 pt or 1"x1" area
pdf.drawImage(im_tmp.name, 0, 0, width=72, height=72)
pdf.showPage()
pdf.save()
pdf_bytes = img2pdf.convert([im_tmp.name], dpi=8)
with open(filename, 'wb') as pdf:
pdf.write(pdf_bytes)
pdfinfo = pageinfo.pdf_get_all_pageinfo(filename)
@@ -68,7 +69,7 @@ def test_single_page_image():
pdfimage = page['images'][0]
assert pdfimage['width'] == 8
# assert pdfimage['color'] == 'gray'
assert pdfimage['color'] == 'gray'
# While unexpected, this is correct
# PDF spec says /FlateDecode image must have /BitsPerComponent 8
+4
View File
@@ -204,6 +204,10 @@ setup(
'reportlab>=3.1.44',
'PyPDF2>=1.25.1'
],
test_requires=[
'img2pdf>=0.1.5',
'pytest>=2.7.2'
],
entry_points={
'console_scripts': [
'ocrmypdf = ocrmypdf.main:run_pipeline'