1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python Convert List Image to multiple PDF

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    In the case

    I have a folder of image list and list name file with csv

    I want to write a python script to convert list of PNG's to multiple pdf file with name file of pdf from csv file at column D

    like this: [​IMG]

    Then i have tried python code like this:

    import os
    import csv
    import img2pdf
    from PIL import Image

    # Set this to the folder with your files
    folder_path = r"C:\Users\dede\Desktop\product_report"
    # Set this to the name of your CSV
    csv_file = "product.csv"

    with open(os.path.join(folder_path, csv_file), newline='') as file:
    reader = csv.reader(file, delimiter='|')
    next(reader) # Skip header row
    for i, row in enumerate(reader, start=1):
    old_name = f"{i}.png"
    new_name = row[0] + ".pdf"
    old_path = os.path.join(folder_path, old_name)
    new_path = os.path.join(folder_path, new_name)
    if os.path.exists(old_path):
    # os.rename(old_path, new_path)
    # print(f"Renamed {old_name} to {new_name}")
    image = Image.open(old_name)
    pdf_bytes = img2pdf.convert(image.old_name)
    file = open(new_name, "wb")
    file.write(pdf_bytes)
    else:
    print(f"File {old_name} not found")


    This code was error result

    Is there a better way to do this, Somebody help me. Thank you.

    Continue reading...

Compartilhe esta Página