html - 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. Text in Bold</strong><br>
<p>Text</p>
</body>
</html>
解决方案
“b”也不起作用尝试使用“strong”。不工作。不工作。如果您使用“h1 或 h2”之类的标签,它就可以工作。但问题是,它会使字体变大,这不是必需的。
推荐阅读
- php - 使用 Laravel 5.6 api 验证 JSON Post
- r - Three continuous Explanatory Variables Visualization in R
- c# - I am receiving an error like "physical path is not allowed ,virtual path only allowed " while exporting a excel file need to save in specific location
- c# - C#:Overlapped Class
- react-native - How do I test how a mobile app gets foregrounded?
- c - How to use global variables in an ISR (Interrupt Handler)
- php - Why the logo didn't appear in website?
- python - 如何调试“您可能需要将 'maginate.net' 添加到 ALLOWED_HOSTS”
- matlab - Sliced Variables in PARFOR loop: Sequential to Parallel Conversion in MATLAB
- c# - MySql 连接。值不能为空。参数名称:类型