【问题标题】:Html text is not converting to Bold using PdfMakeHtml 文本未使用 PdfMake 转换为粗体
【发布时间】:2019-07-27 17:18:45
【问题描述】:

我正在使用 pdf make 将 HTML 内容转换为文本并下载为 pdf。

问题是,粗体标签中的文本没有正确转换。 谁能帮我解决这个问题??

请参考以下代码-

我将 HTML 内容存储在编码字符串中

const parser = new DOMParser();
const dom = parser.parseFromString(
   `<!doctype html><body>${encodedStr}`,
   'text/html');
const decodedString = dom.body.textContent;
const document = { content: [{ text: decodedString, fontSize: 15, alignment: 'justify' } ], pageOrientation: 'portrait', pageSize: 'A4' };

pdfMake.createPdf(document).download(downloadFileName);


Example content i'm using:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<p><strong>Bold text</strong></p><p><strong>I.&nbsp;&nbsp;&nbsp; Text in Bold</strong><br>
<p>Text</p>
</body>
</html>

【问题讨论】:

  • 你试过用&lt;b&gt;代替&lt;strong&gt;吗?始终使用您的工具检查兼容的标签/css,因为它与浏览器中的解析器不同
  • 它正在剥离标签

标签: html reactjs dom react-redux pdfmake


【解决方案1】:

“b”也不起作用 尝试使用“强”。不工作。 不工作。 如果您使用“h1 或 h2”之类的标签,它就可以工作。 但问题是,它会使字体变大,这不是必需的。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-18
  • 2019-11-25
  • 1970-01-01
  • 2016-06-22
  • 2020-01-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多