save pdf

#1
by dawood HF staff - opened
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -344,15 +344,20 @@ def generate_certificate(certificate_model, first_name, last_name):
344
  # Date of certification
345
  d.text((1480, 1170), str(date.today()), fill="black", anchor="mm", font=date_font)
346
 
347
- rgba = im
348
- rgb = Image.new('RGB', im.size, (255, 255, 255)) # white background
349
- rgb.paste(rgba, mask=rgba.split()[3]) # 3 is the alpha channel
350
- pdf_ = rgb.save("certificate.pdf", 'PDF', save_all = True, resolution=100.0)
351
- pdf__ = im.save("certificate.png")
352
- print("RGB", rgb)
353
- print("PDF", pdf_)
354
- print("PDF", pdf__)
355
- pdf = pdf_.filename
 
 
 
 
 
356
 
357
  return im, pdf
358
 
 
344
  # Date of certification
345
  d.text((1480, 1170), str(date.today()), fill="black", anchor="mm", font=date_font)
346
 
347
+
348
+ pdf = im.convert('RGB')
349
+ pdf.save('certificate.pdf')
350
+ print("PDF: ", pdf)
351
+
352
+ # rgba = im
353
+ # rgb = Image.new('RGB', im.size, (255, 255, 255)) # white background
354
+ # rgb.paste(rgba, mask=rgba.split()[3]) # 3 is the alpha channel
355
+ # pdf_ = rgb.save("certificate.pdf", 'PDF', save_all = True, resolution=100.0)
356
+ # pdf__ = im.save("certificate.png")
357
+ # print("RGB", rgb)
358
+ # print("PDF", pdf_)
359
+ # print("PDF", pdf__)
360
+ # pdf = pdf_.filename
361
 
362
  return im, pdf
363