我在 jquery 中有一个打印功能,如下所示:
$("#btn_print").click(function () {
//Create print div
populatePrintdiv();
$("#btn_cmplte").css('display', 'block');
var divToPrint = document.getElementById('printdiv');
var newWin = window.open('', 'Print-Window');
newWin.document.open();
newWin.document.write('<html><body onload="window.print()" style="font-family:consolas;margin-left:30px;">' + divToPrint.innerHTML + '</body></html>');
newWin.document.close();
setTimeout(function () {
newWin.close();
}, 10);
});
在这里,我将 font-family 指定为控制台,正如您在这一行中看到的那样
newWin.document.write('<html><body onload="window.print()" style="font-family:consolas;margin-left:30px;">' + divToPrint.innerHTML + '</body></html>');
我想使用点阵字体系列,所以我下载了字体系列1979_dot_matrix.ttf
文件并将其放在我的项目fonts
文件夹中。
如何在里面使用字体包含这个字体系列:
newWin.document.write('<html><body onload="window.print()" style="font-family:consolas;margin-left:30px;">' + divToPrint.innerHTML + '</body></html>');
在 css 中,它看起来像:
@font-face {
font-family: 1979_dot_matrix;
src: local("1979_dot_matrix"),
local("1979_dot_matrix"),
url(fonts/1979_dot_matrix.ttf);
font-weight: bold;
}
如何使用 jquery 动态使用它作为上面的同一行。