跳转到内容

Java 生成「档案案卷封面(档案管理)」PDF 示例(Layout)

JQuick-PdfBiz Demo

Layout1 页 A4 · 15 KB

基建项目竣工资料移交档案室后打印的案卷封面:3pt 粗外框、顶部全宗号与密级两端分列、中部三级超大字号题名区、两列案卷信息表与底部立卷 / 检查双栏。

下载 PDF 文件查看模板原始文件返回全部示例

档案案卷封面(档案管理) — Layout
渲染效果

输出规格

PDF 页数
1
图表类型
Layout
模板行数
71
源码行数
63

Java 源码 · JQuickBiz55ArchiveCoverTest.java

以下代码即生成上方 PDF 的完整测试类,可直接复制运行;Maven 依赖见快速开始章节。

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright (c) [2025-2099] Martin ([email protected])
 */
package com.github.paohaijiao.demo.biz;

import com.github.paohaijiao.config.JPdfConfig;
import com.github.paohaijiao.demo.constant.JQuickConstant;
import com.github.paohaijiao.executor.JQuickPdfFactory;
import org.junit.Test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 档案封面 Demo 55:档案案卷封面(档案管理场景)
 *
 * <p>业务场景:基建项目竣工资料移交档案室后,为案卷打印封面,需体现全宗号、密级、
 * 案卷题名与档案号等要素,供装盒上架使用。</p>
 *
 * <p>版式:整页 3pt 粗外框 + 顶部全宗号与密级分列两端 + 中部超大字号题名区
 * (单位名 14pt / 案卷类别 22pt / 保管期限 11pt 三级层次)+ 两列「标签 + 下划线值」
 * 案卷信息表 + 底部立卷人与检查人双栏 + 居中单位与年月。</p>
 *
 * <p>本模板为纯版式 Demo,不含图表,因此不需要绑定 {@code svg} 变量;
 * 模板:{@code report/biz/55_archive_cover.txt},输出:{@code D:\test\biz\55_archive_cover.pdf}。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickBiz55ArchiveCoverTest {

    public static final String path = JQuickConstant.path;

    @Test
    public void biz55ArchiveCover() throws IOException {
        File dir = new File(path + "biz");
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(path + "biz/55_archive_cover.pdf");
        JPdfConfig config = new JPdfConfig();
        // 开启 flex 行布局,使模板中的 display:flex 生效(全宗号与密级两端对齐、立卷/检查双栏)
        config.getLayoutConfig().setFlexLayout(true);
        JQuickPdfFactory factory = new JQuickPdfFactory(config);
        byte[] bytes = factory.executeResource("report/biz/55_archive_cover.txt");
        fileOutputStream.write(bytes);
        fileOutputStream.close();
    }
}

最小调用(3 行)

不想读完整测试类?核心就是这三行:绑定图表 SVG,执行模板,拿到 PDF 字节流。可直接复制到你的项目里。

// config 可省略;svg 来自 JChartRendererFactory.renderChart(...),见下方完整源码
byte[] pdf = new JQuickPdfFactory(config).executeResource("report/biz/55_archive_cover.txt");

模板文件 · 55_archive_cover.txt

类 HTML + 内联 CSS 的模板语法,绑定数据后渲染为 PDF。下方为完整模板,可直接复制,也可下载原始文件。

