freemaker 导出 ueditor 编辑内容 到pdf

本文介绍如何使用Freemarker模板引擎将UEditor编辑的内容导出为PDF文件。包括制作FTL模板、安装所需字体、选择模板工具以及实现导出接口的详细步骤。重点在于网络内容的获取和本地文件的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、制作文件模板  pdf.ftl

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"></meta>
    <style type="text/css">
        body {
            font-family: SimSun;
        }
        .title_item {
            width: 100%;
            text-align: center
        }
        .tr_item2{
            width: 650px;
            word-wrap:break-word;
        }
    </style>
</head>
<body>
<p class="title_item">${paperTiele}</p>

<table style="word-wrap:break-word; word-break:break-all;width: 693px;table-layout: fixed">
    <tbody>
        <#list vms as vm>
            <tr>
                <td style="width:20px;text-align:top;vertical-align: text-top;">${vm.sortNum}、</td>
                <td class="tr_item2" style="word-wrap:break-word;word-break:break-all;">${vm.exerciseInfo}</td>
            </tr>
                <#list vm.options as optItem>
                    <tr>
                        <td style="width:20px;text-align:top;;"></td>
                        <td class="tr_item2">&nbsp;${optItem.optionIndex}:${optItem.optionContent}</td>
                    </tr>
                </#list>
            <tr>
                <td style="width: 20px;px;text-align:top;;"></td>
                <td class="tr_item2">【正确答案】:${vm.answer}</td>
            </tr>
            <tr>
                <td style="width:20px;text-align:top;;"></td>
                <td class="tr_item2">【解析】:${vm.explain}</td>
            </tr>
            <tr style="height:20px;"><td style="width:20px;text-align:top;;"></td><td></td></tr>
            <tr style="height:20px;"><td style="width:20px;text-align:top;;"></td><td></td></tr>
        </#list>
    </tbody>
</table>
</body>
</html>

二、安装字体

三、模板工具

package com.xw.ssm.util.pdf;

import com.lowagie.text.pdf.BaseFont;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.xhtmlrenderer.pdf.ITextRenderer;

import java.io.OutputStream;
import java.io.StringWriter;
import java.util.Locale;

/**
 * freemarker模板生成PDF工具类
 *
 * @author ZSX
 */
public class PDFTemplateUtil {

    /**
     * classpath路径
     */
    private String classpath = getClass().getResource("/").getPath();

    /**
     * 指定FreeMarker模板文件的位置
     */
    private String
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值