用阿拉伯字体生成PDF [英] Generate Pdf with Arabic fonts

查看:43
本文介绍了用阿拉伯字体生成PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 react 中下载带有阿拉伯字体的 pdf 文件,但没有找到任何解决方案.我目前正在使用 jsPdf 但它没有正确呈现阿拉伯字体

I want to download a pdf file with Arabic fonts in react and haven't found any solution. I am currently using jsPdf but it's not rendering Arabic font's properly

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

First download a desired font. Then go to https://rawgit.com/MrRio/jsPDF/master/fontconverter/fontconverter.html

并转换 &下载文件.将其移动到您的项目目录并将其导入所需的模块中.

and convert & download the file. Move it to your project directory and import it in the desired module.

您也可以将大字符串放入变量 const myFont "VVV....VVV"

You can also take the large string and put it in a variable const myFont "VVV....VVV"

然后像这样使用它.

   doc.addFileToVFS("MyFont.ttf", myFont);
   doc.addFont("MyFont.ttf", "MyFont", "normal");
   doc.setFont("MyFont");

现在您需要右对齐文本.

Now you will need to right-align the text.

doc.text("Arabic Text", 200, 20, "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.
*/

这篇关于用阿拉伯字体生成PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