generate pdf with multiple devices
This commit is contained in:
parent
a8df3f5e5a
commit
a36fb0b0fc
|
@ -5,8 +5,8 @@ $(document).ready(function() {
|
||||||
load_size();
|
load_size();
|
||||||
})
|
})
|
||||||
|
|
||||||
function qr_draw(url) {
|
function qr_draw(url, id) {
|
||||||
var qrcode = new QRCode($("#qrcode")[0], {
|
var qrcode = new QRCode($(id)[0], {
|
||||||
text: url,
|
text: url,
|
||||||
width: 128,
|
width: 128,
|
||||||
height: 128,
|
height: 128,
|
||||||
|
@ -54,16 +54,26 @@ function printpdf() {
|
||||||
var border = 2;
|
var border = 2;
|
||||||
var height = parseInt($("#height-tag").val());
|
var height = parseInt($("#height-tag").val());
|
||||||
var width = parseInt($("#width-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;
|
img_side = Math.min(height, width) - 2*border;
|
||||||
max_tag_side = (Math.max(height, width)/2) + border;
|
max_tag_side = (Math.max(height, width)/2) + border;
|
||||||
if (max_tag_side < img_side) {
|
if (max_tag_side < img_side) {
|
||||||
max_tag_side = img_side+ 2*border;
|
max_tag_side = img_side+ 2*border;
|
||||||
};
|
};
|
||||||
min_tag_side = (Math.min(height, width)/2) + border;
|
min_tag_side = (Math.min(height, width)/2) + border;
|
||||||
|
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.addImage(imgData, 'PNG', border, border, img_side, img_side);
|
||||||
pdf.text(tag, max_tag_side, min_tag_side);
|
pdf.text(tag, max_tag_side, min_tag_side);
|
||||||
pdf.save('Tag_'+tag+'.pdf');
|
});
|
||||||
|
|
||||||
|
pdf.save('Tag_'+last_tag_code+'.pdf');
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,9 @@
|
||||||
<div id="{{ tag.id }}"></div>
|
<div id="{{ tag.id }}"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -95,14 +97,7 @@
|
||||||
<script src="{{ url_for('static', filename='js/print.pdf.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/print.pdf.js') }}"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
{% for tag in tags %}
|
{% for tag in tags %}
|
||||||
new QRCode(document.getElementById("{{ tag.id }}"), {
|
qr_draw("{{ url_for('inventory.device_details', id=tag.device.devicehub_id, _external=True) }}", "#{{ 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
|
|
||||||
});
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</script>
|
</script>
|
||||||
{% endblock main %}
|
{% endblock main %}
|
||||||
|
|
|
@ -47,10 +47,10 @@
|
||||||
<div id="print">
|
<div id="print">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div id="qrcode"></div>
|
<div id="{{ tag.id }}"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<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>
|
</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/jspdf.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/print.pdf.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/print.pdf.js') }}"></script>
|
||||||
<script type="text/javascript">
|
<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>
|
</script>
|
||||||
{% endblock main %}
|
{% endblock main %}
|
||||||
|
|
Reference in a new issue