有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Springboot&Thymeleaf:HTML>PDF转换

将HTML转换为PDF时出错

ERROR: 'The element type "link" must be terminated by the matching end-tag "".' org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TrAX transformer). org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 3; The element type "link" must be terminated by the matching end-tag "".

该项目基于Springboot和Thymeleaf

Springboot为用户提供了一个带有一系列复选框的表单。表单如下所示:

enter image description here

当formdata被提交到后端时,它会被放回HTML表单的副本中,以便呈现为PDF。我使用的是here中概述的技术

邮政总监:

    @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();
    }

以及评估模板。html

<!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>

排队的时候

pdfGenaratorUtil.createPdf("assessmenttemplate.html",data);

正在运行stacktrace

ERROR: 'The element type "link" must be terminated by the matching end-tag "".' org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TrAX transformer). org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 3; The element type "link" must be terminated by the matching end-tag "".

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


共 (1) 个答案

  1. # 1 楼答案

    我用/>;关闭了所有标签,解决了这个问题;。我还必须关闭Meta标签和所有输入标签