html - Bootstrap CSS 文件不会加载到 PDF usinf Flying Saucer 核心中
问题描述
我已经搜索了两天,但找不到解决方案。我必须制作一个pdf
必须在浏览器中打开的表单。我决定使用flying saucer library
.In html 我的内部 CSS 类成功加载,但 Bootstrap 没有加载。
这是我的Java代码:
public ByteArrayOutputStream html2PdfGenerator() {
context.setVariable("baseUrl", getCurrentBaseUrl());
String processedHtml = templateEngine.process("mainPolicy", context);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ITextRenderer renderer = new ITextRenderer();
URL fontResourceURL = getClass().getResource("/static/fonts/Calibri.ttf");
renderer.getFontResolver().addFont(fontResourceURL.getPath(),
BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.setDocumentFromString(processedHtml, urlBase);
renderer.layout();
renderer.createPDF(bos);
renderer.finishPDF();
bos.flush();
} catch (Exception e) {
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
}
}
}
return bos;
}
这是我的html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content=""/>
<meta name="author" content=""/>
<link href="/css/bootstrap.css" rel="stylesheet" type="text/css" media="all"/>
<link href="/css/insurance.css"
rel="stylesheet" type="text/css"/>
</head>
我的文件夹结构是/resource/static/css。Insurance css
加载,但bootstrap
没有。我试图在tymeleaf 中包含 css但没有成功。
解决方案
推荐阅读
- hadoop - Hadoop 3.2.1 和 HBase 2.2.3 不兼容:hadoop-functions.sh 中的错误
- python - IF、ELIF、ELSE 语句缩进
- qt - 如何在选择或取消选择时直接通知 QGraphicsItem
- javascript - 或选择器中的运算符
- python-3.x - Python Crypto.Cipher 是否直接接收十六进制数据?
- mysql - Python2.7 中的 MySQL 连接池无法按预期工作。连接池的close()函数面临问题
- android - 如何将 PreferenceHandler 字符串值更改为 IntetService
- android - 如何选择蓝牙协议反应原生库?
- python-3.x - Pandas DataFrame 中的压缩列
- python - 为什么 Pandas 没有提供使用 .apply 的选项?