首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在jspdf-autotable头阿拉伯文本中断中

在jspdf-autotable头阿拉伯文本中断中
EN

Stack Overflow用户
提问于 2020-03-18 08:59:57
回答 2查看 1.4K关注 0票数 1
代码语言:javascript
运行
复制
 document.autoTable({
      head,
      body,
      startY: XX,
      styles: { lineColor: '#c7c7c7', lineWidth: 0, cellPadding: 2, font: 'Helvetica' },
      headStyles: { fillColor: '#ffffff', textColor: '#333333', font: 'Helvetica' },
      bodyStyles: { fillColor: '#f5f5f5', textColor: '#333333', fontSize: 7, lineColor: '#c7c7c7', lineWidth: 0 }
    });

head am passing as below:
const head = [{
        content: "طيران الإمارات",
        styles: { valign: 'centre', cellPadding: {top: 3}, fontSize: 9, fontStyle: 'bold', cellWidth: 110.6 },
      },
      {
        content: 'Miles',
        styles: { fontSize: 9, fontStyle: 'normal', valign: 'centre', cellWidth: 35 },
      },
      {
        content: 'Tier Miles',
        styles: { fontSize: 9, fontStyle: 'normal', valign: 'centre', cellWidth: 35 },
      }
      ];

使用Helvetica字体,头文本显示为特殊字符。特殊字符

使用自定义字体,它以阿拉伯语显示,但单词正在中断,我作为标题传递给了这个“طيرانالإمارات”,但在pdf中,它显示为这个طيرلإماطيرلإما

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-27 21:04:24

headStyles: { fillColor: '#bde4d1', textColor: '#333333' , fontStyle: 'Amiri' }

您必须在fontStyle对象中添加headStyles

票数 2
EN

Stack Overflow用户

发布于 2022-04-10 03:44:25

  1. 转到谷歌字体并下载Amiri字体 (我尝试过其他阿拉伯字体,但由于某种原因它们没有工作)。
  2. 转到这个转换器工具将字体转换为base64并下载生成的JavaScript文件(在转换Amiri字体时,每次上传一个.ttf文件,而不是完整的.zip文件夹,否则会出现错误。如果您想要添加更多的字体变体,上传并单独添加它们)。
  3. 转到您的项目并导入下载的文件(如果不使用模块,则手动添加脚本标记)。

代码语言:javascript
运行
复制
import "./fonts/Amiri";

// .... here goes your code working with the table.

  1. 如果您使用jspdf-自动表库,将以下代码添加到它的信任中:

代码语言:javascript
运行
复制
const jsPDFDoc = new jsPDF();

jsPDFDoc.autoTable({
  html: "#my-table",
  useCss: true,
  theme: "grid",
  headStyles: { font: "Amiri" }, // For Arabic text in the table head
  bodyStyles: { font: "Amiri" }, // For Arabic text in the table body
});

使用autotable的完整示例如下所示:

代码语言:javascript
运行
复制
import { jsPDF } from "jspdf";
import "jspdf-autotable";
import "../../../fonts/Amiri";

const jsPDFDoc = new jsPDF();

jsPDFDoc.autoTable({
  html: "#my-table",
  useCss: true,
  theme: "grid",
  headStyles: { font: "Amiri" },
  bodyStyles: { font: "Amiri" },
});

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60736255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档