Save pictures to PDF.
Project description
Save pictures to PDF from the command line or from your Python programs.
Requirements
Installation
pip install pictureshow
Usage
As a command line tool
usage: pictureshow [-h] [-p SIZE] [-L] [-m MARGIN] [-l LAYOUT] [-s] [-f]
[-q | -v] [-V]
PIC [PIC ...] PDF
positional arguments:
PIC one or more input picture file paths
PDF target PDF file path
options:
-h, --help show this help message and exit
-p SIZE, --page-size SIZE
specify page size; default is A4
-L, --landscape set landscape orientation of page; default is
portrait
-m MARGIN, --margin MARGIN
set width of empty space around pictures; default is
72 (72 points = 1 inch)
-l LAYOUT, --layout LAYOUT
specify grid layout (columns x rows) of pictures on
page, e.g. 2x3 or 2,3; default is 1x1
-s, --stretch-small scale small pictures up to fit drawing area
-f, --force-overwrite
save target file even if filename exists
-q, --quiet suppress printing to stdout
-v, --verbose provide details on files skipped due to error
-V, --version show program's version number and exit
Example 1
Save single picture to PDF.
$ pictureshow pics/potato.jpg potato.pdf
Saved 1 picture (1 page) to 'potato.pdf'
Example 2
Save multiple pictures, four pictures per page (two columns, two rows), set page to landscape Letter-sized [1].
$ pictureshow --page-size=LETTER --landscape --layout=2x2 photos/* photos
Saved 50 pictures (13 pages) to 'photos.pdf'
Please note that if the target filename has no extension specified, .pdf will be appended to it. This only applies for the command line tool.
Example 3
Save pictures from URLs, set smaller margin and stretch small pictures.
$ pictureshow --margin=36 --stretch-small https://<picture.1.url> https://<picture.2.url> https://<picture.3.url> pics_from_web
Saved 3 pictures (3 pages) to 'pics_from_web.pdf'
As a Python library
Using the PictureShow class:
from pictureshow import PictureShow
pic_show = PictureShow('pics/cucumber.jpg', 'pics/onion.jpg')
pic_show.save_pdf('vegetables.pdf')
Using the pictures_to_pdf shortcut function:
from pictureshow import pictures_to_pdf
pictures_to_pdf('pics/cucumber.jpg', 'pics/onion.jpg', pdf_file='vegetables.pdf')
Please note that contrary to the PictureShow.save_pdf method, pdf_file must be specified as a keyword argument in the above example, because the pictures_to_pdf function treats all positional arguments as input files.
Another example, demonstrating all available keyword-only arguments:
from pathlib import Path
from pictureshow import pictures_to_pdf
list_of_pictures = Path.cwd().glob('pics/*')
pictures_to_pdf(
*list_of_pictures,
pdf_file='pictures.pdf',
page_size='A5',
landscape=True,
margin=18,
layout=(3, 2),
stretch_small=True,
force_overwrite=True
)
Footnotes
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.6.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e161dd4e853417c77c9d8bd4042a1a46814c1a00d8641edfead24e6c1badd85a |
|
MD5 | dc26f813698dc877cc4fb286bffedf9a |
|
BLAKE2b-256 | f5d8936a73227e39e67e451e6bac42b20e76f24e7148a8759c14921b41368120 |