如何从图像数据JavaScript中打印图像

时间:2018-06-11 03:28:46

标签: javascript jquery printing

我希望用PDF打印图像,我有一个按钮打印:

<input type="button" onclick="PrintImage()" value="Print">

我想要打印到下面的窗口:

function PrintImage(){
   var myImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABOkAAAKIC.........";
    window.open( myImage );
}

2 个答案:

答案 0 :(得分:0)

这是我的问题解决方案..:D 这可能对你有帮助..

    <input type="button" onclick="PrintImage()" value="Print">
<script>
function PrintImage(){
   var myImage = "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7";
    //var image = new Image();
    //image.src=myImage;
    var myWindow = window.open("", "Image");
    myWindow.document.write('<img src="'+myImage+'"/>');
}
</script>

答案 1 :(得分:0)

试试这个:

<input type="button" onclick="PrintImage()" value="Print">

<script type="text/javascript">
function PrintImage() {
    var myImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABOkAAAKIC.........";
    var myWindow = window.open("", "Image");
    myWindow.document.write("<img src='"+myImage+"''>");
    myWindow.print();
}
</script>