简体   繁体   English

如何使用jQuery打印多个条形码图像

[英]how to print multiple barcode images using jquery

I have generated multiple barcodes using this code: 我使用以下代码生成了多个条形码:

function getCode() {
    var multipleCodes = document.getElementById('codeArea').value;
    var eachLine = multipleCodes.split('\n');
    console.log("eachLine = " + eachLine);
    for (var i = 0; i < eachLine.length; i++) {
        console.log("Inside loop: " + eachLine[i]);

        var div = document.createElement('iframe');
        div.innerHTML = "";

        div.setAttribute('id', 'iFrameID' + i);
        document.body.appendChild(div);
        document.getElementById('iFrameID' + i).src = 'barCodeGenerator/generateBarCode.php?q=' + eachLine[i];

    }

and trying to print it by using this method: 并尝试使用以下方法将其打印:

function printDiv(divName) {
    var strName = document.getElementById("codeArea").value;
    var imageId = document.getElementsByClassName('decoded');

    var imagObject = new Image();
    imagObject = imageId;
    var originalImage = '<img id="imageViewer" src="' + imageSrc + '" style="padding-top: 20px"   alt="' + imageSrc + '" />';
    popup = window.open('', 'popup', 'toolbar=no,menubar=no,width=700,height=650');
    popup.document.open();
    popup.document.write("<html><head></head><body onload='print()'>");
    popup.document.write(originalImage);
    popup.document.write("</body></html>");
    window.close('popup');
    popup.document.close();
    setTimeout(function () { popup.close(); }, 8000);
}

which only print single image by merging all barcodes. 通过合并所有条形码仅打印单个图像。 How can i print them separately as multiple images. 如何将它们分别打印为多张图像。 Any help will be appreciated. 任何帮助将不胜感激。

The most part of this code is irrelevant to your question. 此代码的大部分与您的问题无关。 Consider removing your logs, the parts about showing popup and hiding it for more clearance. 考虑删除日志,这是有关显示弹出窗口并将其隐藏以获取更多权限的部分。

Seems imageSrc variable in your code contains the source of one image, so you need to change your code by sending the array of image sources and iterating over it: 您的代码中的imageSrc变量似乎包含一个图像的源,因此您需要通过发送图像源数组并对其进行迭代来更改代码:

var originalImage = '';
// assuming imageSrc is an array of image sources
for (var i=; i < imageSrc.length; i++) {

    // note that I'm changing the id of the image a litle bit to ensure it will remain unique
    originalImage  += '<img id="imageViewer' + i + '" src="' + imageSrc[i] + '" style="padding-top: 20px"   alt="' + imageSrc[i] + '" />';

}

then the rest of your code must work. 那么其余的代码必须正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM