Преобразование Django weasyprint HTML в PDF работает очень медленно

Я покрываю файл HTML в PDF, используя weasyprint в веб-приложении Django. Все работает нормально, но работает очень медленно при конвертации HTML в PDF. Когда я конвертирую, это занимает более двух минут. Я использую шрифт Bangla в своем HTML-файле.

это мой код views.py

def get_pdf_file(request, customer_id, sys_type):
    sys_type = customer_id
    area = "pdf"
    site_credit = site_credit1
    time_now = timezone.now()
    customers = get_object_or_404(CustomerInfo, pk=customer_id)




    due_taka_track = customers.duetaka_set.all()

    if due_taka_track == None:
        due_taka_track = 0

    unpaid_taka = int(customers.customer_price -
                      customers.customer_due_taka_info)
    due_taka_track = customers.duetaka_set.all()

    sum_cost_taka = due_taka_track.aggregate(
        sp=Sum('customer_due')).get('sp', 0)

    if sum_cost_taka == None:
        sum_cost_taka = 0
    total_paid_taka = sum_cost_taka + customers.customer_due_taka_info

    payment_status = 'complete'
    payment_message = 'Full Paid'
    remain_taka='PAID'
    remain_msg=''

    if customers.customer_due_taka_info < customers.customer_price:
        payment_status = 'incomplete'
        payment_message = 'সম্পূর্ন টাকা পরিষোধ করা হয়নি'
        remain_msg='টাকা বাকী আছে'
        baki_ase="পাওনা আছে "

        remain_taka = customers.customer_price - customers.customer_due_taka_info



    context = {'customers': customers,
    'sys_type': sys_type,
    'area': area,
    'site_credit': site_credit,
    'site_name': 'Moon Telecom',
    'sys_type': sys_type,
    'due_taka_track': due_taka_track,
    'total_paid_taka': total_paid_taka,
    'payment_message': payment_message,
    'time_now': time_now,
    'unpaid_taka': unpaid_taka,
    'payment_message': payment_message,
    'remain_taka': remain_taka,
    'sum_cost_taka': sum_cost_taka,
    'remain_msg': remain_msg}

    html_string = render_to_string('shop/pdf_invoice.html', context)
    html = HTML(string=html_string)
    result = html.write_pdf()

    response = HttpResponse(content_type='application/pdf;')
    response['Content-Disposition'] = 'inline; filename=invoice'+sys_type+'.pdf'
    response['Content-Transfer-Encoding'] = 'UTF-8'
    with tempfile.NamedTemporaryFile(delete=True) as output:
        output.write(result)
        output.flush()
        output = open(output.name, 'rb')
        response.write(output.read())

    return response

Это мой HTML-файл. Этот файл я конвертирую HTML в PDF

<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Moon Telecom</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="https://fonts.maateen.me/kalpurush/font.css" rel="stylesheet">
    <style>

        p,
        td,
        tr {
            font-size: 10px;
            line-height: 12px;
        }

        body {
            font-family: 'Kalpurush', Arial, sans-serif !important;
        }
    </style>
</head>

