我想在React中下载带有阿拉伯字体的pdf文件,但没有找到任何解决方案。我目前正在使用 jsPdf 但它无法正确渲染阿拉伯字体
let doc = new PDFDocument
let doc = new pdf();
doc.setFontSize(10);
doc.rect(20, 20, doc.internal.pageSize.getWidth() - 40,
doc.internal.pageSize.getHeight() - 40, 'S');
doc.setTextColor(128,0,128);
doc.text("Date", 30, 25);
doc.text(this.state.date, 50, 25);
doc.text("السلام عليكم", 30, 35);
doc.text("Quantity", 120, 35);
let distance = 30;
doc.save("data.pdf");
提前致谢
首先下载所需的字体。然后去https://rawgit.com/MrRio/jsPDF/master/fontconverter/fontconverter.html https://rawgit.com/MrRio/jsPDF/master/fontconverter/fontconverter.html
并转换并下载文件。将其移至您的项目目录并将其导入所需的模块中。
您还可以将大字符串放入变量中const myFont = "VVV....VVV"
然后像这样使用它。
doc.addFileToVFS("MyFont.ttf", myFont);
doc.addFont("MyFont.ttf", "MyFont", "normal");
doc.setFont("MyFont");
现在您需要右对齐文本。
doc.text("Arabic Text", 200, 20, "right");
//OR
doc.text("Arabic Text", 200, 20, { align : "right" } );
/*
200 is the x coordinate and marks the starting position of the text from right.
y coordinate is the distance from the top of the page.
*/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)