ReportLabs Django Integration

后端 未结 2 1761
情深已故
情深已故 2021-01-22 22:34

I\'m following this link to integrate the ReportLabs in Django. I did everything correctly but I get an error saying -

Exception Type: RenderPMError

Exception          


        
2条回答
  •  萌比男神i
    2021-01-22 23:29

    To register a font:

    import os
    from reportlab.pdfbase import pdfmetrics  
    from reportlab.pdfbase.ttfonts import TTFont
    
    pdfmetrics.registerFont(TTFont("Arial", os.path.join(settings.PROJECT_ROOT, 'static', 'fonts', 'arial.ttf'))) # here i have my fonts for PDF's
    

    to use it, ex:

    page = canvas.Canvas(response, pagesize=A4, pageCompression = 0)
    
    canvas.setFont('Arial',9)
    

提交回复
热议问题