title: Generate pdf from html using xhtml2pdf in django project
body: <p>I am trying to generate pdf from html template in a django project using xhtml2pdf. Everything is working fine but bootstrap is not working. I am following this tutorial <a href="https://www.codingforentrepreneurs.com/blog/html-template-to-pdf-in-django/" rel="nofollow noreferrer">https://www.codingforentrepreneurs.com/blog/html-template-to-pdf-in-django/</a></p>
  
  <p>Views.py</p>
  
  <pre><code>def generate_pdf(request, inflow_id):
      template = 'cashflow/invoice2.html'
      inflow = get_object_or_404(Inflow, pk=inflow_id)
      context = {
          "invoice_id": inflow.id,
          "customer_name": inflow.student,
          "amount": inflow.amount,
          "today": inflow.time,
          "fee_type": inflow.fee_type,
      }
      pdf = render_to_pdf(template, context)
      if pdf:
          response = HttpResponse(pdf, content_type='application/pdf')
          filename = "Invoice_%s.pdf" % inflow.student
          content = "inline; filename='%s'" % filename
          download = request.GET.get("download")
          if download:
              content = "attachment; filename='%s'" % filename
          response['Content-Disposition'] = content
          return response
      return HttpResponse("Not found")
  </code></pre>
  
  <p>render_to_pdf function in utils.py</p>
  
  <pre><code>def render_to_pdf(template_src, context_dict={}):
      template = get_template(template_src)
      html = template.render(context_dict)
      result = BytesIO()
      pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
      if not pdf.err:
          return HttpResponse(result.getvalue(), content_type='application/pdf')
      return None
  </code></pre>
  
  <p>invoice2.html file</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;duck&lt;/title&gt;
      &lt;link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"&gt;
      &lt;script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;script src="//code.jquery.com/jquery-1.11.1.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-sm-4 col-md-3"&gt;
                  &lt;div class="card" style="width: 24rem;"&gt;
                    &lt;img class="card-img-top" src='https://cdn.bulbagarden.net/upload/thumb/0/0d/025Pikachu.png/250px-025Pikachu.png' alt="Card image cap"&gt;
                    &lt;div class="card-body"&gt;
                      &lt;p class="card-text"&gt;Please enter all the fee payments here.&lt;/p&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div&gt;
              &lt;h1&gt;Invoice id: {{ invoice_id }}&lt;/h1&gt;
              &lt;h2&gt;Customer name: {{ customer_name }}&lt;/h2&gt;
              &lt;h3&gt;Amount: {{ amount }}&lt;/h3&gt;
              &lt;h4&gt;Time: {{ today }}&lt;/h4&gt;
              &lt;h5&gt;Fee Type: {{ fee_type }}&lt;/h5&gt;
          &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="well col-xs-10 col-sm-10 col-md-6 col-xs-offset-1 col-sm-offset-1 col-md-offset-3"&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-xs-6 col-sm-6 col-md-6"&gt;
                          &lt;address&gt;
                              &lt;strong&gt;Elf Cafe&lt;/strong&gt;
                              &lt;br&gt;
                              2135 Sunset Blvd
                              &lt;br&gt;
                              Los Angeles, CA 90026
                              &lt;br&gt;
                              &lt;abbr title="Phone"&gt;P:&lt;/abbr&gt; (213) 484-6829
                          &lt;/address&gt;
                      &lt;/div&gt;
                      &lt;div class="col-xs-6 col-sm-6 col-md-6 text-right"&gt;
                          &lt;p&gt;
                              &lt;em&gt;Date: 1st November, 2013&lt;/em&gt;
                          &lt;/p&gt;
                          &lt;p&gt;
                              &lt;em&gt;Receipt #: 34522677W&lt;/em&gt;
                          &lt;/p&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="text-center"&gt;
                          &lt;h1&gt;Receipt&lt;/h1&gt;
                      &lt;/div&gt;
                      &lt;table class="table table-hover"&gt;
                          &lt;thead&gt;
                              &lt;tr&gt;
                                  &lt;th&gt;Product&lt;/th&gt;
                                  &lt;th&gt;#&lt;/th&gt;
                                  &lt;th class="text-center"&gt;Price&lt;/th&gt;
                                  &lt;th class="text-center"&gt;Total&lt;/th&gt;
                              &lt;/tr&gt;
                          &lt;/thead&gt;
                          &lt;tbody&gt;
                              &lt;tr&gt;
                                  &lt;td class="col-md-9"&gt;&lt;em&gt;Baked Rodopa Sheep Feta&lt;/em&gt;&lt;/h4&gt;&lt;/td&gt;
                                  &lt;td class="col-md-1" style="text-align: center"&gt; 2 &lt;/td&gt;
                                  &lt;td class="col-md-1 text-center"&gt;$13&lt;/td&gt;
                                  &lt;td class="col-md-1 text-center"&gt;$26&lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td class="col-md-9"&gt;&lt;em&gt;Lebanese Cabbage Salad&lt;/em&gt;&lt;/h4&gt;&lt;/td&gt;
                                  &lt;td class="col-md-1" style="text-align: center"&gt; 1 &lt;/td&gt;
                                  &lt;td class="col-md-1 text-center"&gt;$8&lt;/td&gt;
                                  &lt;td class="col-md-1 text-center"&gt;$8&lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td class="col-md-9"&gt;&lt;em&gt;Baked Tart with Thyme and Garlic&lt;/em&gt;&lt;/h4&gt;&lt;/td&gt;
                                  &lt;td class="col-md-1" style="text-align: center"&gt; 3 &lt;/td&gt;
                                  &lt;td class="col-md-1 text-center"&gt;$16&lt;/td&gt;
                                  &lt;td class="col-md-1 text-center"&gt;$48&lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;   &lt;/td&gt;
                                  &lt;td&gt;   &lt;/td&gt;
                                  &lt;td class="text-right"&gt;
                                  &lt;p&gt;
                                      &lt;strong&gt;Subtotal: &lt;/strong&gt;
                                  &lt;/p&gt;
                                  &lt;p&gt;
                                      &lt;strong&gt;Tax: &lt;/strong&gt;
                                  &lt;/p&gt;&lt;/td&gt;
                                  &lt;td class="text-center"&gt;
                                  &lt;p&gt;
                                      &lt;strong&gt;$6.94&lt;/strong&gt;
                                  &lt;/p&gt;
                                  &lt;p&gt;
                                      &lt;strong&gt;$6.94&lt;/strong&gt;
                                  &lt;/p&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;   &lt;/td&gt;
                                  &lt;td&gt;   &lt;/td&gt;
                                  &lt;td class="text-right"&gt;&lt;h4&gt;&lt;strong&gt;Total: &lt;/strong&gt;&lt;/h4&gt;&lt;/td&gt;
                                  &lt;td class="text-center text-danger"&gt;&lt;h4&gt;&lt;strong&gt;$31.53&lt;/strong&gt;&lt;/h4&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/tbody&gt;
                      &lt;/table&gt;
                      &lt;button type="button" class="btn btn-success btn-lg btn-block"&gt;
                          Pay Now   &lt;span class="glyphicon glyphicon-chevron-right"&gt;&lt;/span&gt;
                      &lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Please let me know what can I change here or use here to load bootstrap while generating pdf</p>