Save pictures to PDF
Project description
Save pictures to PDF — from the command line, or from your Python programs.
Requirements
Python 3.6 or higher is required. The only direct dependency is the wonderful reportlab library.
Installation
pip install pictureshow
As a command line tool
Usage:
usage: pictureshow [-h] [-p SIZE] [-L] [-m MARGIN] [-l LAYOUT] [-s] [-f] [-q]
[-v]
PIC [PIC ...] PDF
positional arguments:
PIC one or more input picture file paths
PDF output PDF file path
optional arguments:
-h, --help show this help message and exit
-p SIZE, --page-size SIZE
specify page size; default is A4
-L, --landscape force landscape orientation of page
-m MARGIN, --margin MARGIN
set width of empty space around pictures; default is
72 points (1 inch)
-l LAYOUT, --layout LAYOUT
specify grid layout of pictures on page; default is
1x1
-s, --stretch-small scale small pictures up to fit drawing area
-f, --force-overwrite
save output file even if filename exists
-q, --quiet suppress printing to stdout
-v, --version show program's version number and exit
Example 1
Save a single picture to PDF.
$ pictureshow pics/mandelbrot.png mandelbrot.pdf
Saved 1 picture to '/.../mandelbrot.pdf'
Result:
Example 2
Select pictures using a glob pattern, set half-inch margin and layout with 1x3 pictures per page.
$ pictureshow --margin=36 --layout=1x3 pics/noise*.* noise.pdf
Saved 5 pictures to '/.../noise.pdf'
Result:
Example 3
Select pictures using a glob pattern, set page to landscape Letter-sized, 2x2 pictures per page.
$ pictureshow pics/*.jpg jpg_pics.pdf -pLETTER -L -l2x2
Saved 4 pictures to '/.../jpg_pics.pdf'
Result:
As a Python library
Using the PictureShow class:
from pictureshow import PictureShow
pic_show = PictureShow('pics/mandelbrot.png', 'pics/darkcyan.jpg')
pic_show.save_pdf('pictures.pdf')
Result:
Using the pictures_to_pdf shortcut function:
from pictureshow import pictures_to_pdf
pictures_to_pdf('pics/mandelbrot.png', 'pics/darkcyan.jpg', 'pictures.pdf')
The example above will work as long as the output file is passed as the last positional argument. It is however recommended to always use a keyword argument:
from pictureshow import pictures_to_pdf
list_of_pictures = ['pics/mandelbrot.png', 'pics/darkcyan.jpg']
pictures_to_pdf(*list_of_pictures, pdf_file='pictures.pdf')
Another example, demonstrating all available keyword parameters:
from pathlib import Path
from pictureshow import pictures_to_pdf
list_of_pictures = sorted(Path.cwd().glob('pics/*green*'))
pictures_to_pdf(
*list_of_pictures,
pdf_file='green.pdf',
page_size='A5',
landscape=True,
margin=36,
layout=(2, 2),
stretch_small=True,
force_overwrite=True
)
Result:
The page_size and layout parameters can be specified either by a string or by a sequence of two numbers. For example, page_size='LETTER', layout='2x3' is equivalent to page_size=(72 * 8.5, 72 * 11), layout=(2, 3).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for pictureshow-0.3.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 822eda429f1c72fd7a369df6d01a63c6dfbdb644e1f530a13f22cf982f3e0e90 |
|
MD5 | 6a697f0d2f808718ba664fa749c0d9cb |
|
BLAKE2b-256 | 9118c0e74521e3f51d74ab727df4cabb651ba956ba6a029c1aa96e561c4b1112 |