Is there a way to generate pdf containing non-ascii symbols with pisa from django template?

后端 未结 6 796
情歌与酒
情歌与酒 2021-02-05 08:11

I\'m trying to generate a pdf from template using this snippet:

def write_pdf(template_src, context_dict):
    template = get_template(template_src)
    context          


        
6条回答
  •  逝去的感伤
    2021-02-05 08:38

    You need to modify your django template. Add a new font face in the stylesheet that will link to a font file with characters used in your document. And that font file must be accessible from your server (under Ubuntu you can find files with fonts in /usr/share/fonts/truetype/ directory). For example:

    @font-face {
      font-family: DejaMono; 
      src: url(font/DejaVuSansMono.ttf);
    }
    

    Then if you have next HTML code:

    Some non-latin characters

    you can display that text in DejaMono font with this CSS rule:

    div { font-family: DejaMono; }
    

    This works for me when I generate PDF documents with cyrillic characters.

提交回复
热议问题