gpt4 book ai didi

jquery - 需要使用 jquery 动态添加字体系列点阵进行打印

转载 作者:行者123 更新时间:2023-11-28 06:21:43 24 4
gpt4 key购买 nike

我在 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);
});

这里我将字体系列指定为控制台,正如您在这一行中看到的那样

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 动态地使用它,就像上面的同一行。

最佳答案

我得到的解决方案是:

newWin.document.write('<html><style>@font-face {font-family: DotMatrix;src: url("fonts/1979_dot_matrix.ttf");}</style><body onload="window.print()" style="font:1em DotMatrix;margin-left:30px;">' + divToPrint.innerHTML + '</body></html>');

关于jquery - 需要使用 jquery 动态添加字体系列点阵进行打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35553577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com