首页 > 解决方案 > 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/cssInsurance css加载,但bootstrap没有。我试图在tymeleaf 中包含 css但没有成功。

标签: htmlspringspring-bootbootstrap-4flying-saucer

解决方案


推荐阅读