生成带有阿拉伯字体的Pdf [英] Generate Pdf with Arabic fonts

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

问题描述

我想下载带有阿拉伯字体的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天全站免登陆