pdfme.image
- class pdfme.image.PDFImage(image, extension=None, image_name=None)
Bases:
objectClass that represents a PDF image.
You can pass the location path (
strorpathlib.Pathformat) of the image, or pass a file-like object (io.BufferedIOBase) with the image bytes, the extension of the image, and the image name.Only JPEG and PNG image formats are supported in this moment. PNG images are converted to JPEG, and for this Pillow library is required.
- Parameters
image (str, pathlib.Path, BufferedIOBase) – The path or file-like object of the image.
extension (str, optional) – If
imageis path-like object, this argument should contain the extension of the image. Options are [jpg,jpeg,png].image_name (str, optional) – If
imageis path-like object, this argument should contain the name of the image. This name should be unique among the images added to the same PDF document.
- parse_jpg(bytes_)
Method to extract metadata from a JPEG image
bytes_needed to embed this image in a PDF document.This method creates this instance’s attibute
pdf_obj, containing a dict that can be added to apdfme.base.PDFBaseinstance as a PDF Stream object that represents this image.- Parameters
bytes (BufferedIOBase) – A file-like object containing the image.
- parse_png(bytes_)
Method to convert a PNG image to a JPEG image and later parse it as a JPEG image.
This method creates this instance’s attibute
pdf_obj, containing a dict that can be added to apdfme.base.PDFBaseinstance as a PDF Stream object that represents this image.- Parameters
bytes (BinaryIO) – A file-like object containing the image.