ReportLab kann keine Ressource öffnen, wenn Minio (S3) vorgewiesen wird
Posted: 05 Apr 2025, 11:14
Ich verwende ReportLab in einem Container-Django-Projekt mit Django-Minio-Backend zum Speichern von Benutzern. Ich möchte ein PDF erstellen, das das hochgeladene Bild als Hintergrund verwendet.
Code: Select all
from django_minio_backend import MinioBackendStatic
from reportlab.lib.utils import ImageReader
def render_pdf(data: dict, image_url: str) -> io.BytesIO:
RGB_VAL = 50
# Create a file-like buffer to receive PDF data.
buffer = io.BytesIO()
# Register the Open Sans Font
font_file = MinioBackendStatic().open("/fonts/OpenSans-Regular.ttf")
pdfmetrics.registerFont(TTFont("OpenSans", font_file))
# Create the PDF object, using the buffer as its "file."
p = canvas.Canvas(buffer, pagesize=landscape(A4))
image = ImageReader(image_url) #