跳转到内容

Java 生成「海关进口增值税缴款书」PDF 示例(Template)

JQuick-Pdf财税票据 Demo

Template1 页 A4 · 25 KB

海关进口增值税专用缴款书版式,进口抵扣场景。

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

海关进口增值税缴款书 — Template
渲染效果

输出规格

PDF 页数
1
图表类型
Template
模板行数
136
源码行数
200

Java 源码 · JQuickBiz109CustomsImportVatPayment.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.finance;

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

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 单据 109:海关进口增值税专用缴款书(finance 领域第 10 项)。
 *
 * <p>本类为独立可运行 Demo:自带 {@code main} 方法、不依赖任何公共工具类或实体类,
 * 数据以 key-value 形式通过 {@link JQuickPdfFactory#bindAll(Map)} 注入,
 * 版式全部落在模板文件 {@code demo/biz/finance/109_customs_import_vat_payment.txt} 中。</p>
 *
 * <p>视觉主题「金橙·厚框·下线」:主色 #AB912A、辅色 #276E91、浅底 #F7F5F0;
 * 版式为 underline 抬头 + chip 信息区 + solid 明细表 + right 签章区 + right 落款,
 * 与同领域其它单据互不重样。</p>
 *
 * <p>对标海关进口增值税专用缴款书票样:缴款书号码、征收机关、缴款单位、</p>
 * <p>完税价格与各项税额明细、税款合计大小写与海关印章占位。</p>
 *
 * <p>运行后输出:{@code D:/test/pdf/109_customs_import_vat_payment.pdf}。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickBiz109CustomsImportVatPayment {

    private static final String PDF_DIR = "D:/test/pdf/";
    private static final String OUT_FILE = PDF_DIR + "109_customs_import_vat_payment.pdf";
    private static final String TEMPLATE = "demo/biz/finance/109_customs_import_vat_payment.txt";

    /** 模板固定明细行数,不足时补空行,避免占位符原样输出。 */
    private static final int ITEM_ROWS = 5;

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

        // ---------- 1. 数据(无实体类,直接 bind)----------
        String[][] items = {
                {"进口增值税", "486200.00", "13%", "63206.00", "0.00", "63206.00"},
                {"进口关税", "486200.00", "5%", "24310.00", "0.00", "24310.00"},
                {"进口消费税", "—", "—", "0.00", "0.00", "0.00"},
                {"海关监管手续费", "—", "—", "486.20", "0.00", "486.20"},
                {"滞报金", "—", "—", "0.00", "0.00", "0.00"}
        };

        Map<String, Object> data = new LinkedHashMap<String, Object>();
        data.put("paymentNo", "220120261012003388");
        data.put("issueDate", "2026年10月08日");
        data.put("officeName", "××海关");
        data.put("payerName", "××国际贸易有限公司");
        data.put("payerTaxNo", "91330100MA2H5T71XB");
        data.put("portName", "××口岸 / 220120261012003388");
        data.put("taxPeriod", "2026年09月");
        data.put("dueDate", "2026年10月23日");
        data.put("remark", "本缴款书为进口环节增值税法定扣税凭证,缴款单位须在备注栏注明报关单号码并自开具之日起 180 日内申报抵扣。");
        data.put("payee", "崔行知");
        data.put("reviewer", "柳文渊");
        data.put("drawer", "苏见宁");

        // 明细逐格展开,并累计金额
        BigDecimal itemTotal = BigDecimal.ZERO;
        for (int i = 0; i < ITEM_ROWS; i++) {
            int n = i + 1;
            if (i >= items.length) {
                data.put("itemName" + n, "—");
                data.put("itemSpec" + n, "—");
                data.put("itemUnit" + n, "—");
                data.put("itemQty" + n, "—");
                data.put("itemPrice" + n, "—");
                data.put("itemAmount" + n, "—");
                continue;
            }
            data.put("itemName" + n, items[i][0]);
            data.put("itemSpec" + n, items[i][1]);
            data.put("itemUnit" + n, items[i][2]);
            data.put("itemQty" + n, items[i][3]);
            data.put("itemPrice" + n, items[i][4]);
            itemTotal = itemTotal.add(new BigDecimal(items[i][5]));
            data.put("itemAmount" + n, items[i][5]);
        }

        data.put("totalAmount", itemTotal.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
        data.put("totalAmountInWords", toChineseAmount(itemTotal));

        data.put("totalLine", "税款合计(大写)" + toChineseAmount(itemTotal) + "  (小写)¥" + itemTotal.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());

        // ---------- 2. 渲染 ----------
        JPdfConfig config = new JPdfConfig();
        config.getLayoutConfig().setFlexLayout(true);
        config.getDoc().setMargins(Arrays.asList(40, 40, 40, 40));
        config.getFontConfig().setDefaultFontName("Noto Sans CJK SC");
        config.getHeaderConfig().setEnabled(true);
        config.getHeaderConfig().setText("××海关 海关进口增值税专用缴款书 220120261012003388");
        config.getHeaderConfig().setFontSize(8f);
        config.getHeaderConfig().setHeight(32);
        config.getFooterConfig().setEnabled(true);
        config.getFooterConfig().setFontSize(8);
        config.getFooterConfig().setPageNumberFormat("— %d —");

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

    /** 人民币金额转票据大写(元角分,末尾补「整」)。 */
    private static String toChineseAmount(BigDecimal amount) {
        String[] digits = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
        String[] units = {"", "拾", "佰", "仟"};
        String[] sections = {"", "万", "亿", "万亿"};
        long cents = amount.setScale(2, BigDecimal.ROUND_HALF_UP)
                .movePointRight(2).longValue();
        if (cents == 0) {
            return "零元整";
        }
        long yuan = cents / 100;
        int jiao = (int) (cents % 100 / 10);
        int fen = (int) (cents % 10);
        StringBuilder sb = new StringBuilder();
        if (yuan > 0) {
            sb.append(toChineseSection(yuan, digits, units, sections)).append("元");
        }
        if (jiao == 0 && fen == 0) {
            sb.append("整");
        } else {
            if (jiao > 0) {
                sb.append(digits[jiao]).append("角");
            } else if (yuan > 0) {
                sb.append("零");
            }
            if (fen > 0) {
                sb.append(digits[fen]).append("分");
            }
        }
        return sb.toString();
    }

    /** 整数部分按四位分节转大写。 */
    private static String toChineseSection(long value, String[] digits, String[] units, String[] sections) {
        StringBuilder sb = new StringBuilder();
        int sectionIndex = 0;
        boolean needZero = false;
        while (value > 0) {
            int section = (int) (value % 10000);
            StringBuilder part = new StringBuilder();
            int unitIndex = 0;
            boolean zeroInSection = false;
            int temp = section;
            while (temp > 0) {
                int digit = temp % 10;
                if (digit == 0) {
                    zeroInSection = true;
                } else {
                    if (zeroInSection || (needZero && part.length() == 0 && sb.length() > 0)) {
                        part.insert(0, digits[0]);
                    }
                    part.insert(0, units[unitIndex]);
                    part.insert(0, digits[digit]);
                    zeroInSection = false;
                    needZero = false;
                }
                unitIndex++;
                temp /= 10;
            }
            if (part.length() > 0) {
                part.append(sections[sectionIndex]);
            }
            sb.insert(0, part);
            needZero = section < 1000 && section > 0;
            value /= 10000;
            sectionIndex++;
        }
        return sb.toString();
    }
}

最小调用(3 行)

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

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

模板文件 · 109_customs_import_vat_payment.txt

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

<pdf>
<body>
  // 109 海关进口增值税专用缴款书(finance 领域第 10 项) 视觉主题:金橙·厚框·下线
  // 版式组合:抬头=underline 信息区=chip 明细表=solid 段落=box 签章=right 落款=right
  // 主色 #AB912A 辅色 #276E91 浅底 #F7F5F0
  // 海关进口增值税专用缴款书:含完税价格、税率、增值税 / 关税 / 消费税额与缴款期限。

  // 抬头:underline
  <table style="width:100%; marginBottom:1px">
    <tr>
      <td style="width:62%; padding:2px; bold:true; fontSize:15pt; color:#8A7213; characterSpacing:3pt">'海关进口增值税专用缴款书'</td>
      <td style="padding:2px; textAlign:right; fontSize:7.5pt; color:#78838C">'缴款书号码 '${paymentNo}'  填发日期 '${issueDate}'  口岸 '${portName}</td>
    </tr>
  </table>
  <lineSeparator style="color:#AB912A; thickness:2.5f; marginBottom:8px"></lineSeparator>

  // 信息区:chip
  <table style="width:100%; fontSize:8.5pt; marginBottom:8px">
    <tr>
      <td style="width:25%; padding:4px; border:1px solid #D7D2BF">'缴款书号码:'${paymentNo}</td>
      <td style="width:25%; padding:4px; border:1px solid #D7D2BF">'填发日期:'${issueDate}</td>
      <td style="width:25%; padding:4px; border:1px solid #D7D2BF">'征收机关:'${officeName}</td>
      <td style="padding:4px; border:1px solid #D7D2BF">'缴款单位:'${payerName}</td>
    </tr>
    <tr>
      <td style="width:25%; padding:4px; border:1px solid #D7D2BF">'缴款单位识别号:'${payerTaxNo}</td>
      <td style="width:25%; padding:4px; border:1px solid #D7D2BF">'口岸 / 报关单号:'${portName}</td>
      <td style="width:25%; padding:4px; border:1px solid #D7D2BF">'税款所属期:'${taxPeriod}</td>
      <td style="padding:4px; border:1px solid #D7D2BF">'缴款期限:'${dueDate}</td>
    </tr>
  </table>

  <p style="fontSize:10.5pt; bold:true; color:#8A7213; marginBottom:4px">'税(费)款明细'</p>
  <table style="width:100%; fontSize:8pt; marginBottom:8px">
    <tr>
      <th style="width:22%; padding:4px; backgroundColor:#AB912A; color:white; bold:true; textAlign:center; border:1px solid #AB912A">'税(费)种'</th>
      <th style="width:18%; padding:4px; backgroundColor:#AB912A; color:white; bold:true; textAlign:center; border:1px solid #AB912A">'完税价格(CNY)'</th>
      <th style="width:12%; padding:4px; backgroundColor:#AB912A; color:white; bold:true; textAlign:center; border:1px solid #AB912A">'税率'</th>
      <th style="width:18%; padding:4px; backgroundColor:#AB912A; color:white; bold:true; textAlign:center; border:1px solid #AB912A">'税(费)额'</th>
      <th style="width:14%; padding:4px; backgroundColor:#AB912A; color:white; bold:true; textAlign:center; border:1px solid #AB912A">'滞纳金'</th>
      <th style="padding:4px; backgroundColor:#AB912A; color:white; bold:true; textAlign:center; border:1px solid #AB912A">'合计'</th>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:left; border:1px solid #D7D2BF">${itemName1}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemSpec1}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #D7D2BF">${itemUnit1}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemQty1}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemPrice1}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemAmount1}</td>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:left; border:1px solid #D7D2BF">${itemName2}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemSpec2}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #D7D2BF">${itemUnit2}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemQty2}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemPrice2}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemAmount2}</td>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:left; border:1px solid #D7D2BF">${itemName3}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemSpec3}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #D7D2BF">${itemUnit3}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemQty3}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemPrice3}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemAmount3}</td>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:left; border:1px solid #D7D2BF">${itemName4}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemSpec4}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #D7D2BF">${itemUnit4}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemQty4}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemPrice4}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemAmount4}</td>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:left; border:1px solid #D7D2BF">${itemName5}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemSpec5}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #D7D2BF">${itemUnit5}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemQty5}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemPrice5}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #D7D2BF">${itemAmount5}</td>
    </tr>
    <tr>
      <td style="padding:4px; bold:true; backgroundColor:#F7F5F0; textAlign:center; border:1px solid #AB912A">'合 计'</td>
      <td style="padding:4px; backgroundColor:#F7F5F0; border:1px solid #AB912A">'—'</td>
      <td style="padding:4px; backgroundColor:#F7F5F0; border:1px solid #AB912A">'—'</td>
      <td style="padding:4px; backgroundColor:#F7F5F0; border:1px solid #AB912A">'—'</td>
      <td style="padding:4px; backgroundColor:#F7F5F0; border:1px solid #AB912A">'—'</td>
      <td style="padding:4px; bold:true; backgroundColor:#F7F5F0; textAlign:right; border:1px solid #AB912A">'¥'${totalAmount}</td>
    </tr>
  </table>

  // 段落:box
  <table style="width:100%; marginBottom:6px">
    <tr>
      <td style="width:150px; padding:5px; backgroundColor:#F7F5F0; bold:true; fontSize:9.5pt; color:#8A7213; border:1px solid #D7D2BF">'税款合计'</td>
      <td style="padding:5px; fontSize:9pt; border:1px solid #D7D2BF">${totalLine}</td>
    </tr>
  </table>
  <table style="width:100%; marginBottom:6px">
    <tr>
      <td style="width:150px; padding:5px; backgroundColor:#F7F5F0; bold:true; fontSize:9.5pt; color:#8A7213; border:1px solid #D7D2BF">'备注'</td>
      <td style="padding:5px; fontSize:9pt; border:1px solid #D7D2BF">${remark}</td>
    </tr>
  </table>

  // 签章区:right
  <!-- 签章占位区:后续加盖电子公章 / 骑缝章 / 打印二维码 -->
  <table style="width:100%; fontSize:8pt; marginBottom:8px">
    <tr>
      <td style="width:32%; padding:5px; backgroundColor:#F7F5F0; fontSize:7.5pt; color:#78838C; border:1px solid #D7D2BF">'本联次加盖印章后有效,扫码可验真'</td>
      <td style="padding:3px; textAlign:center; color:#AB912A; border:1px dashed #AB912A">'(公章 / 财务专用章占位)' '(骑缝章 / 二维码占位)'</td>
    </tr>
    <tr>
      <td style="width:32%%; padding:4px">' '</td>
      <td style="padding:3px; textAlign:center; color:#78838C; border:1px dashed #AB912A">'单位名称:'${officeName} '骑缝章沿右边线骑缝加盖'</td>
    </tr>
    <tr>
      <td style="width:32%%; padding:4px">' '</td>
      <td style="padding:3px; textAlign:center; color:#78838C; border:1px dashed #AB912A">'签章日期:'${issueDate} '二维码打印于右上角方框内'</td>
    </tr>
  </table>

  // 落款:right
  <!-- 落款栏 -->
  <table style="width:100%; fontSize:9pt; marginTop:6px">
    <tr>
      <td style="width:24%; padding:4px">' '</td>
      <td style="width:38%; padding:4px; textAlign:center; color:#8A7213">'缴款单位经办人:'${payee}</td>
      <td style="width:38%; padding:4px; textAlign:center; color:#8A7213">'复核:'${reviewer}</td>
      <td style="padding:4px; textAlign:center; color:#8A7213">'填发人:'${drawer}</td>
    </tr>
  </table>
</body>
</pdf>

同分组示例

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