Experiment to make a self-catering PDF for Kindle with Python

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

Experiment to make a self-catering PDF for Kindle with Python
I want to make a game with Python
Try to make a "cryptanalysis" cipher with Python
Try to make a dihedral group with Python
Make a fortune with Python
Let's make a GUI with python.
How to make a Python package (written for an intern)
Make a recommender system with python
Let's make a graph with python! !!
[5th] I tried to make a certain authenticator-like tool with python
Rubyist tried to make a simple API with Python + bottle + MySQL
[2nd] I tried to make a certain authenticator-like tool with python
[3rd] I tried to make a certain authenticator-like tool with python
How to make a surveillance camera (Security Camera) with Opencv and Python
I tried to make a periodical process with Selenium and Python
I tried to make a 2channel post notification application with Python
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I tried to make a todo application using bottle with python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
I tried to make a strange quote for Jojo with LSTM
Memo to ask for KPI with python
[Python] How to make a class iterable
Fractal to make and play with Python
Let's make a voice slowly with Python
Make Qt for Python app a desktop app
Let's make a web framework with Python! (1)
Make a desktop app with Python with Electron
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Python: I tried to make a flat / flat_map just right with a generator
Python beginners decided to make a LINE bot with Flask (Flask rough commentary)
[Introduction to Udemy Python3 + Application] 47. Process the dictionary with a for statement
Try to make a capture software with as high accuracy as possible with python (2)
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
How to read a CSV file with Python 2/3
Send a message to LINE with Python (LINE Notify)
Library comparison summary to generate PDF with Python
A memorandum to make WebDAV only with nginx
Convert PDF to image (JPEG / PNG) with Python
Make a Twitter trend bot with heroku + Python
[Python] Make a game with Pyxel-Use an editor-
Get a ticket for a theme park with python
[Concept] A strategy to analyze data with python and aim for a decline after shareholder benefits to make a profit
Create a LINE BOT with Minette for Python
Try to draw a life curve with python
How to make a dictionary with a hierarchical structure.
Procedure for creating a LineBot made with Python
[Python] Make a simple maze game with Pyxel
Decide to assign a laboratory with Python (fiction)
Steps to create a Twitter bot with python
Let's replace UWSC with Python (5) Let's make a Robot
Commands for creating a python3 environment with virtualenv
Let's make a module for Python using SWIG
I want to write to a file with Python
How to make Python faster for beginners [numpy]
A layman wants to get started with Python
Lark Basics (Python, Lark to make a shell-like guy)
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
I tried to make a simple mail sending application with tkinter of Python
[Patent analysis] I tried to make a patent map with Python without spending money