I wondered if I could manage to use Python to capture a jpg file with a scanner. First, import the required modules.
$ pip install reportlab
I also need PIL, so install it.
$ brew install libjpeg
http://www.pythonware.com/products/pil/ Download PIL from the above URL. After unzipping, move the directory with cd.
$ cd Imaging-1.1.7
$ sudo python setup.py install
For the time being, the script I came up with at the moment is as follows.
pdf.py
#!/user/bin/env python
# -*- coding: utf-8 -*-
from reportlab.pdfgen import canvas
from reportlab.rl_config import defaultPageSize
canvas = canvas.Canvas("sample.pdf")
PAGE_WIDTH = defaultPageSize[0]
PAGE_HEIGHT = defaultPageSize[1]
canvas.drawInlineImage("test.jpg ", 0, 0, PAGE_WIDTH, PAGE_HEIGHT)
canvas.save()
print ("Success")
PAGE_HEIGHT = defaultPageSize[1] Specify the page size as A4 with.
Read test.jpg in the same directory as the executable file pdf.py and convert it to PDF. That's it. I don't know what would happen if I converted a larger file. It has been confirmed that 840 x 1200 jpg files fit in A4.
Recommended Posts