<body>

    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <div class="site_title" style="text-align:center; margin:0 auto">
                    <p style="font-size:15px">মুন টেলিকম</p>

                    <div class="invoice_info_one" style="width:100%; text-align:center">
                        <p>সকল প্রকার মোবাইল সেট, সীম কার্ড, মেমোরী কার্ড, MP-3, সোলার চার্জার, সোলার ফ্যান, মোবাইল ফোনের ব্যাটারী,
                            চার্জার, ক্যাচিং,কাভার,হেডফোন, রেবন, ডিসপ্লে এবং ইলেট্রিক মালামাল বিক্রেতা</p>
                    </div>
                    <div class="invoice_location">
                        <p>জাহাঙ্গীর সুপার মার্কেট, ব্রীজ রোড, ফুলহাতা বাজার, মোডেলগঞ্জ।</p>
                    </div>
                    <div class="invoice_contact">
                        <p>01717-051200(সুকান্ত) 01828-163858(দোকান)</p>
                        <p>
                            <b>Email:</b> [email protected]</p>
                    </div>



                    <hr>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="col-lg-12">

                <div class="customer_info">
                    {% if customers.customer_name %}
                    <p style="font-size:15px">Customer Name:
                        <b> {{customers.customer_name}}</b>
                        <span style="color:red">{{customers.customer_first_due_info}}</span>
                    </p>
                    {% else %}
                    <p> Name: দেওয়া হয়নি</p> {% endif %}

                    <p style="font-size:14px">Phone Number: {% if customers.customer_mobile_no %} {{customers.customer_mobile_no}} {% else %} No Mobile
                        Number {% endif %}
                    </p>
                    <p style="font-size:14px">Purchase Time: {{customers.customer_sell_date}}</p>
                    <p style="font-size:14px">invoice id:
                        <b>{{customers.customer_uid}}</b>
                    </p>
                    <p>{{customers.product_warrenty}}</p>
                </div>

            </div>
        </div>
    </div>



    <div class="customer_product_and_paid_info">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <div class="">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>Product Name</th>
                                    <th colspan="">Price</th>
                                    <th>ID or IME</th>
                                    <th>Warrenty</th>
                                    <th>QN</th>

                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>
                                        <b>{{customers.customer_product_name}}</b>
                                    </td>
                                    <td>
                                        <b>{{customers.customer_price}}</b> TK
                                        <i>{% if customers.customer_discount_taka %} Discount added TK: {{customers.customer_discount_taka}}
                                            TK {% else %} {% endif %}</i>
                                    </td>
                                    <td>{{customers.customer_product_id}}</td>


                                    <td>
                                        {% if customers.customer_product_warrenty %} {{customers.customer_product_warrenty}} Months {% else %} No {% endif %}
                                    </td>
                                    <td>{{customers.customer_product_quantity}}</td>
                                </tr>


                                <th>
                                    <hr> First Time Payment</th>
                                <th>

                                    <hr> {{customers.customer_first_time_payment}} TK
                                    <span style="color:red">{{customers.customer_first_due_info}}</span>
                                </th>
                                <td>
                                    <hr> {{customers.customer_sell_date}}
                                </td>


                                {% if due_taka_track %}


                                <thead>
                                    <tr>
                                        <th>SL</th>
                                        <th>Taka</th>
                                        <th>Paid Date</th>
                                        <td>Due Info</td>

                                    </tr>
                                </thead>
                                <tbody>
                                    <hr> {% for track in due_taka_track %}
                                    <tr>
                                        <td>{{forloop.counter}}</td>
                                        <td>
                                            <i>{{track.customer_due}}</i> TK</td>
                                        <td>{{track.customer_due_date}}</td>
                                        <td>{{track.customer_due_info}}</td>
                                    </tr>
                                    {% endfor %}
                                </tbody>


                                {% else %} {% endif %} {% if sum_cost_taka %}
                                <tr>

                                    <td>Total Due Complete </td>

                                    <th>{{sum_cost_taka}} TK</th>

                                </tr>
                                {% else %} {% endif %}





                                <tr>
                                    <td>
                                        <b>Total Paid</b>
                                    </td>

                                <th>


                                    {% if payment_message %} 

                                    {{customers.customer_due_taka_info}} TK

                                    <span style="color:red">{{payment_message}}</span>
                                    <br>

                                    <button type="button" class="btn btn-danger">{{remain_msg}} {{remain_taka}} TK</button>
                                    {%else %} 

                                    {{customers.customer_due_taka_info}} TK
                                    <button type="button" class="btn btn-success">Payment Completed</button>

                                    {% endif %}
                                </th>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <div class="customer_notifications">
        <div class="container">
            <div class="row">
                <div class="col-lg-6">

                    {% if customers.customer_conditions %}
                    <div class="warning">
                        <p style="font-size:8px; width:500px;line-height:15px;">
                            <i>{{customers.customer_product_name}} {{customers.customer_conditions}}</i>
                        </p>
                    </div>

                    {% else %} {% endif %}
                </div>
            </div>
        </div>
    </div>








    <div class="footer" style="display:block">
        <div class="footer_info">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="footer_info">
                            <p>Print date: {{time_now}}</p>
                            <p>
                                <b>বিঃদ্রঃ ডেলিভারির সময় মাল বুঝিয়া নিবেন। পরে কোন আপত্তী গ্রহনযোগ্য নয়</b>
                            </p>
                            <p>বিক্রিত মাল ফেরত নেওয়া হয় না</p>
                        </div>
                        <div class="copy_right">
                            {% if site_credit %}
                            <p>{{site_credit}}</p>
                            {% else %}

                            {% endif %}

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>

person Asaduzzaman Sohel    schedule 19.10.2017    source источник
comment
Я не эксперт в этой области, но вот альтернативный метод, который я использую. Может быть, попробовать это для сравнения скорости? перегринсалон .com/блог/2015/06/   -  person FlipperPA    schedule 20.10.2017
comment
См. также ответ на этот вопрос: stackoverflow.com/q/41723844/5320906   -  person snakecharmerb    schedule 20.10.2017