Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html label design: Vector font, flexible label design, preview and print result 1:1 and more #84

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 42 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ This plugin depends on [qrcode](https://github.com/lincolnloop/python-qrcode) an
| 0.0.11 | >= 3.7.0 | 3.7.x |
| 0.0.13 | >= 4.0.2 | v4.0.2 |

Netbox version 2 is no longer supported.

## Installation

If Netbox was installed according to the standard installation instructions. It may be necessary to activate the virtual environment.
Expand All @@ -36,74 +38,53 @@ Restart NetBox and add `netbox-qrcode` to your local_requirements.txt

## Configuration

The following options are available:
### Set the label printer correctly

* `with_text`: Boolean (default True). Text label will be added to QR code image if enabled.
* `text_template`: [Jinja2](https://jinja.palletsprojects.com/) template with {{ obj }} as context for device, rack, etc., using it ignores `text_fields` and `custom_text`.
If the print does not look like the preview in the Netbox, first try to get a perfect print using Word. As many printer settings also have an influence on the print result. Borderless printing is possible if the printer (e.g. thermal transfer printer) supports this.

Example to output name and site in two lines with caption (See also screenshots below):
```
'text_template': 'Name: {{ obj.name }}\nSite: {{ obj.site }}',
```
* `text_fields`: List of String (default ['name']). Text fields of an object that will be added as text label to QR image. It's possible to use custom field values.
* `font`: String (default TahomaBold) Font name for text label ( Some font include in package, see fonts dir).
* `text_location`: Where to render the text, relative to the QR code. Valid values are `"right"` (default), `"left"`", `"up"`, and `"down"`.
* `custom_text`: String or None (default None) additional text label to QR code image (will be added after text_fields).
* `qr_version`: Integer (default 1) parameter is an integer from 1 to 40 that controls the size of
the QR Code (the smallest, version 1, is a 21x21 matrix).
* `qr_error_correction`: Integer (default 0), controls the error correction used for the
QR Code. The following values are available:
![ShowImage](/docs/img/Configuration_Printer_WordPreview.png)

1 - About 7% or less errors can be corrected.
0 - About 15% or less errors can be corrected.
2 - About 30% or less errors can be corrected.
3 - About 25% or less errors can be corrected.

* `qr_box_size`: Integer (default 6), controls how many pixels each "box" of the QR code
is.
* `qr_border`: Integer (default 4), controls how many boxes thick the border should be
(the default is 4, which is the minimum according to the specs).
Here is an example of what needs to be considered to print borderless from a Word document. [Go to: Eexample Zebra ZM400 300dpi label printer and a label 56x32mm. >>](/docs/img/Configuration_Printer_ZM400.png)

### Per object options

Per object options override default options. Per object options dictionary can contains any of default options inside.
### Browser Print Settings correctly

* `device`: Dict or None (default {'text_fields': ['name', 'serial']}), set None to disble QR code
* `rack`: Dict or None (default {'text_fields': ['name']}) , set None to disble QR code
* `cable`: Dict or None ( defaul {'text_fields': ['_termination_a_device', 'termination_a', '_termination_b_device', 'termination_b',]}), set None to disble QR code
When you press the “Print” button, there are some print properties that are added by the browser. However, these interfere with the print result. They should therefore be deactivated.

Configuration example:
```
PLUGINS_CONFIG = {
'netbox_qrcode': {
'with_text': True,
'text_fields': ['name', 'serial'],
'font': 'ArialMT',
'font_size': 12, # If the value is 0 or the line does not exist, then the text is automatically adjusted
'custom_text': 'Property of SomeCompany\ntel.8.800333554-CALL',
'text_location': 'up',
'qr_version': 1,
'qr_error_correction': 0,
'qr_box_size': 4,
'qr_border': 4,
# per object options
'cable': None, # disable QR code for Cable object
'rack': {
'text_fields': [
'site',
'name',
'facility_id',
'tenant',
'cf.cf_name'
]
},
'device': {
'qr_box_size': 6,
'custom_text': None,
}
}
}
```
#### Firefox:

| Parameter | Value |
| --------------------------------------------- | --------------------------- |
| Orientation | Portrait |
| Paper size | User defined |
| Margins | none |
| Scale | Fit to page width or 100% |
| Options --> Print headers and footers | disable |
| Options --> Print backgrounds | disable |

#### Chrome:
The worst part was finding the right parameters for Chrome. Because it always turned it differently when printing than the print preview shows.
| Parameter | Value |
| --------------------------------------------- | --------------------------- |
| Layout | Portrait |
| Paper size | empty !!! |
| Pages per sheet | 1 |
| Margins | none |
| Scale | Default or 100% |
| Options --> PBackground grafics | disable |

![Image](/docs/img/Configuration_Browser_Print_Settings.png)


### Design your own label

You can customise the label as you wish, even 2 different labels for the ‘Device’ view, for example, are possible.

- [Go to Configuration >>](docs/README_Subpages/README_Configuration.md)
- [Go to Example label configurations >>](docs/README_Subpages/README_Configuration_ExampleLabelConf.md)

![Cable QR Code](/docs/img/Configuration_Label_Example_10.png)

## Contributing
Developing tools for this project based on [ntc-netbox-plugin-onboarding](https://github.com/networktocode/ntc-netbox-plugin-onboarding) repo.
Expand All @@ -119,7 +100,4 @@ Rack QR code
![Rack QR Code](docs/img/qrcode_rack.png)

Cable QR code
![Cable QR Code](docs/img/qrcode_cable.png)

Device QR code via Jinja2 "text_template" Parameter (Multiline and labeled)
![Cable QR Code](docs/img/qrcode_text_template.png)
![Cable QR Code](docs/img/qrcode_cable.png)
Loading