admin管理员组文章数量:1399339
I have an HTML invoice template and I want to print this template (WHOLE PAGE) with custom sizes like 80mm and 297mm. I tried this code:
@media print {
@page {
size: 80mm 297mm;
margin: 0;
}
}
but it's not working. How can I print a page with custom sizes?
I have an HTML invoice template and I want to print this template (WHOLE PAGE) with custom sizes like 80mm and 297mm. I tried this code:
@media print {
@page {
size: 80mm 297mm;
margin: 0;
}
}
but it's not working. How can I print a page with custom sizes?
Share Improve this question edited Apr 8, 2021 at 14:28 Boussadjra Brahim 1 asked Sep 1, 2018 at 11:45 Mehmet Ali KuşMehmet Ali Kuş 791 silver badge8 bronze badges 4- what do you want to print exactly table or another thing? – Boussadjra Brahim Commented Sep 1, 2018 at 11:51
- 1 table. but i dont think its important – Mehmet Ali Kuş Commented Sep 1, 2018 at 12:03
- 2 could you provide some code to be more clear ? – Boussadjra Brahim Commented Sep 1, 2018 at 12:58
- bro i don't think you understand. I have a html invoice template. Think a page only content is a table. i want to print whole page and i am okey with it. But my problem is paper size. I want to print this page with invoice printer and this invoice printer sizes 8.5cm width X auto height. When i print the page, its show me full width a4 sizes content – Mehmet Ali Kuş Commented Sep 1, 2018 at 14:49
2 Answers
Reset to default 4You could use this JS function that allows you to print your content with the given size, you could call this function by firing an event
function print() {
var yourDOCTYPE = "<!DOCTYPE html>";
var printPreview = window.open('', 'print_preview');
var printDocument = printPreview.document;
printDocument.open();
var head =
"<head>" +
"<style> .to-print{height:279mm; width:80mm; } </style>" +
"</head>";
printDocument.write(yourDOCTYPE +
"<html>" +
head +
"<body>" +
"<div class='to-print'>" +
"<!-- your content to print can be put here or you can simply use document.getElementById('id-content-toprint')-->"+
"</div>"+
"</body>" +
"</html>");
printPreview.print();
printPreview.close()
}
you can wrap your whole page by a div
with id="main-page"
and use document.getElementById('main-page')
inside <div class='to-print'></div>
CSS Solution :
.printableArea {
width: 8.5cm; // !important
height:100%; // !important
}
@page {
size: 8cm auto; //
width: 8cm; //
height: 100%; //
margin: 0;
margin-left: 5px !important; // this is for me.
}
本文标签: javascriptVuejsHow can I print a web page with custom sizesStack Overflow
版权声明:本文标题:javascript - Vue.js - How can I print a web page with custom sizes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744188348a2594399.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论