首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Springboot & Thymeleaf : HTML -> PDF转换

Springboot & Thymeleaf : HTML -> PDF转换
EN

Stack Overflow用户
提问于 2018-07-04 21:22:03
回答 1查看 3.5K关注 0票数 0

将HTML转换为PDF时出错

错误:“元素类型”"link“必须由匹配的结束标记”.“结束。org.xhtmlrenderer.util.XRRuntimeException:无法加载TrAX资源(使用TrAX转换器)。org.xml.sax.SAXParseException;lineNumber: 9;columnNumber: 3;元素类型"link“必须以匹配的结束标记"”结束。

该项目是基于Springboot和Thymeleaf的。

Springboot通过一系列复选框向用户提供表单。该表格如下:

当表单数据被提交到后端时,它会被放回HTML表单的副本中,以呈现为PDF。我正在使用概述的这里技术。

邮递员:

代码语言:javascript
复制
    @PostMapping("/assessment")
public String greetingSubmit(@ModelAttribute("assessemnt") Assessment assessment, BindingResult result, Model model,
                             HttpServletRequest request, SessionStatus status) throws IOException {

    // GET A LIST OF ATTRIBUTES IN CLASS AND PUT IN MAP
    Map<String, Object> map = oMapper.convertValue(assessment, Map.class);
    Iterator it = map.entrySet().iterator();

    Map<String,String> data = new HashMap<String,String>();
    it = map.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry)it.next();
        if (pair.getValue() instanceof Boolean) {
            if (pair.getValue().equals(true)) {
                data.put(pair.getKey().toString(), "checked");
            }
        }
    }

    try {
        pdfGenaratorUtil.createPdf("assessmenttemplate.html",data);
    } catch (Exception e) {
        e.printStackTrace();
    }

和assessmenttemplate.html

代码语言:javascript
复制
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Assessment</title>
<link rel="stylesheet" type="text/css" href="/css/assessment.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css">
</head>
<body>
<form action="#" th:action="@{/greeting}" method="post">
<div class="container">
    <div class="navbar navbar-default">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">Bootstrap 24445 + Flatly theme</a>
    </div>

</div>

<div class="panel-group" id="accordion">
    <div class="panel panel-default" id="panel1">

        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-target="#section1" href="#collapseOne">
                    Collapsible Group Item #1
                </a>
            </h4>
        </div>
        <div id="section1" class="panel-collapse collapse">

            <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird
                on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table,
                raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            </div>
                <div class="form-check form-check-inline">
                    <input class="form-check-input checkbox1" type="checkbox" id="section1Checkbox1" value="option1" th:field="*{needsAssessment.section1Checkbox1}">
                    <label class="form-check-label" for="section1Checkbox1">Checkbox 1</label>
                </div>

当线

代码语言:javascript
复制
pdfGenaratorUtil.createPdf("assessmenttemplate.html",data);

正在运行的堆栈跟踪是

错误:“元素类型”"link“必须由匹配的结束标记”.“结束。org.xhtmlrenderer.util.XRRuntimeException:无法加载TrAX资源(使用TrAX转换器)。org.xml.sax.SAXParseException;lineNumber: 9;columnNumber: 3;元素类型"link“必须以匹配的结束标记"”结束。

错误很明显--但是如果我将assessmenttemple.html上传到w3验证器,它会正确地抱怨th标签,但是链接标记没有关闭没有问题。

EN

回答 1

Stack Overflow用户

发布于 2018-07-04 21:49:47

我通过用/>关闭所有标记来修正它。我还必须关闭Meta标记和所有输入标记。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51180885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档