2

I wanted to print barcodes using for loop in python. This is my code:

`{%- from "templates/print_formats/standard_macros.html" import add_header -%}

<hr>

{% set a = doc.end %}
{% set count = 0 %}
<div class="row">
{%- for i in range(doc.start,doc.end) -%}

<div class="col-md-4 text-center">
<p style="font-family: Code39AzaleaFont;font-weight: normal;font-style: normal;font-size:30px;">
00000000000000{{ i }}</p>
{% set count = count + 1 %}
{{count}}

<br/>
</div>

{%- endfor -%}
</div>
    <hr>
    <br>
    <p class="strong">

        <br>
        <br>
        <br>
        {{ _("Authorized Signatory") }}
    </p>
</div>`

The problem is,I wanted to restrict the number of barcodes printed on one sheet of paper to 24.Is there any way to do that?

LaksHmiSekhar
  • 315
  • 2
  • 7
  • 16
  • Use nested loop where the parent loop will represent pages and child loop will represent number of barcode you want to print. – Gaurav Dave Jan 05 '15 at 09:41

2 Answers2

3

You can add a page break after every 24th barcode using:

{% if count % 24 %}<div style="page-break-before: always;"></div>{% endif %}
  • @LaksHmiSekhar can you share your updated code after incorporating the answer. I am trying to do something similar but I am not sure where should this above code go. – iCHAIT Jan 25 '20 at 16:48
0

HTML doesn't have a really good concept of "paper sheet size". A HTML page has an infinite height and browser's are notoriously bad a printing HTML in a readable way (with the notable exception of Opera).

With CSS 3, three page break properties were defined.

They might be supported by your browser. If they are, then wrap 24 bar codes in a <div> and give that <div> a class which tells the browser to break the page afterwards.

If the browser emits an empty page at the end, then you need two classes: One for the first <div> without a page break and one for every successive <div> and a page-break-before: always;

If that doesn't work well, you should look at PDF. PDF allows you place elements exactly on pages with a known, fixed size.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820