跳转到内容

Java 生成「银行资信证明」PDF 示例(Template)

JQuick-Pdf场景 Demo

Template1 页 A4 · 31 KB

银行制式资信证明,单页,右下角预留银行公章。

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

银行资信证明 — Template
渲染效果

输出规格

PDF 页数
1
图表类型
Template
模板行数
60
源码行数
96

Java 源码 · JQuickBiz82CreditCertificate.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.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

public class JQuickBiz82CreditCertificate {

    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 + "82_credit_certificate.pdf";
    private static final String TEMPLATE = "report/biz/82_credit_certificate.txt";

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

        // ---------- 1. 生成业务专用章图片(模板按字面量路径引用)----------
        generateSeal(IMG_DIR + "82_seal.png");

        // ---------- 2. 组织数据(普通 Map,无实体类)----------
        Map<String, Object> data = new LinkedHashMap<String, Object>();
        data.put("certNo", "资信证明〔2026〕第 20261019-086 号");
        data.put("customerName", "××数字科技有限公司");
        data.put("idNo", "91310115MA1K9XXXX");
        data.put("accountNo", "3100 1234 5678 9012 345");
        data.put("accountType", "基本存款账户");
        data.put("balance", "人民币 ¥ 8,642,300.00");
        data.put("openDate", "2018年05月16日");
        data.put("validUntil", "90 日");
        data.put("bankName", "××银行××支行");
        data.put("issueDate", "2026年10月19日");

        // ---------- 3. 渲染 ----------
        JPdfConfig config = new JPdfConfig();
        config.getLayoutConfig().setFlexLayout(true);
        config.getDoc().setMargins(Arrays.asList(58, 66, 58, 66));
        config.getFooterConfig().setEnabled(false);

        JQuickPdfFactory factory = new JQuickPdfFactory(config);
        factory.bindAll(data);
        byte[] pdf = factory.executeResource(TEMPLATE);
        java.nio.file.Files.write(new File(OUT_FILE).toPath(), pdf);
        System.out.println("已生成:" + OUT_FILE);
    }

    /** 生成银行业务专用章(圆环 + 行名 + 「业务专用章」字样)。 */
    private static void generateSeal(String path) throws IOException {
        int size = 210;
        BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Color red = new Color(0xC6, 0x28, 0x28);
        g.setColor(red);
        g.setStroke(new BasicStroke(6f));
        g.drawOval(8, 8, size - 16, size - 16);
        g.setFont(new Font("Microsoft YaHei", Font.BOLD, 15));
        g.drawString("××银行", size / 2 - 30, 62);
        g.drawString("××支行", size / 2 - 30, 84);
        g.setFont(new Font("Microsoft YaHei", Font.BOLD, 17));
        g.drawString("业务专用章", size / 2 - 45, size / 2 + 32);
        g.dispose();
        ImageIO.write(image, "png", new File(path));
    }

    /** 预留:余额格式化,业务中建议用 BigDecimal 处理后再传入字符串。 */
    @SuppressWarnings("unused")
    private static String format(BigDecimal amount) {
        return String.format("%,.2f", amount);
    }
}

最小调用(3 行)

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

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

模板文件 · 82_credit_certificate.txt

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

<pdf>
<body>

  <h1 style="fontSize:17pt; bold:true; color:#B71C1C; textAlignment:center; characterSpacing:4pt">${bankName}</h1>
  <div style="borderBottom:2px solid #B71C1C; marginTop:5px"></div>
  <div style="borderBottom:1px solid #B71C1C; marginTop:2px; marginBottom:14px"></div>

  <h2 style="fontSize:20pt; bold:true; color:#1A2733; textAlignment:center; characterSpacing:8pt; marginBottom:4px">'资 信 证 明'</h2>
  <p style="fontSize:9pt; color:#5A6B7C; textAlignment:right; marginBottom:10px">'编号:'${certNo}</p>

  <p style="fontSize:11pt; bold:true; color:#1A2733; marginBottom:6px">${customerName}':'</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:4px">'应贵单位申请,现就贵单位在我行开立账户及资信情况证明如下:'</p>

  <table style="width:100%; fontSize:10pt; marginTop:8px; marginBottom:8px">
    <tr>
      <td style="width:110px; padding:6px; backgroundColor:#FDF2F2; bold:true; border:1px solid #D9B3B3">'客户名称'</td>
      <td style="padding:6px; border:1px solid #D9B3B3">${customerName}</td>
    </tr>
    <tr>
      <td style="padding:6px; backgroundColor:#FDF2F2; bold:true; border:1px solid #D9B3B3">'证件号码'</td>
      <td style="padding:6px; border:1px solid #D9B3B3">${idNo}</td>
    </tr>
    <tr>
      <td style="padding:6px; backgroundColor:#FDF2F2; bold:true; border:1px solid #D9B3B3">'账户账号'</td>
      <td style="padding:6px; border:1px solid #D9B3B3">${accountNo}</td>
    </tr>
    <tr>
      <td style="padding:6px; backgroundColor:#FDF2F2; bold:true; border:1px solid #D9B3B3">'账户类型'</td>
      <td style="padding:6px; border:1px solid #D9B3B3">${accountType}</td>
    </tr>
    <tr>
      <td style="padding:6px; backgroundColor:#FDF2F2; bold:true; border:1px solid #D9B3B3">'存款余额'</td>
      <td style="padding:6px; border:1px solid #D9B3B3">${balance}</td>
    </tr>
    <tr>
      <td style="padding:6px; backgroundColor:#FDF2F2; bold:true; border:1px solid #D9B3B3">'开户日期'</td>
      <td style="padding:6px; border:1px solid #D9B3B3">${openDate}</td>
    </tr>
  </table>

  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:4px">'截至 '${issueDate}' 止,贵单位上述账户资金往来正常,信用状况良好,在我行无不良记录、无未结清的逾期贷款及欠息。'</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginBottom:4px">'本证明自开具之日起 '${validUntil}' 内有效,仅用于证明贵单位资信状况,不作其他用途。'</p>
  <p style="fontSize:10.5pt; color:#333333; textIndent:21pt; marginTop:8px">'特此证明。'</p>

  <div style="display:flex; justifyContent:space-between; marginTop:24px">
    <div style="width:44%">
      <p style="fontSize:8.5pt; color:#8a939b">'说明:本证明仅对所列账户在证明时点的状态负责,'</p>
      <p style="fontSize:8.5pt; color:#8a939b">'不构成我行对客户未来偿付能力的担保。'</p>
    </div>
    <div style="width:48%; paddingLeft:110px">
      <image src='D:/test/image/82_seal.png' style="width:100px; height:100px"></image>
      <p style="fontSize:10.5pt; bold:true; color:#1A2733; textAlignment:center">${bankName}</p>
      <p style="fontSize:9pt; color:#5A6B7C; textAlignment:center">'业务专用章'</p>
      <p style="fontSize:10.5pt; color:#333333; textAlignment:center; marginTop:2px">${issueDate}</p>
    </div>
  </div>

</body>
</pdf>

同分组示例

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