简体   繁体   中英

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

I'm trying to print image using 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;" on img but its prints like :

在此处输入图片说明

How can I print the image on left top without any empty space?

Help me.. Thank you..

You can try css @page

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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