Try report lab
parent
387064db8c
commit
2922692cda
|
|
@ -5,6 +5,7 @@ import shutil
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import threading
|
import threading
|
||||||
import img2pdf
|
import img2pdf
|
||||||
|
from reportlab.pdfgen import canvas
|
||||||
|
|
||||||
# Fix for Matplotlib in threads: Set backend to non-interactive 'Agg'
|
# Fix for Matplotlib in threads: Set backend to non-interactive 'Agg'
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
|
@ -226,16 +227,31 @@ def process_student(args):
|
||||||
json.dump(final_json_map, f, indent=2)
|
json.dump(final_json_map, f, indent=2)
|
||||||
|
|
||||||
|
|
||||||
# Pour éviter du drift
|
# # Pour éviter du drift, avec img2pdf
|
||||||
temp_img_path = os.path.join(output_dir, "Reference.jpg")
|
# # Pb : Xournal can't add annotations
|
||||||
concat_img.save(temp_img_path, quality=90) # Save as standard image first
|
# temp_img_path = os.path.join(output_dir, "Reference.jpg")
|
||||||
with open(os.path.join(output_dir, "Concat.pdf"), "wb") as f:
|
# concat_img.save(temp_img_path, quality=90) # Save as standard image first
|
||||||
f.write(img2pdf.convert(temp_img_path))
|
# with open(os.path.join(output_dir, "Concat.pdf"), "wb") as f:
|
||||||
|
# f.write(img2pdf.convert(temp_img_path))
|
||||||
|
|
||||||
|
|
||||||
|
# Avec reportlab.pdfgen
|
||||||
|
# Au moins, le drift n'empire pas au fil de la copie
|
||||||
|
temp_img_path = os.path.join(output_dir, "Reference.jpg") # Can't use png here
|
||||||
|
concat_img.save(temp_img_path, quality=90)
|
||||||
|
pdf_path = os.path.join(output_dir, "Concat.pdf")
|
||||||
|
w, h = concat_img.size
|
||||||
|
c = canvas.Canvas(pdf_path, pagesize=(w, h))
|
||||||
|
c.drawImage(temp_img_path, 0, 0, width=w, height=h)
|
||||||
|
c.save()
|
||||||
|
|
||||||
# Ancien code, avec du drift
|
# Ancien code, avec du drift
|
||||||
# concat_img.save(os.path.join(output_dir, "Concat.pdf"), "PDF", resolution=DPI)
|
# concat_img.save(os.path.join(output_dir, "Concat.pdf"), "PDF", resolution=DPI)
|
||||||
# concat_img.save(os.path.join(output_dir, "Reference.png"))
|
# concat_img.save(os.path.join(output_dir, "Reference.png"))
|
||||||
|
|
||||||
|
# Try to fix the drift with 72 DPI, non essayé
|
||||||
|
# concat_img.save(os.path.join(output_dir, "Concat.pdf"), "PDF", resolution=72.0)
|
||||||
|
# concat_img.save(os.path.join(output_dir, "Reference.jpg"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue