Questions tagged [img2pdf]

A Python package for lossless conversion of raster images to PDF.

The image embedded in the PDF will always have the exact same color information for every pixel as the input.

img2pdf homepage on Gitlab: https://gitlab.mister-muffin.de/josch/img2pdf

24 questions
3
votes
1 answer

(Python) Converting Hundreds of PNGs to a Single PDF

I have a folder with 452 images (.png) that I'm trying to merge into a single PDF file, using Python. Each of the images are labelled by their intended page number, e.g. "1.png", "2.png", ....., "452.png". This code was technically successful, but…
Dylan H.
  • 43
  • 5
2
votes
1 answer

Fetching, Rendering and Positioning images in a PDF file using Pyhon

I have a folder where i have stored multiple .bmp images, which I want to place in a .pdf file in a structured manner. Can anyone assist. Say I have 100 .bmp images in a folder named as image1, image2....image100. I want to display these images in…
Shantanu
  • 41
  • 4
2
votes
2 answers

img2pdf AlphaChannelError: what is the best way to remove alphachannel

I have set of images from which I create pdf by the following code with io.BytesIO() as tmp_io: tmp_io.write(img2pdf.convert(img_file_paths)) result_bytes = tmp_io.getvalue() One of files contains alpha channel and I got raise…
Ryabchenko Alexander
  • 10,057
  • 7
  • 56
  • 88
2
votes
3 answers

Invalid rotation when converting jpg to pdf with python

I'm trying to convert a jpg to pdf with img2pdf. It works with most jpg's but not all. Here is my script: import img2pdf import PIL.Image import os image = PIL.Image.open("Lidl.jpg") pdf_bytes = img2pdf.convert(image.filename) file = open(pdf_path,…
Kresten
  • 810
  • 13
  • 36
2
votes
2 answers

multiple tiff images to pdf with python

I have a image file list and I would like to generate a single output.pdf file with these images. The following code works with one image file only (here the first element of image_list): with open("output.pdf","wb") as f, io.BytesIO() as output: …
Mathias
  • 177
  • 2
  • 10
2
votes
1 answer

Using Pillow and img2pdf to convert images to pdf

I have a task that requires me to get data from an image upload (jpg or png), resize it based on the requirement, and then transform it into pdf and then store in s3. The file comes in as ByteIO I have Pillow available so I can resize the image…
JChao
  • 2,178
  • 5
  • 35
  • 65
1
vote
0 answers

Python: Img2Pdf is ordering images in the final PDF incorrectly despite naming conventions

EDIT: Thanks to a commenter I see that the root of the problem is that os.scandir is sorting arbitrarily. However I don't have the skills to follow through. So I have very little experience. I have a few dozen root-folders that are each full of…
Matt Bone
  • 11
  • 2
1
vote
1 answer

python Portrait and landscape page in pdf

I am new to python. I want to generate a pdf with 3 images, 1 image is a portrait, the second image is a landscape and the third image is a portrait again. But it seems the code below cannot handle this situation, am I missing anything? images =…
0
votes
0 answers

Converting very long images (800px x 12,000px) into PDF with img2pdf and image magick leaves large white spaces between images

I have 10 images that range from 800x8500 to 800x11500 with one of them being header/footer images that are 1100x875 that are intended to be stacked vertically, end to end (its a web comic meant to be read from top to bottom) but every time I try to…
sweet
  • 15
  • 1
  • 5
0
votes
0 answers

img2pdf key error when trying to convert to pdf

When trying to convert a list of .tif/.tiff files I run into a key error that is thrown from PIL package. I'm running the Anaconda diet on a Mac. I haven't been able to find many answers on why this happens. I can see that the list of images is 6…
0
votes
1 answer

Python: JPEGs from folder to a Multipage-PDF with img2pdf

I'm an newbie and I'm trying to create a multipage pdf with img2pdf (recursive), but only the last picture is saved in a pdf file. from pathlib import Path import os import img2pdf main_dir = Path(Path.cwd(),'MAIN') for subfolder in…
0
votes
1 answer

img2pdf not converting png to bytes

I have a script that turns my images into .pdf formats and assigns these their respective article name and author. I have two separate files for two different authors, the script works fine for one of the two, when it's not working I get the…
tesla john
  • 310
  • 1
  • 2
  • 9
0
votes
0 answers

How to combine images into a PDF ordered by the time that they were taken?

I am attempting to compile a folder of images into a single PDF by the order in which they were taken. os.getcwd() os.chdir(folder_path) a= glob.glob(folder_path) b = [os.path.getctime(i) for i in a] c = {} for i,j in list(zip(a,b)): c[i] =…
Dominic Naimool
  • 313
  • 2
  • 11
0
votes
1 answer

Python script violates the command-line character limit

I am using a Python script to batch convert many images in different folders into single pdfs (with https://pypi.org/project/img2pdf/): import os import subprocess import img2pdf from shutil import copyfile def main(): folders = [name for name…
qwertxyz
  • 143
  • 1
  • 7
0
votes
1 answer

TypeError: a bytes-like object is required, not 'str' while using img2pdf library

While using the img2pdf library I'm getting the above mentioned error, my code looks something like this, this is also the line of code that throws the above mentioned error pdf = img2pdf.convert('maskedImage'+ filename + '.jpeg') where filename is…
Nimish
  • 11
  • 4
1
2