PDF generator module

This module will create a pdf file containing all the images from an experiment, the sample name (prefix) of the images is used to group the images onto separate pages, and the image number is included below each image.

Usage

The simple usage of this is summed up below:

from SimpliPyTEM.PDF_generator import pdf_generator
#This generator gives a list of the images
Images = [x for x in os.listdir('Path/to/images/directory') if x[-3:]=='jpg']

#A pdf can then be generated by::
pdf_generator(Images, Title='Experiment title', Notes='Here are some notes about the experiment.....', directory='Path/to/images/directory' )

PDF files generated from this can be easily shared. However, if movies are required consider using html_writer

PDF_generator.find_number(string)

Function to find the idenfication number of the images so they can be labelled in the pdf.

Parameters

string: str

Filename which contains the image number

Returns

im_id:str

The ID number of the image

prefix:str

The prefix to the image id - normally contains details about the sample.

PDF_generator.group_images(images)

Sorts a number of images into a dictionary with images separated by the sample name, these can then be separated onto different pages.

Parameters

images:list

List of images (by filename)

Returns

organised_dict:dict

Dictionary containing the sample names (image prefixes) as the keys and a list of images with that name as the value.

PDF_generator.pdf_generator(images, title, notes, directory='', max_num=9)

Function for generating a pdf file showing images, this aims to make it easier to examine, evaluate and share images from a TEM session by putting them in a single document.

Parameters

images: list

A list of images to place in the pdf document. This can be easily created with a generator function, eg. images = [x for x in os.listdir(‘PATH/TO/DIRECTORY’) if x[-3:]==’jpg’]

title: str

A title for the experiment

notes: str

Experimental notes, need to be kept fairly short (a few sentances max), these will be placed on the first page.

directory: str

If being run outside of the directory containing the images, the path to the directory needs to be included here, by default it assumes the same directory.

max_num: int

The maximum number of images to include on a single pdf page, this can be 1,4,6 or 9 (default). Smaller number means larger images (but longer document)

Output

Saves a pdf document under the name {title}.pdf with the images contained within the list.

PDF_generator.return_coords(max_num)

Gives the coordinates for the images & captions, and the size of the images depending on the number per page.

Parameters

max_num:int

The number of images per page.

Returns

Image_coords:list

The coordinates for each image on the page

cap_coords:list

The coordinates for each caption on the page

size:int

The size of the images.