[英]Add FontAwesome Icon in jsPdf
I am using jspdf.debug.js
latest version.我正在使用
jspdf.debug.js
最新版本。 FontAwesome
icons used in a web page are not rendering in pdf
.网页中使用的
FontAwesome
图标不会以pdf
呈现。 I added a FontAwesome
user icon in the page.Refer to the image.(Left one is HTML
and pdf
output is on right) Below is my code snippet.我在页面中添加了一个
FontAwesome
用户图标。参考图片。(左边是HTML
,右边是pdf
输出)下面是我的代码片段。
var pdf = new jsPDF('p', 'pt', 'letter');
pdf.addFont('FontAwesome', 'FontAwesome', 'normal');
pdf.setFont('FontAwesome');
pdf.canvas.height = 72 * 11;
pdf.canvas.width = 72 * 8.5;
html2pdf(document.body, pdf, function(pdf){
var iframe = document.createElement('iframe');
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
document.body.appendChild(iframe);
iframe.src = pdf.output('datauristring');
});
jspdf does not support special symbols. jspdf 不支持特殊符号。 Here is the gitHub issue .
这是gitHub 问题。 See info in this answer .
请参阅此答案中的信息。
I did in this way and all works with font Awesome 5...<\/i>我就是这样做的,并且所有字体都可以使用 Awesome 5 ...<\/b><\/p>
Following this article<\/a> i uploaded the fa-solid-900-normal.ttf at https:\/\/peckconsulting.s3.amazonaws.com\/fontconverter\/fontconverter.html<\/a><\/i>在
这篇文章<\/a>之后,我在https:\/\/peckconsulting.s3.amazonaws.com\/fontconverter\/fontconverter.html<\/a>上传了 fa-solid-900-normal.ttf<\/b><\/p><\/li>
I got the js file and import it.<\/i>我得到了js文件并导入它。<\/b><\/p><\/li>
In Angular i did in this way<\/i>在Angular中我这样做了<\/b><\/p>
constructor() { var callAddFont = function () { this.addFileToVFS('fa-solid-900-normal.ttf', jsPDFfonts.fontawesome5_fa_solid_900); this.addFont('fa-solid-900-normal.ttf', 'fa-solid-900', 'normal'); }; jsPDF.API.events.push(['addFonts', callAddFont])<\/code><\/pre>
}<\/i> }<\/b><\/p><\/li><\/ol>
where
jsPDFfonts.fontawesome5_fa_solid_900<\/code> is the content of the file<\/i>其中
jsPDFfonts.fontawesome5_fa_solid_900<\/code>是文件的内容<\/b><\/p>
Then during the print process for printing an icon i did in this way<\/i>然后在打印图标的打印过程中我以这种方式<\/b><\/p>
pdf.setFont('fa-solid-900', 'normal'); pdf.setFontSize(10); pdf.text('\', 15, 15*index);<\/code><\/pre><\/li><\/ol>
i printed directly the unicode of the icon<\/i>我直接打印了图标的unicode<\/b><\/p>"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.