From 60593b5ad300ca1791aca7f1b8be541ded714b9f Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Fri, 5 Feb 2016 14:37:05 -0800 Subject: [PATCH 1/6] Tighten up package requirements to deal with incompatible img2pdf 0.2 release --- requirements.txt | 11 ++++++----- setup.py | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/requirements.txt b/requirements.txt index f36dafe9..7ba54a41 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -ruffus>=2.6.3 -Pillow>=2.4.0 -reportlab>=3.1.44 -PyPDF2>=1.25.1 -git+https://github.com/jbarlow83/img2pdf.git@e9bcce0afc3720752ca53a991db93f911a1df709#egg=img2pdf-0.1.5.dev +ruffus==2.6.3 +Pillow==3.1.1 +reportlab==3.2.0 +PyPDF2==1.25.1 +git+https://github.com/jbarlow83/img2pdf.git@0.1.5.dev + diff --git a/setup.py b/setup.py index 187e8ddb..1bd8b17e 100644 --- a/setup.py +++ b/setup.py @@ -210,11 +210,11 @@ setup( ], use_scm_version={'version_scheme': 'post-release'}, install_requires=[ - 'ruffus', - 'Pillow', - 'reportlab', - 'PyPDF2', - 'img2pdf' + 'ruffus>=2.6.3', + 'Pillow>=2.4.0', + 'reportlab>=3.1.44', + 'PyPDF2>=1.25.1', + 'img2pdf==0.1.5.dev' ], tests_require=tests_require, entry_points={ From e9b87cefccffc0afaf74f9531615a7617aee0e4a Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Fri, 5 Feb 2016 14:38:37 -0800 Subject: [PATCH 2/6] Try img2pdf 0.2 --- ocrmypdf/main.py | 10 ++++++++-- requirements.txt | 3 +-- setup.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ocrmypdf/main.py b/ocrmypdf/main.py index c8ade0ae..04eaf990 100755 --- a/ocrmypdf/main.py +++ b/ocrmypdf/main.py @@ -592,9 +592,15 @@ def select_image_layer( re_symlink(page_pdf, output_file) else: pageinfo = get_pageinfo(image, pdfinfo, pdfinfo_lock) - dpi = round(max(pageinfo['xres'], pageinfo['yres'], options.oversample)) + dpi = round(max(pageinfo['xres'], pageinfo['yres'], + options.oversample)) + imgsize = '{0}dpix{1}dpi'.format(dpi, dpi) + layout_fun = img2pdf.get_layout_fun(None, imgsize, None, None, None) + with open(output_file, 'wb') as pdf: - img2pdf.convert([image], dpi=dpi, outputstream=pdf) + pdf.write(img2pdf.convert( + [image], producer="img2pdf", with_pdfrw=False, + layout_fun=layout_fun)) @active_if(options.pdf_renderer == 'hocr') diff --git a/requirements.txt b/requirements.txt index 7ba54a41..18cb6b81 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,4 @@ ruffus==2.6.3 Pillow==3.1.1 reportlab==3.2.0 PyPDF2==1.25.1 -git+https://github.com/jbarlow83/img2pdf.git@0.1.5.dev - +img2pdf==0.2 diff --git a/setup.py b/setup.py index 1bd8b17e..243b94cd 100644 --- a/setup.py +++ b/setup.py @@ -214,7 +214,7 @@ setup( 'Pillow>=2.4.0', 'reportlab>=3.1.44', 'PyPDF2>=1.25.1', - 'img2pdf==0.1.5.dev' + 'img2pdf>=0.2.0' ], tests_require=tests_require, entry_points={ From daa3916430558c1923b2201bfc9cd6336043cf4c Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Fri, 5 Feb 2016 15:13:26 -0800 Subject: [PATCH 3/6] Fix img2pdf 0.2 usage All tests pass when forced to rely on img2pdf, so seems okay --- ocrmypdf/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ocrmypdf/main.py b/ocrmypdf/main.py index 04eaf990..fbd13769 100755 --- a/ocrmypdf/main.py +++ b/ocrmypdf/main.py @@ -165,9 +165,6 @@ parser.add_argument( '--skip-big', type=float, metavar='MPixels', help="skip OCR on pages larger than the specified amount of megapixels, " "but include skipped pages in final output") -# parser.add_argument( -# '--exact-image', action='store_true', -# help="Use original page from PDF without re-rendering") advanced = parser.add_argument_group( "Advanced", @@ -594,12 +591,15 @@ def select_image_layer( pageinfo = get_pageinfo(image, pdfinfo, pdfinfo_lock) dpi = round(max(pageinfo['xres'], pageinfo['yres'], options.oversample)) - imgsize = '{0}dpix{1}dpi'.format(dpi, dpi) + imgsize = ((img2pdf.ImgSize.dpi, dpi), (img2pdf.ImgSize.dpi, dpi)) + layout_fun = img2pdf.get_layout_fun(None, imgsize, None, None, None) - with open(output_file, 'wb') as pdf: + with open(image, 'rb') as imfile, \ + open(output_file, 'wb') as pdf: + rawdata = imfile.read() pdf.write(img2pdf.convert( - [image], producer="img2pdf", with_pdfrw=False, + rawdata, producer="img2pdf", with_pdfrw=False, layout_fun=layout_fun)) From 4abb20390dc7f881f25e2aad9d337c296123d67f Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Fri, 5 Feb 2016 16:08:26 -0800 Subject: [PATCH 4/6] Bump Dockerfile versions --- Dockerfile | 2 +- Dockerfile.polyglot | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d8134135..3db7f8d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # OCRmyPDF # -# VERSION 3.0.2 +# VERSION 3.2 FROM debian:stretch MAINTAINER James R. Barlow diff --git a/Dockerfile.polyglot b/Dockerfile.polyglot index f6288978..d52d4cb1 100644 --- a/Dockerfile.polyglot +++ b/Dockerfile.polyglot @@ -1,6 +1,6 @@ # OCRmyPDF polyglot # -# VERSION 3.0.2 +# VERSION 3.2 FROM jbarlow83/ocrmypdf:latest MAINTAINER James R. Barlow From 6fe32bbaf7089af06b756c04068a9b34b577893a Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Fri, 5 Feb 2016 16:10:18 -0800 Subject: [PATCH 5/6] v3.2.1 --- RELEASE_NOTES.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst index 3ed6177d..44db3d9e 100644 --- a/RELEASE_NOTES.rst +++ b/RELEASE_NOTES.rst @@ -6,8 +6,18 @@ Please always read this file before installing the package Download software here: https://github.com/jbarlow83/OCRmyPDF/tags +v3.2.1: +======= + +Changes +------- + +- Fixed issue #47 "convert() got and unexpected keyword argument 'dpi'" by upgrading to img2pdf 0.2 +- Tweaked the Dockerfiles + + v3.2: -========= +===== New features ------------ From 04cb8865b0d1267d1cd3ff955420eb7a2f455a98 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sat, 6 Feb 2016 18:18:30 -0800 Subject: [PATCH 6/6] Fetch application from PyPI instead of local setuptools_scm barfs because it can't find the version, because Docker hub retrieves the application from Github in a way that omits the necessary details. I suppose there is a certain logic to Docker only using the tagged released versions from PyPI, so go with it. The other attractive option is to nix setuptools_scm. --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3db7f8d3..9e7c12ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,13 +41,11 @@ RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/* RUN pyvenv /appenv \ && pyvenv --system-site-packages /appenv -COPY . /application/ - # Install application and dependencies # In this arrangement Pillow and reportlab will be provided by the system RUN . /appenv/bin/activate; \ pip install --upgrade pip \ - && pip install --no-cache-dir /application \ + && pip install ocrmypdf \ && pip install --no-cache-dir -r /application/test_requirements.txt USER docker