Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

converting multipage tiff to pdf python

$ img2pdf img1.png img2.jpg -o out.pdf
Comment

converting multipage tiff to pdf python

for i in....     
            # Create one pdf file per tiff file
            with open(str(i) + '.pdf', "wb") as f, io.BytesIO() as output:
                img = PIL.Image.open(str(i) + '.tiff')
                img.save(output, format='tiff')
                f.write(img2pdf.convert(output.getvalue()))

# merge the pdf file into one output pdf file
pdf_writer = PdfFileWriter()

output_file = publication_number + ".pdf"
file_list = os.listdir()
pdf_list = []
for file in file_list:
    if file.endswith(".pdf"):
        pdf_list.append(file)
pdf_list.sort(key=lambda f: int(
    ''.join(filter(str.isdigit, f))))  # trier la liste d'image du plus petit au plus grand (et pas 1, 10, 11, 2, 3)

for pdf_file in pdf_list:
    pdf_reader = PdfFileReader(pdf_file)
    for page in range(pdf_reader.getNumPages()):
        pdf_writer.addPage(pdf_reader.getPage(page))
with open(output_file, 'wb') as fh:
    pdf_writer.write(fh)

for i in range(1, max_page + 1):  
    os.remove(str(i) + '.tiff')
    os.remove(str(i) + '.pdf')
Comment

PREVIOUS NEXT
Code Example
Python :: como agregar elementos a un array en python 
Python :: pip install not happening in python cmd 
Python :: pandas numpy multiplicar dos columnas segun una condicion 
Python :: david dobrik 
Python :: traduce query model 
Python :: loading .dat file in python 
Python :: plant python documentation 
Python :: bassie en adriaan 
Python :: directory corrente python 
Python :: when training= false still dropout 
Python :: fizz buzz python 
Python :: rabin karp algorithm 
Python :: bolumden kalan python 
Shell :: install git ec2 linux 
Shell :: amazon linux 2 install stress 
Shell :: docker delete all images 
Shell :: git change username email 
Shell :: ubuntu install telegram 
Shell :: update node version debian 
Shell :: reinstall mysql 
Shell :: install metasploitable on ubuntu 
Shell :: install pymysql 
Shell :: como instalar telegram ubuntu 
Shell :: find my ip mac terminal 
Shell :: uninstall postgres brew 
Shell :: check if nginx is running 
Shell :: apache enable mod reqrite 
Shell :: how to check linux distro from terminal 
Shell :: firebase : File C:UsersAbrar MahiAppDataRoaming pmfirebase.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at 
Shell :: Create React App requires Node 14 or higher. 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =