generate pdf with multiple devices

This commit is contained in:
Cayo Puigdefabregas 2022-03-16 14:27:55 +01:00
parent a8df3f5e5a
commit a36fb0b0fc
3 changed files with 25 additions and 20 deletions

View File

@ -5,8 +5,8 @@ $(document).ready(function() {
load_size();
})
function qr_draw(url) {
var qrcode = new QRCode($("#qrcode")[0], {
function qr_draw(url, id) {
var qrcode = new QRCode($(id)[0], {
text: url,
width: 128,
height: 128,
@ -54,16 +54,26 @@ function printpdf() {
var border = 2;
var height = parseInt($("#height-tag").val());
var width = parseInt($("#width-tag").val());
var tag = $("#tag").text();
var pdf = new jsPDF('l', 'mm', [width, height]);
var imgData = $('#qrcode img').attr("src");
img_side = Math.min(height, width) - 2*border;
max_tag_side = (Math.max(height, width)/2) + border;
if (max_tag_side < img_side) {
max_tag_side = img_side+ 2*border;
};
min_tag_side = (Math.min(height, width)/2) + border;
pdf.addImage(imgData, 'PNG', border, border, img_side, img_side);
pdf.text(tag, max_tag_side, min_tag_side);
pdf.save('Tag_'+tag+'.pdf');
var last_tag_code = '';
var pdf = new jsPDF('l', 'mm', [width, height]);
$(".tag").map(function(x, y) {
if (x != 0){
pdf.addPage();
console.log(x)
};
var tag = $(y).text();
last_tag_code = tag;
var imgData = $('#'+tag+' img').attr("src");
pdf.addImage(imgData, 'PNG', border, border, img_side, img_side);
pdf.text(tag, max_tag_side, min_tag_side);
});
pdf.save('Tag_'+last_tag_code+'.pdf');
}

View File

@ -32,7 +32,9 @@
<div id="{{ tag.id }}"></div>
</div>
<div class="col">
<div style="padding-top: 55px"><b id="tag_{{ tag.id }}">{{ tag.id }}</b></div>
<div style="padding-top: 55px">
<b class="tag">{{ tag.id }}</b>
</div>
</div>
</div>
</div>
@ -95,14 +97,7 @@
<script src="{{ url_for('static', filename='js/print.pdf.js') }}"></script>
<script type="text/javascript">
{% for tag in tags %}
new QRCode(document.getElementById("{{ tag.id }}"), {
text: "{{url_for('inventory.device_details', id=tag.device.devicehub_id, _external=True)}}",
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
qr_draw("{{ url_for('inventory.device_details', id=tag.device.devicehub_id, _external=True) }}", "#{{ tag.id }}")
{% endfor %}
</script>
{% endblock main %}

View File

@ -47,10 +47,10 @@
<div id="print">
<div class="row">
<div class="col">
<div id="qrcode"></div>
<div id="{{ tag.id }}"></div>
</div>
<div class="col">
<div style="padding-top: 55px"><b id="tag">{{ tag.id }}</b></div>
<div style="padding-top: 55px"><b class="tag">{{ tag.id }}</b></div>
</div>
</div>
</div>
@ -109,6 +109,6 @@
<script src="{{ url_for('static', filename='js/jspdf.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/print.pdf.js') }}"></script>
<script type="text/javascript">
qr_draw("{{url_for('inventory.device_details', id=tag.device.devicehub_id, _external=True)}}");
qr_draw("{{url_for('inventory.device_details', id=tag.device.devicehub_id, _external=True)}}", "#{{ tag.id }}");
</script>
{% endblock main %}