简体   繁体   English

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

[英]how to remove margin or padding of window in javascript/css?

I'm trying to print image using javascript : 我正在尝试使用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..

It prints fine the problem is here : 它打印得很好,问题在这里:

在此处输入图片说明

I want to remove that empty space because I'm printing it on narrow paper(bill/receipt paper). 我要删除该空白区域,因为我将其打印在窄纸上(比尔/收据纸)。 Image is prints very small think because of that empty spaces . 由于存在空白,图像打印很小。 I've tried like set style="margin-top:-25px; margin-left: -25px;" 我尝试过像set style="margin-top:-25px; margin-left: -25px;" on img but its prints like : img但是它的打印像:

在此处输入图片说明

How can I print the image on left top without any empty space? 如何在left top打印image而没有任何空白空间?

Help me.. Thank you.. 帮帮我..谢谢

You can try css @page 您可以尝试CSS @page

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

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

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