converting multipage tiff to pdf python

Solutions on MaxInterview for converting multipage tiff to pdf python by the best coders in the world

showing results for - "converting multipage tiff to pdf python"
Ethann
05 Feb 2016
1$ img2pdf img1.png img2.jpg -o out.pdf
2
Irene
27 Sep 2019
1for i in....     
2            # Create one pdf file per tiff file
3            with open(str(i) + '.pdf', "wb") as f, io.BytesIO() as output:
4                img = PIL.Image.open(str(i) + '.tiff')
5                img.save(output, format='tiff')
6                f.write(img2pdf.convert(output.getvalue()))
7
8# merge the pdf file into one output pdf file
9pdf_writer = PdfFileWriter()
10
11output_file = publication_number + ".pdf"
12file_list = os.listdir()
13pdf_list = []
14for file in file_list:
15    if file.endswith(".pdf"):
16        pdf_list.append(file)
17pdf_list.sort(key=lambda f: int(
18    ''.join(filter(str.isdigit, f))))  # trier la liste d'image du plus petit au plus grand (et pas 1, 10, 11, 2, 3)
19
20for pdf_file in pdf_list:
21    pdf_reader = PdfFileReader(pdf_file)
22    for page in range(pdf_reader.getNumPages()):
23        pdf_writer.addPage(pdf_reader.getPage(page))
24with open(output_file, 'wb') as fh:
25    pdf_writer.write(fh)
26
27for i in range(1, max_page + 1):  
28    os.remove(str(i) + '.tiff')
29    os.remove(str(i) + '.pdf')
30