0

我正在尝试使用 printThis jQuery 插件在我的网页上打印一些“选择的”内容。当我按print_btn时,打印中没有图像或<hr>显示。为什么?

HTML

<button id="print_btn"></button>
<div class="elementBricka display" style="page-break-after:always">
    <div class="lkbLoggo"></div>
    <hr>
     ....

CSS

#elementBrickor{
    align-items: center;
}

.elementBricka{
    width: 9.614cm;
    height: 14.404cm;
    border: 1px solid;
    background-color: white;

    float: none;
    margin-left: auto;
    margin-right: auto;
}
.lkbLoggo{
    width: 9.182cm;
    height: 2.721cm;
    margin-top: 0.199cm;
    background-image: url("/img/lkb_logga2.png");
    background-repeat: no-repeat;
    background-position: center;
}

JS

$(document).ready(function () {
    $('#print_btn').click(function () {
        $('.display').printThis({
            debug: true,
            importCSS: true,
            importStyle: true,
            loadCSS: "/Data.css",
            pageTitle: false,
        });
    });
});

更新

我会回答我自己的问题。
这与“PrintThis”无关。
这是一个浏览器“问题”。
但是通过添加很容易修复:!important在我加载img的Css文件中。

4

4 回答 4

2

我的解决方案是实施

-webkit-print-color-adjust:精确!重要;

于 2020-10-15T15:02:10.570 回答
1

图像通常不会打印,因为这是浏览器中的设置。

转到工具 / Internet 选项 / 高级 / 并确保勾选“打印背景和图像”。

但是,没有解决方法可以使用 printThis 插件打印要打印的图像。

如果您想尝试使用 jquery 打印图像,您可以这样做:http: //jsfiddle.net/8dXvt/626/

function nWin() {
  var w = window.open();
  var html = $("#toNewWindow").html();
  /*for(var i=0;i<5;i++){
  $("#toNewWindow").clone().prependTo("body")
 }*/
 $(w.document.body).html(html);
 setTimeout(function(){w.print()}, 1500);
}
于 2015-11-25T13:35:18.370 回答
1
$('.display').printThis({
base='true'
});

尝试这个

于 2017-11-01T10:38:44.650 回答
0

好的,所以没有办法让“PrintThis”打印我的图像。
但我在 CSS 中找到了一种方法:

.lkbLoggo{
    width: 9.182cm !important;
    height: 2.721cm !important;
    margin-top: 0.199cm !important;
    background-image: url("/img/lkb_logga2.png") !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
}

只需!important在每行之后添加,它就会显示在打印中。
现在..我想要一个使整个班级变得重要的功能,而不是将其添加到每一行。

于 2015-11-26T08:23:53.297 回答