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))