首页 > 解决方案 > Html 文本未使用 PdfMake 转换为粗体

问题描述

我正在使用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>

标签: htmlreactjsdomreact-reduxpdfmake

解决方案


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


推荐阅读