django-weasyprint icon indicating copy to clipboard operation
django-weasyprint copied to clipboard

image issues on next page

Open smilefl0w opened this issue 1 year ago • 0 comments

Hi,

My current issue: the first image of the next page is not being rendered in a PDF. A simple html page doesn't have the issue. I am trying to use a simple templating loop to render the objects from my database. The PDF is about print labels with fixed width and height. django v5 tailwindcss v 3.8 Any ideas?

<body class="font-lato bg-gray-900 flex justify-center">
    <div class="bg-white" style="width:210mm; height:297mm;">
        <div class="flex flex-wrap">
            <!--flex flex-wrap-->
            {% for work in works %}
                <div class="flex items-center justify-center" style="width:{{dimensions.0}}mm; height:{{dimensions.1}}mm; border-left-width: 0px;
                border-right-width: 0px;">
                    <img class="p-2 m-auto" id="image" src="{{ work.image.url }}" alt="image" style="width: 100px; object-fit: contain;">
                    
                    <div id="metadata" class="text-center my-auto p-5 w-full" style="color: rgb(75,85,99); width: 190px; object-fit: contain; font-size: 10px;">
                        <!--INVENTORY NUMBER-->
                        <p class="text-xl mb-1">INV-{{work.inventory_number}}</p>
                        <!--NAME-->
                        {% if work.artist %}
                            <p class="uppercase">{{work.artist.name}}</p>
                        {% else %}
                        <p class="uppercase">{{request.user.first_name}} {{request.user.last_name}}</p>
                        {% endif %}
                        <!--ARTWORK TITLE-->
                        <p class="italic">{{work.title}}</p>
                        <!--DIMENSIONS-->
                        {% if work.width and work.height %}
                            <p class="italic">{{work.width|floatformat}} x {{work.height|floatformat}} {% if work.depth %}x {{work.depth|floatformat}} {% endif %}</p>
                        {% endif %}
                        <!--MATERIALS-->
                        {% if work.materials %}
                            <p>{{work.materials}}</p>
                        {% endif %}

                    </div>
                </div>
            {% endfor %} 
        </div>
    </div> 
</body>
class LabelCreationView(WeasyTemplateResponseMixin, TemplateView):
    label_options = {
        1: (70, 42.3),
        2: (105, 42.3)
    }
    model = Work.objects.all()
    template_name = 'dashboard/pdf_templates/label_template.html'
    pdf_attachment = False
    pdf_stylesheets = [
        '/theme/static/css/dist/styles.css',
    ]

    def post(self, request, *args, **kwargs):
        selected_work_values_json = request.POST.get('selected_work_values')
        selected_label_dimensions = request.POST.get('selected_label_dimensions')
        
        selected_work_values = json.loads(selected_work_values_json)
        self.label_dimensions = self.label_options.get(int(selected_label_dimensions), (0, 0))
        self.works = Work.objects.filter(pk__in=selected_work_values)
        
        return super().get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['works'] = self.works
        context['dimensions'] = self.label_dimensions
        return context

smilefl0w avatar Feb 11 '24 20:02 smilefl0w