【发布时间】: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. Text in Bold</strong><br>
<p>Text</p>
</body>
</html>
【问题讨论】:
-
你试过用
<b>代替<strong>吗?始终使用您的工具检查兼容的标签/css,因为它与浏览器中的解析器不同 -
它正在剥离标签
标签: html reactjs dom react-redux pdfmake