<pdf>
<body>
  <div style="border:3px solid #6B4A2F; padding:20px">

    // ---------- 顶部:全宗号 与 密级 ----------
    <div style="display:flex; justifyContent:space-between">
      <div style="width:300px">
        <p style="fontSize:9pt; color:#6B4A2F; bold:true">'全宗号:QZ-2024-018'</p>
      </div>
      <div style="width:200px; textAlignment:right">
        <p style="fontSize:10pt; color:#B71C1C; bold:true; characterSpacing:3pt">'密级:内部'</p>
      </div>
    </div>

    // ---------- 中部题名区:三级字号层次 ----------
    <h1 style="fontSize:14pt; bold:true; color:#3E2A1A; textAlignment:center; marginTop:70px; marginBottom:8px">'××市交通运输局'</h1>
    <h1 style="fontSize:22pt; bold:true; color:#1A2733; textAlignment:center; characterSpacing:10pt; marginBottom:10px">'基本建设项目档案'</h1>
    <p style="fontSize:11pt; color:#6B4A2F; textAlignment:center; characterSpacing:4pt; marginBottom:56px">'(永 久 保 管)'</p>

    // ---------- 案卷信息:四列「标签 + 下划线值」 ----------
    <table style="width:470px; fontSize:10pt">
      <tr>
        <td style="width:90px; padding:7px; textAlignment:right; color:#5A6B7C">'案卷题名:'</td>
        <td style="width:300px; padding:7px; color:#1A2733; borderBottom:1px solid #8C7A6B">'××路地下管网改造工程竣工资料'</td>
      </tr>
      <tr>
        <td style="padding:7px; textAlignment:right; color:#5A6B7C">'编制单位:'</td>
        <td style="padding:7px; color:#1A2733; borderBottom:1px solid #8C7A6B">'××市政建设集团有限公司'</td>
      </tr>
      <tr>
        <td style="padding:7px; textAlignment:right; color:#5A6B7C">'编制日期:'</td>
        <td style="padding:7px; color:#1A2733; borderBottom:1px solid #8C7A6B">'2024年12月20日'</td>
      </tr>
      <tr>
        <td style="padding:7px; textAlignment:right; color:#5A6B7C">'归档年度:'</td>
        <td style="padding:7px; color:#1A2733; borderBottom:1px solid #8C7A6B">'2024年度'</td>
      </tr>
      <tr>
        <td style="padding:7px; textAlignment:right; color:#5A6B7C">'保管期限:'</td>
        <td style="padding:7px; color:#1A2733; borderBottom:1px solid #8C7A6B">'永久'</td>
      </tr>
      <tr>
        <td style="padding:7px; textAlignment:right; color:#5A6B7C">'案卷件数:'</td>
        <td style="padding:7px; color:#1A2733; borderBottom:1px solid #8C7A6B">'共 6 件'</td>
      </tr>
      <tr>
        <td style="padding:7px; textAlignment:right; color:#5A6B7C">'案卷页数:'</td>
        <td style="padding:7px; color:#1A2733; borderBottom:1px solid #8C7A6B">'共 428 页(图纸 26 张)'</td>
      </tr>
      <tr>
        <td style="padding:7px; textAlignment:right; color:#5A6B7C">'档案号:'</td>
        <td style="padding:7px; bold:true; color:#6B4A2F; borderBottom:1px solid #8C7A6B">'JZ-2024-JS-0186'</td>
      </tr>
    </table>

    // ---------- 底部:立卷 / 检查 双栏 ----------
    <div style="display:flex; justifyContent:space-between; marginTop:64px">
      <div style="width:230px; borderTop:1px solid #8C7A6B; paddingTop:5px">
        <p style="fontSize:9pt; color:#5A6B7C; textAlignment:center">'立卷人(签字)'</p>
      </div>
      <div style="width:230px; borderTop:1px solid #8C7A6B; paddingTop:5px">
        <p style="fontSize:9pt; color:#5A6B7C; textAlignment:center">'档案检查人(签字)'</p>
      </div>
    </div>

    <p style="fontSize:10pt; color:#3E2A1A; textAlignment:center; marginTop:26px">'××市交通运输局档案室'</p>
    <p style="fontSize:10pt; color:#6B4A2F; textAlignment:center; marginTop:3px">'二〇二四年十二月'</p>
  </div>
</body>
</pdf>

同分组示例

本页 PDF、预览图、模板与源码均由 JQuick-Pdf 真实运行产出,可自由复制到你的项目中使用。