javascript - 如何在 javascript/css 中删除窗口的边距或填充?

标签 javascript jquery html css

我正在尝试使用 javascript 打印图像:

function printImage(src){
        var printWindow = window.open('', 'Print Window','height=400,width=600');
        printWindow.document.write('<html><head><title>Print Window</title>');
        printWindow.document.write('</head><body ><img src=\'');
        printWindow.document.write(src);
        printWindow.document.write('\' /></body></html>');
        printWindow.document.close();
        printWindow.print();
}

printImage(src); //this is image src..

打印正常,问题出在这里:

enter image description here

我想删除那个空白区域,因为我正在将它打印在窄纸(账单/收据纸)上。由于那个空白区域,图像打印得非常小。我试过像 set style="margin-top:-25px; margin-left: -25px;" on img 但它的打印像:

enter image description here

如何在 left top 上打印 image 而没有任何空白?

帮帮我.. 谢谢..

最佳答案

你可以试试css @page

@page {
    size: auto;
    margin: 0;
}

关于javascript - 如何在 javascript/css 中删除窗口的边距或填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29793102/

相关文章:

javascript - iOS 8 故障影响窗口大小调整

javascript - AngularJS - 在另一个图像之上显示图像

Javascript 贪吃蛇游戏(防止逆转,同时保持响应能力)

json - 使用 jquery ajax 发布数组

javascript - 扩展错误 es6 类模块问题

javascript - Jquery自动完成在结果和结果之间有空格,结果未显示在模式中

php - 将用户的输入存储到数据库中

jQuery slider : Active links

javascript - toPrecision 的行为是否像 round 和 toString 一样?

javascript - 如何从 Tr 重复的输入文本中获取值?