【发布时间】:2021-08-11 22:18:30
【问题描述】:
我正在开发一个电影票务应用程序,当我打印票时,它总是打印在 A4 页面上。我需要小页面上的票,而不是全尺寸 a4 页面上的票。我尝试使用 CSS 解决此问题,但页面大小的结果始终相同。
HTML 模板
data:text/html;charset=utf-8,
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Print Ticket</title>
<style type="text/css">
</style>
</head>
<body>
<div>
<div style="width: 471px; height: 431px; padding-left: 20px; border-radius: 10px 10px 0 0; font-family: Helvetica; display: flex">
<div style=" width: 470px;">
<div style="display: flex;">
<div style="height: 80px">
<h1 style="border-bottom: 6px rgb(147, 47, 60) solid;">YABOUS TICKET</h1>
</div>
</div>
<div style="width: 470px; display: flex;">
<div style="max-width: 280px">
<div style="width: 310px; height: 70px; display: flex; justify-content: space-between;">
<div style="width:240px"> <span style="font-weight: 550; font-size: 20px">EVENT</span>
<br> <span style="font-size: 20px">%event%</span>
</div>
</div>
<div style="height: 70px; max-width: 290px">
<span style="font-weight: 550; font-size: 20px">HALL</span>
<br> <span style="font-size: 20px">%hall%</span>
</div>
<div style="height: 70px"> <span style="font-weight: 550; font-size: 20px">TICKET NO.</span><span style="font-weight: 550; font-size: 20px; margin-left: 90px;">PRICE</span>
<br> <span style="font-size: 20px">%seatNo%</span> <span style="font-size: 20px; margin-right: 35px; float: right">%ticketPrice%</span>
</div>
<div style="height: 90px; display: flex; align-items: flex-end">
<div style="width: 80px; height: 70px"> <span style="font-weight: 550; font-size: 15px">FLOOR</span>
<br> <span style="color: rgb(69, 68, 67); font-size: 25px"><b>%floor%</b></span>
</div>
<div style="width: 80px; height: 70px"> <span style="font-weight: 550; font-size: 15px">SEAT</span>
<br> <span style="color: rgb(69, 68, 67); font-size: 25px"><b>%seat%</b></span>
</div>
<div style="width: 80px; height: 70px"> <span style="font-weight: 550; font-size: 15px">ROW</span>
<br> <span style="color: rgb(69, 68, 67); font-size: 25px;"><b>%row%</b></span>
</div>
</div>
<div>
<span style="font-size: 11px; color: rgb(147, 47, 60)">GATE CLOSES 30 MINUTES BEFORE EVENT START</span>
</div>
</div>
<div style="width: 185px; display: flex; justify-content: center; flex-direction: column; padding-top: 30px">
<div style="display: flex; justify-content: center; width: 100%">
<div>
<span style="font-weight: 550; font-size: 16px">EVENT TIME</span>
<br>
<div style="display: flex;flex-direction: column;"> <span style="font-size: 25px"><b>%time%</b></span> <span style="color: rgb(69, 68, 67); font-size: 20px;">%date%</span> </div>
</div>
</div>
<div style="display: flex;justify-content: center; align-items: center; height: 200px"> <img src="%qrCode%" width="200"> </div>
</div>
</div>
</div>
</div>
<div style="width: 496px; height: 23px; background: rgb(147, 47, 60); border-radius: 0 0 10px 10px;color: white; font-family: Helvetica; display: flex; justify-content: space-between; padding-right: 12px; padding-left: 12px; font-size: 15px; padding-top: 5px; -webkit-print-color-adjust: exact; ">
<span>
<b>WWW.YABOUS.ORG</b>
</span>
<span>
<b>YABOUS</b>
</span>
</div>
</div>
</body>
JS 代码
const options = {
silent: false,
marginType: 1,
landscape: true,
pagesPerSheet: 1,
collate: true,
copies: 1,
printBackground: true,
pageSize: {
height: 454,
width: 471
}
}
let win2 = new BrowserWindow({
height: 454,
width: 471,
icon: __dirname + `/dist/storyteller/assets/favicon.ico`
});
win2.setMenu(null);
win2.loadURL(page);
// win2.webContents.reload();
// let win = BrowserWindow.getAllWindows()[0];
win2.webContents.on('did-finish-load', () => {
win2.webContents.print(options, (success, failureReason) => {
if (!success) console.log(failureReason);
console.log('Print Initiated');
});
})
打印结果
我需要删除工单周围的空白,使工单适合页面。
【问题讨论】:
标签: javascript node.js electron desktop-application