Advertisement
plirof2

sch python generate many PDF from an image and a CSV

Mar 4th, 2024
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. You can achieve this using a programming language like Python and a library like ReportLab for generating PDFs. Here's a basic outline of how you can accomplish this:
  2.  
  3. Load your image and CSV file containing the names into your Python script.
  4. Use ReportLab to open a new PDF file and add the image onto each page.
  5. Iterate through each name in the CSV file, add the name onto the image, and save the PDF file with the corresponding name.
  6. Below is a sample code snippet to get you started:
  7.  
  8.  
  9. from reportlab.pdfgen import canvas
  10. from reportlab.lib.pagesizes import letter
  11. from reportlab.lib.units import inch
  12. from reportlab.pdfbase.ttfonts import TTFont
  13. from reportlab.pdfbase import pdfmetrics
  14. import csv
  15.  
  16. # Load image
  17. image_path = 'your_image.jpg'
  18.  
  19. # Load CSV file
  20. csv_file = 'your_names.csv'
  21.  
  22. # Function to generate PDF with name
  23. def generate_pdf(name):
  24.    c = canvas.Canvas(f'{name}.pdf', pagesize=letter)
  25.    c.drawImage(image_path, 0, 0, width=8.5*inch, height=11*inch)
  26.    c.setFont("Helvetica", 12)
  27.    c.drawString(100, 100, name)
  28.    c.save()
  29.  
  30. # Main function
  31. def main():
  32.    # Load names from CSV file
  33.    with open(csv_file, 'r') as file:
  34.        reader = csv.reader(file)
  35.        for row in reader:
  36.            name = row[0]
  37.            generate_pdf(name)
  38.  
  39. if __name__ == '__main__':
  40.    main()
  41. Replace your_image.jpg with the path to your image and your_names.csv with the path to your CSV file containing names. This script will generate a PDF file for each name in your CSV list with the name added onto the image. You may need to adjust the positioning of the name on the image to suit your needs.
  42.  
  43. Make sure to install ReportLab library, you can do it by running pip install reportlab command.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement