Edinburgh-Genome-Foundry / blabel

:label: Python label/sticker PDF generation. HTML templates, built-in barcodes, qr codes, and other goodies
https://edinburgh-genome-foundry.github.io/blabel
MIT License
179 stars 38 forks source link

Printing multiple labels #23

Closed rickbps closed 2 years ago

rickbps commented 2 years ago

I see in the documentation that it is possible to print two labels sequentially by using two separate dicts.

If I have x number of records in a table and want to loop through them, is it possible to print them on one PDF?

veghp commented 2 years ago

Can you please point to that part of documentation and also clarify what you mean? What format (Python object) do you have your table in?

There are examples in https://github.com/Edinburgh-Genome-Foundry/blabel/tree/master/examples for printing several items per page, reading from spreadsheet etc

rickbps commented 2 years ago

Hello,

The documentation shows how to print two labels on one PDF as follows:

`from blabel import LabelWriter

label_writer = LabelWriter("item_template.html", default_stylesheets=("style.css",)) records= [ dict(sample_id="s01", sample_name="Sample 1"), dict(sample_id="s02", sample_name="Sample 2") ]

label_writer.write_labels(records, target='qrcode_and_label.pdf')`

My requirements are:

veghp commented 2 years ago

I see the problem now. The package is designed around a fixed PDF page or label size as that's how label printers (or printers in general) operate. But you have variable number of items, which means different PDF sizes. As I mentioned, it's possible to print several items per page, or see this example: https://github.com/Edinburgh-Genome-Foundry/blabel/issues/6

And here is an example for working from tables (spreadsheet / dataframe): https://github.com/Edinburgh-Genome-Foundry/blabel/tree/c95052f562af44ef47e2ec5b220ffbb3b721659b/examples/labels_from_spreadsheet

Alternatively you can work directly with WeasyPrint or PDF Reports.

rickbps commented 2 years ago

The printing from table/label is closest to what I need, so maybe I can use that. Thank you.