ReportLabs Django Integration

后端 未结 2 1737
情深已故
情深已故 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条回答
  • 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)
    
    0 讨论(0)
  • 2021-01-22 23:33

    You have to download the fonts and place them in your ReportLabs package.

    You need these files:

    http://www.reportlab.com/ftp/fonts/pfbfer.zip

    Unzip them in:

    /path/to/your/python/site-packages/reportlab/fonts
    
    0 讨论(0)
提交回复
热议问题