跳转到内容

Java 生成「入职通知」PDF 示例(Template)

JQuick-Pdf场景 Demo

Template1 页 A4 · 44 KB

红头文件样式的入职通知,单页,适合 HR 正式录用通知。

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

入职通知 — Template
渲染效果

输出规格

PDF 页数
1
图表类型
Template
模板行数
56
源码行数
101

Java 源码 · JQuickBiz74OnboardNotice.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.biz.scenario;

import com.github.paohaijiao.config.JPdfConfig;
import com.github.paohaijiao.executor.JQuickPdfFactory;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

public class JQuickBiz74OnboardNotice {

    private static final String PDF_DIR = "D:/test/pdf/";
    private static final String IMG_DIR = "D:/test/image/";
    private static final String OUT_FILE = PDF_DIR + "74_onboard_notice.pdf";
    private static final String TEMPLATE = "report/biz/74_onboard_notice.txt";

    public static void main(String[] args) throws IOException {
        new File(PDF_DIR).mkdirs();
        new File(IMG_DIR).mkdirs();

        // ---------- 1. 图片:红头 logo ----------
        generateLogo(IMG_DIR + "74_logo.png");

        // ---------- 2. 数据(普通 Map,无实体类)----------
        Map<String, Object> data = new LinkedHashMap<String, Object>();
        data.put("companyName", "××数字科技有限公司");
        data.put("noticeNo", "人事〔2026〕入职第 086 号");
        data.put("employeeName", "许安");
        data.put("position", "资深 Java 后端工程师(P6)");
        data.put("checkInTime", "2026年11月02日(星期一)上午 9:30");
        data.put("checkInAddress", "××市浦东新区××路 88 号 JQ 大厦 12 层 人力资源部");
        data.put("salaryInfo", "月基本工资 28,000 元,绩效奖金按季度考核发放;试用期 3 个月,试用期工资为转正工资的 80%;"
                + "按上海市规定缴纳五险一金,另享补充商业医疗保险与年度体检。");

        // 报到材料:逐条 bind 为 material1~6
        String[] materials = {
                "身份证原件及复印件 2 份",
                "最高学历、学位证书原件及复印件各 1 份(境外学历需附教育部认证报告)",
                "原单位离职证明原件",
                "一寸白底免冠照片 4 张(含电子版)",
                "本人名下银行卡复印件 1 份(用于工资发放)",
                "近三个月体检报告(三级甲等医院)"
        };
        for (int i = 0; i < materials.length; i++) {
            data.put("material" + (i + 1), materials[i]);
        }

        data.put("issueDate", "2026年10月19日");

        // ---------- 3. 渲染 ----------
        JPdfConfig config = new JPdfConfig();
        config.getLayoutConfig().setFlexLayout(true);
        // 公文版心:上 60、下 55,左右 70(约 2.5cm 标准公文页边距)
        config.getDoc().setMargins(Arrays.asList(60, 70, 55, 70));
        config.getFooterConfig().setEnabled(false);

        JQuickPdfFactory factory = new JQuickPdfFactory(config);
        factory.bindAll(data);
        byte[] pdf = factory.executeResource(TEMPLATE);

        FileOutputStream out = new FileOutputStream(OUT_FILE);
        out.write(pdf);
        out.close();
        System.out.println("已生成:" + OUT_FILE);
    }

    private static void generateLogo(String path) throws IOException {
        BufferedImage image = new BufferedImage(80, 80, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setColor(new Color(0xB7, 0x1C, 0x1C));
        g.fillOval(2, 2, 76, 76);
        g.setColor(Color.WHITE);
        g.setFont(new Font("Microsoft YaHei", Font.BOLD, 30));
        g.drawString("JQ", 17, 52);
        g.dispose();
        ImageIO.write(image, "png", new File(path));
    }
}

最小调用(3 行)

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

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

模板文件 · 74_onboard_notice.txt

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

<pdf>
<body>
  <div style="display:flex; justifyContent:space-between; borderBottom:2px solid #B71C1C; paddingBottom:6px">
    <div style="width:80px">
      <image src='D:/test/image/74_logo.png' style="width:40px; height:40px"></image>
    </div>
    <div style="width:300px; textAlignment:center">
      <h1 style="fontSize:18pt; bold:true; color:#B71C1C; characterSpacing:3pt">${companyName}</h1>
    </div>
    <div style="width:80px; textAlignment:right">
      <p style="fontSize:8pt; color:#B71C1C">'人力资源部'</p>
    </div>
  </div>
  <div style="borderBottom:1px solid #B71C1C; marginTop:2px; marginBottom:12px"></div>

  <h2 style="fontSize:17pt; bold:true; color:#1A2733; textAlignment:center; characterSpacing:6pt; marginTop:6px">'入 职 通 知 书'</h2>
  <p style="fontSize:9pt; color:#5A6B7C; textAlignment:center; marginBottom:14px">${noticeNo}</p>

  <p style="fontSize:11pt; bold:true; color:#1A2733; marginBottom:6px">${employeeName}' 先生/女士:'</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:5px">'您好!感谢您对我司的信任与关注。经综合评估,我司决定录用您担任 '${position}' 一职。现将有关入职事宜通知如下,请按期办理报到手续。'</p>

  <p style="fontSize:11pt; bold:true; color:#1A2733; marginTop:10px; marginBottom:4px">'一、报到时间与地点'</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:3px">'报到时间:'${checkInTime}</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:3px">'报到地址:'${checkInAddress}</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:3px">'请携带本通知书打印件,于报到当日 9:30 前到前台登记,由人力资源部安排后续流程。'</p>

  <p style="fontSize:11pt; bold:true; color:#1A2733; marginTop:10px; marginBottom:4px">'二、薪资待遇'</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:3px">${salaryInfo}</p>

  <p style="fontSize:11pt; bold:true; color:#1A2733; marginTop:10px; marginBottom:4px">'三、报到所需材料'</p>
  <list style="listStyleType:decimal; paddingLeft:26px; fontSize:10.5pt; color:#333333">
    <li style="marginBottom:3px">${material1}</li>
    <li style="marginBottom:3px">${material2}</li>
    <li style="marginBottom:3px">${material3}</li>
    <li style="marginBottom:3px">${material4}</li>
    <li style="marginBottom:3px">${material5}</li>
    <li style="marginBottom:3px">${material6}</li>
  </list>

  <p style="fontSize:11pt; bold:true; color:#1A2733; marginTop:10px; marginBottom:4px">'四、其他事项'</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:5px">'如您因特殊原因无法按期报到,请提前 3 个工作日致电人力资源部说明情况;逾期未报到且未作说明的,视为放弃录用资格,本通知书自动失效。'</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:5px">'本通知书自签发之日起 15 日内有效,请妥善保管,不得转借他人。'</p>

  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginTop:12px">'特此通知。'</p>

  <div style="marginTop:26px">
    <p style="fontSize:10.5pt; bold:true; color:#1A2733; textAlignment:right">${companyName}' 人力资源部'</p>
    <p style="fontSize:10.5pt; color:#333333; textAlignment:right; marginTop:4px">${issueDate}</p>
  </div>

  <div style="borderTop:1px solid #B71C1C; marginTop:22px; paddingTop:5px">
    <p style="fontSize:8pt; color:#8a939b; textAlignment:center">${companyName}' 地址:××市××区××路 88 号 电话:021-0000-0000 网址:www.example.com'</p>
  </div>
</body>
</pdf>

同分组示例

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