title: how to generate pdf in django in other than english?
body: <p>i am trying to generate pdf using xhtml2pdf in django for other than english  but it shows black square boxes and unusual texts.
  i am trying to render nepali text in my pdf but i m getting this issue, can anyone help me to solve this issue ,,
  import imp
  from io import StringIO
  # from weasyprint import HTML
  from django.template.loader import render_to_string
  import tempfile
  from django.http import HttpResponse
  from django.conf import settings
  import datetime</p>
  <pre><code>#A stream implementation using an in-memory bytes buffer
  # It inherits BufferIOBase
  
  from django.http import HttpResponse
  from django.template.loader import get_template
  
  #pisa is a html2pdf converter using the ReportLab Toolkit,
  #the HTML5lib and pyPdf.
  
  from xhtml2pdf import pisa  
  
  def render_to_pdf(template_src, context_dict={}):
      '''
      This method will converts the template file into pdf
      @params template_src is the template file to be converted
      @params context_dict is the dictionary containing all the data written into the template
      '''
      template = get_template(template_src)
      context_dict.update({&quot;invoice_title&quot;:context_dict['invoice_title']+str(datetime.datetime.now())+&quot;.pdf&quot;})
      # this will render the html template and parse the data into the template
      html  = template.render(context_dict)
      # result = StringIO()
      response = HttpResponse(content_type='application/pdf')
      response['Content-Disposition'] = 'inline;attachment; filename='+context_dict['invoice_title']+str(datetime.datetime.now())+'.pdf'
      response['Content-Transfer-Encoding'] = 'utf8'
      
      #part will create the pdf.
      # pdf = pisa.pisaDocument(BytesIO(html.encode(&quot;ISO-8859-1&quot;)), result)
      pisa_status = pisa.pisaDocument(html.encode(&quot;UTF-8&quot;),response)
  
      # pisa_status= pisa.CreatePDF(
      #     html, dest=response
      # )
      if pisa_status.err:
          return HttpResponse(&quot;We had some errors &lt;pre&gt;&quot;+html+&quot;&lt;/pre&gt;&quot;)
      return response
  
  html template 
  &lt;html lang=&quot;en&quot;&gt;
  
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;title&gt;Purchase Invoice&lt;/title&gt;
      &lt;style&gt;
          .heading {
              font-size: 12px;
              font-display: bold;
              text-align: center;
              padding-top: 50px;
          }
          
          .subheading {
              font-size: 12px;
              text-align: center;
          }
          
          .col-12 {
              width: 100%;
              float: left;
          }
          
          .col-3 {
              width: 25%;
              float: left;
          }
          
          .col-6 {
              width: 50%;
              float: left;
          }
          
          .textalignright {
              text-align: right;
              font-size: 12px;
          }
          
          .detail {
              font-size: 12px;
              /* font-weight: bold; */
          }
          
          table,
          th,
          td {
              border: 1px solid black;
              border-collapse: collapse;
              padding: 3px 3px 0px 3px;
          }
          
          .w-5 {
              width: 10%;
          }
          
          .w-25 {
              width: 50%;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class=&quot;container&quot;&gt;
          &lt;div class=&quot;Company_profile&quot;&gt;
              &lt;div class=&quot;row&quot;&gt;
                  &lt;div class=&quot;col-12 heading&quot;&gt;
                      &lt;h1 class=&quot;text-white&quot;&gt;{{request.user.company.print_name}}&lt;/h1&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;row&quot;&gt;
                  &lt;table style=&quot;width:100%; border:none;&quot;&gt;
                      &lt;tr style=&quot;border:none;&quot;&gt;
                          &lt;td style=&quot;width:33.33%; border:none;&quot;&gt;&lt;/td&gt;
                          &lt;td style=&quot;width:33.33%; border:none; text-align:center;&quot;&gt;Email : {{request.user.company.email}}
                          &lt;/td&gt;
                          &lt;td style=&quot;width:33.33%; border:none; text-align:right;&quot;&gt;Times Printed :1&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr style=&quot;border:none;&quot;&gt;
                          &lt;td style=&quot;width:33.33%; border:none;&quot;&gt;&lt;/td&gt;
                          &lt;td style=&quot;width:33.33%; border:none; text-align:center;&quot;&gt;VAT Registration No: {{request.user.company.it_pan}}&lt;/td&gt;
                          &lt;td style=&quot;width:33.33%; border:none; text-align:right;&quot;&gt;Copy of Original&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/div&gt;
              &lt;div class=&quot;row&quot;&gt;
                  &lt;div class=&quot;col-12 subheading&quot;&gt;
                      &lt;h3 class=&quot;float-left&quot;&gt;कर बिजक&lt;/h3&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;Customer_info&quot;&gt;
              &lt;div class=&quot;row&quot;&gt;
                  &lt;table style=&quot;width:100%; border:none;&quot;&gt;
                      &lt;tr style=&quot;border:none;&quot;&gt;
                          &lt;td style=&quot;width:50%; border:none;&quot; class=&quot;detail&quot;&gt;Invoice No.:{{purchase_data.voucherno}}&lt;/td&gt;
                          &lt;td style=&quot;width:50%; border:none; text-align:right;&quot; class=&quot;detail&quot;&gt;Invoice Date :{{purchase_data.formatted_nepalidate}}&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr style=&quot;border:none;&quot;&gt;
                          &lt;td style=&quot;width:50%; border:none;&quot; class=&quot;detail&quot;&gt;Customer Name:{{purchase_data.party.name}}&lt;/td&gt;
                          &lt;td style=&quot;width:50%; border:none;&quot;&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr style=&quot;border:none;&quot;&gt;
                          &lt;td style=&quot;width:50%; border:none;&quot; class=&quot;detail&quot;&gt;Customer Address :{{purchase_data.party.address}}&lt;/td&gt;
                          &lt;td style=&quot;width:50%; border:none;&quot;&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr style=&quot;border:none;&quot;&gt;
                          &lt;td style=&quot;width:50%; border:none;&quot; class=&quot;detail&quot;&gt;Customer's VAT/PAN No:{{purchase_data.party.it_pan}}&lt;/td&gt;
                          &lt;td style=&quot;width:50%; border:none;&quot;&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;div class=&quot;Sales_detail&quot;&gt;
              &lt;table style=&quot;width:100%;&quot;&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
                          &lt;th class=&quot;w-5&quot;&gt;S.N&lt;/th&gt;
                          &lt;th class=&quot;w-25&quot;&gt;Particulars&lt;/th&gt;
                          &lt;th class=&quot;w-5&quot;&gt;Qty&lt;/th&gt;
                          &lt;th class=&quot;w-5&quot;&gt;Unit &lt;/th&gt;
                          &lt;th class=&quot;w-5&quot;&gt; Price&lt;/th&gt;
                          &lt;th class=&quot;w-5&quot;&gt;Amount&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      {% for purchaseItem in purchase_items %}
                      &lt;tr&gt;
                          &lt;td scope=&quot;row&quot;&gt;{{ forloop.counter }}&lt;/th&gt;
                          &lt;td&gt;{{purchaseItem.item.name}}&lt;/td&gt;
                          &lt;td&gt;{{purchaseItem.quantity}}&lt;/td&gt;
                          &lt;td&gt;{{purchaseItem.unit.name}}&lt;/td&gt;
                          &lt;td&gt;{{purchaseItem.formatted_price}}&lt;/td&gt;
                          &lt;td&gt;{% if purchase_data.is_line_discount %}{{purchaseItem.formatted_amount}}{% else %}{{purchaseItem.formatted_amount}}{% endif %}&lt;/td&gt;
                      &lt;/tr&gt;
                      {% endfor %}
                      &lt;tr&gt;
                          &lt;td colspan=&quot;5&quot; style=&quot;text-align:left;&quot;&gt;Total Amount&lt;/td&gt;
                          &lt;td&gt;{{purchase_data.total_amount}}&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td colspan=&quot;5&quot; style=&quot;text-align:left;&quot;&gt;Discount Amount&lt;/td&gt;
                          &lt;td&gt;{{purchase_data.trade_discount_amount}}&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td colspan=&quot;5&quot; style=&quot;text-align:left;&quot;&gt;Total Taxable Amount&lt;/td&gt;
                          &lt;td&gt;{{purchase_data.taxable_amount}}&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td colspan=&quot;5&quot; style=&quot;text-align:left;&quot;&gt;13% VAT&lt;/td&gt;
                          &lt;td&gt;{{purchase_data.vat_amount}}&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td colspan=&quot;5&quot; style=&quot;text-align:left; font-weight:Bold;&quot;&gt;Total NPR Incl. VAT&lt;/td&gt;
                          &lt;td style=&quot;font-weight:Bold;&quot;&gt;{{purchase_data.total_amount_inc_vat}}&lt;/td&gt;
  
                      &lt;/tr&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
  
              &lt;div class=&quot;row&quot;&gt;
                  &lt;div class=&quot;col-12 detail&quot;&gt;
                      &lt;p&gt;&lt;b&gt;Total Amount in Words :&lt;/b&gt; {{purchase_data.formatted_amountwords}}
                      &lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;footer&quot; style=&quot;margin-top:100px ;&quot;&gt;
              &lt;table style=&quot;width:100%; border:none;&quot;&gt;
                  &lt;tr style=&quot;border:none;&quot;&gt;
                      &lt;td style=&quot;width:100%; border:none;&quot;&gt;
                          &lt;p class=&quot;text-left&quot;&gt;(E. &amp; O. E) Goods once sold are not exchangeable or returnable.&lt;/p&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr style=&quot;border:none;&quot;&gt;
                      &lt;td style=&quot;width:50%; border:none;&quot;&gt;&lt;/td&gt;
                      &lt;td style=&quot;width:50%; border:none; text-align:right;&quot;&gt;-----------------------------&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr style=&quot;border:none;&quot;&gt;
                      &lt;td style=&quot;width:50%; border:none;&quot;&gt;&lt;/td&gt;
                      &lt;td style=&quot;width:50%; border:none; text-align:right;&quot;&gt;Authorised Signatory&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr style=&quot;border:none;&quot;&gt;
                      &lt;td style=&quot;width:50%; border:none;&quot;&gt;&lt;/td&gt;
                      &lt;td style=&quot;width:50%; border:none; text-align:right;&quot;&gt;Printed On : {{purchase_data.formatted_nepalidate}}&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr style=&quot;border:none;&quot;&gt;
                      &lt;td style=&quot;width:50%; border:none;&quot;&gt;&lt;/td&gt;
                      &lt;td style=&quot;width:50%; border:none; text-align:right;&quot;&gt;Printed By: {{request.user.username}}&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
  
          &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>I am getting this output with black square but not the text:</p>
  <p><a href="https://i.stack.imgur.com/alzEt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/alzEt.jpg" alt="Error-screenshot" /></a></p>