Skip to content

Bonded record list — generate this PDF with Java (Template)

JQuick-PdfCustoms & Trade Demos

Template1 页 A4 · 30 KB

Customs entry/exit bonded goods record list.

Download the PDFView raw template fileBack to all demos

Bonded record list — Template
Rendered output

Output specs

PDF pages
1
Chart type
Template
Template lines
162
Source lines
204

Java source · JQuickBiz126EntryExitRecordList.java

This is the complete test class that produced the PDF above — copy it and run as-is; see the quick-start section for the Maven dependency.

/*
 * 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.customs;

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;

/**
 * 单据 126:中华人民共和国海关进出境货物备案清单(customs 领域第 2 项)。
 *
 * <p>本类为独立可运行 Demo:自带 {@code main} 方法、不依赖任何公共工具类或实体类,
 * 数据以 key-value 形式通过 {@link JQuickPdfFactory#bindAll(Map)} 注入,
 * 版式全部落在模板文件 {@code demo/biz/customs/126_entry_exit_record_list.txt} 中。</p>
 *
 * <p>视觉主题「靛蓝·素雅·票式」:主色 #297586、辅色 #912745、浅底 #F1F5F6;
 * 版式为 ticket 抬头 + strip 信息区 + light 明细表 + right 签章区 + table 落款,
 * 与同领域其它单据互不重样。</p>
 *
 * <p>对标海关进出境货物备案清单票样:备案清单编号、经营单位、备案性质、</p>
 * <p>货物 HS 编码与备案总价、录入单位与海关签章栏。</p>
 *
 * <p>运行后输出:{@code D:/test/pdf/126_entry_exit_record_list.pdf}。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickBiz126EntryExitRecordList {

    private static final String PDF_DIR = "D:/test/pdf/";
    private static final String OUT_FILE = PDF_DIR + "126_entry_exit_record_list.pdf";
    private static final String TEMPLATE = "demo/biz/customs/126_entry_exit_record_list.txt";

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

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

        // ---------- 1. 数据(无实体类,直接 bind)----------
        String[][] items = {
                {"1", "8542.3100", "集成电路 IC-8800", "12000 个", "中国台湾", "1.86", "22320.00"},
                {"2", "8534.0000", "印刷电路板 PCB-6L", "3600 片", "中国台湾", "4.20", "15120.00"},
                {"3", "8541.1000", "二极管 DIO-40V", "50000 个", "韩国", "0.03", "1500.00"},
                {"4", "8533.2100", "贴片电阻 RES-1K", "80000 个", "韩国", "0.01", "800.00"},
                {"5", "—", "电子元器件辅料", "1 批", "日本", "860.00", "860.00"},
                {"6", "—", "备用包装材料", "1 批", "中国", "320.00", "320.00"}
        };

        Map<String, Object> data = new LinkedHashMap<String, Object>();
        data.put("recordNo", "220120261012004411");
        data.put("recordDate", "2026年10月09日");
        data.put("portName", "××海关××口岸");
        data.put("operatorName", "××保税物流有限公司 91330100MA2H5T71XB");
        data.put("counterpart", "××保税物流有限公司");
        data.put("recordType", "保税仓储 / 进境备案");
        data.put("transport", "公路运输 / 苏A·D72K18");
        data.put("inputUnit", "××报关服务有限公司");
        data.put("refDeclarationNo", "220120261012003388");
        data.put("validUntil", "2026年12月31日");
        data.put("remark", "本备案清单适用于保税区、出口加工区等特殊监管区域进出境货物,不作正式报关单使用,货物实际离境时另行申报。");
        data.put("declarer", "崔行知");
        data.put("inputer", "苏见宁");
        data.put("customsOfficer", "××海关");

        // 明细逐格展开,并累计金额
        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, "—");
                data.put("itemTax" + 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]);
            data.put("itemAmount" + n, items[i][5]);
            itemTotal = itemTotal.add(new BigDecimal(items[i][6]));
            data.put("itemTax" + n, items[i][6]);
        }

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

        data.put("totalLine", "备案总价(大写)" + toChineseAmount(itemTotal) + " 美元  (小写)USD " + itemTotal.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());

        // ---------- 2. 渲染 ----------
        JPdfConfig config = new JPdfConfig();
        config.getLayoutConfig().setFlexLayout(true);
        config.getDoc().setMargins(Arrays.asList(44, 44, 44, 44));
        config.getFontConfig().setDefaultFontName("Noto Sans CJK SC");
        config.getHeaderConfig().setEnabled(true);
        config.getHeaderConfig().setText("××海关 进出境货物备案清单 220120261012004411");
        config.getHeaderConfig().setFontSize(7.5f);
        config.getHeaderConfig().setHeight(34);
        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();
    }
}

Minimal invocation (3 lines)

Skip the full test class — the core is these three lines: bind the chart SVG, execute the template, get the PDF bytes. Copy them straight into your project.

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

Template file · 126_entry_exit_record_list.txt

An HTML-like template with inline CSS that renders to PDF once bound to data. The full template is below — copy it or download the raw file.

<pdf>
<body>
  // 126 中华人民共和国海关进出境货物备案清单(customs 领域第 2 项) 视觉主题:靛蓝·素雅·票式
  // 版式组合:抬头=ticket 信息区=strip 明细表=light 段落=plain 签章=right 落款=table
  // 主色 #297586 辅色 #912745 浅底 #F1F5F6
  // 进出境货物备案清单:适用于保税区等特殊监管区域,含备案性质与关联报关单号。

  // 抬头:ticket
  <h1 style="fontSize:19pt; bold:true; color:#297586; textAlignment:center; characterSpacing:10pt; marginBottom:2px">'中华人民共和国海关进出境货物备案清单'</h1>
  <p style="fontSize:7.5pt; color:#78838C; textAlignment:center">'备案清单编号 '${recordNo}'  备案日期 '${recordDate}'  口岸 '${portName}</p>
  <lineSeparator style="color:#297586; thickness:2f"></lineSeparator>
  <lineSeparator style="color:#297586; thickness:0.5f; marginBottom:8px"></lineSeparator>

  // 信息区:grid2
  <table style="width:100%; fontSize:8.5pt; marginBottom:8px">
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'备案清单编号'</td>
      <td style="width:34%; padding:4px; border:1px solid #C0D1D5">${recordNo}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'备案日期'</td>
      <td style="padding:4px; border:1px solid #C0D1D5">${recordDate}</td>
    </tr>
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'进出境口岸'</td>
      <td style="width:34%; padding:4px; border:1px solid #C0D1D5">${portName}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'经营单位'</td>
      <td style="padding:4px; border:1px solid #C0D1D5">${operatorName}</td>
    </tr>
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'收货 / 发货单位'</td>
      <td style="width:34%; padding:4px; border:1px solid #C0D1D5">${counterpart}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'备案性质'</td>
      <td style="padding:4px; border:1px solid #C0D1D5">${recordType}</td>
    </tr>
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'运输方式 / 工具'</td>
      <td style="width:34%; padding:4px; border:1px solid #C0D1D5">${transport}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'录入单位'</td>
      <td style="padding:4px; border:1px solid #C0D1D5">${inputUnit}</td>
    </tr>
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'关联报关单号'</td>
      <td style="width:34%; padding:4px; border:1px solid #C0D1D5">${refDeclarationNo}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F1F5F6; bold:true; border:1px solid #C0D1D5">'备案有效期'</td>
      <td style="padding:4px; border:1px solid #C0D1D5">${validUntil}</td>
    </tr>
  </table>

  <table style="width:100%; marginBottom:3px">
    <tr>
      <td style="padding:4px; backgroundColor:#F1F5F6; bold:true; fontSize:10pt; color:#125564">'备案货物明细'</td>
    </tr>
  </table>
  <table style="width:100%; fontSize:8.5pt; marginBottom:8px">
    <tr>
      <th style="width:7%; padding:4px; backgroundColor:#F1F5F6; color:#125564; bold:true; textAlign:center; border:1px solid #C0D1D5">'项号'</th>
      <th style="width:14%; padding:4px; backgroundColor:#F1F5F6; color:#125564; bold:true; textAlign:center; border:1px solid #C0D1D5">'商品编号(HS)'</th>
      <th style="width:24%; padding:4px; backgroundColor:#F1F5F6; color:#125564; bold:true; textAlign:center; border:1px solid #C0D1D5">'货物名称规格'</th>
      <th style="width:13%; padding:4px; backgroundColor:#F1F5F6; color:#125564; bold:true; textAlign:center; border:1px solid #C0D1D5">'数量 / 单位'</th>
      <th style="width:12%; padding:4px; backgroundColor:#F1F5F6; color:#125564; bold:true; textAlign:center; border:1px solid #C0D1D5">'原产国'</th>
      <th style="width:13%; padding:4px; backgroundColor:#F1F5F6; color:#125564; bold:true; textAlign:center; border:1px solid #C0D1D5">'单价(USD)'</th>
      <th style="padding:4px; backgroundColor:#F1F5F6; color:#125564; bold:true; textAlign:center; border:1px solid #C0D1D5">'总价(USD)'</th>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemName1}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemSpec1}</td>
      <td style="padding:4px; textAlign:left; border:1px solid #DFE4E5">${itemUnit1}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemQty1}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemPrice1}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemAmount1}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemTax1}</td>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemName2}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemSpec2}</td>
      <td style="padding:4px; textAlign:left; border:1px solid #DFE4E5">${itemUnit2}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemQty2}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemPrice2}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemAmount2}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemTax2}</td>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemName3}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemSpec3}</td>
      <td style="padding:4px; textAlign:left; border:1px solid #DFE4E5">${itemUnit3}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemQty3}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemPrice3}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemAmount3}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemTax3}</td>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemName4}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemSpec4}</td>
      <td style="padding:4px; textAlign:left; border:1px solid #DFE4E5">${itemUnit4}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemQty4}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemPrice4}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemAmount4}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemTax4}</td>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemName5}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemSpec5}</td>
      <td style="padding:4px; textAlign:left; border:1px solid #DFE4E5">${itemUnit5}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemQty5}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemPrice5}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemAmount5}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemTax5}</td>
    </tr>
    <tr>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemName6}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemSpec6}</td>
      <td style="padding:4px; textAlign:left; border:1px solid #DFE4E5">${itemUnit6}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemQty6}</td>
      <td style="padding:4px; textAlign:center; border:1px solid #DFE4E5">${itemPrice6}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemAmount6}</td>
      <td style="padding:4px; textAlign:right; border:1px solid #DFE4E5">${itemTax6}</td>
    </tr>
    <tr>
      <td style="padding:4px; bold:true; backgroundColor:#F1F5F6; textAlign:center; border:1px solid #297586">'备案总价'</td>
      <td style="padding:4px; backgroundColor:#F1F5F6; border:1px solid #297586">'—'</td>
      <td style="padding:4px; backgroundColor:#F1F5F6; border:1px solid #297586">'—'</td>
      <td style="padding:4px; backgroundColor:#F1F5F6; border:1px solid #297586">'—'</td>
      <td style="padding:4px; backgroundColor:#F1F5F6; border:1px solid #297586">'—'</td>
      <td style="padding:4px; backgroundColor:#F1F5F6; border:1px solid #297586">'—'</td>
      <td style="padding:4px; bold:true; backgroundColor:#F1F5F6; textAlign:right; border:1px solid #297586">'USD '${totalAmount}</td>
    </tr>
  </table>

  // 段落:plain
  <p style="fontSize:10.5pt; bold:true; color:#125564; marginBottom:3px">'备案总价'</p>
  <p style="fontSize:9pt; marginBottom:6px">${totalLine}</p>
  <p style="fontSize:10.5pt; bold:true; color:#125564; marginBottom:3px">'备注'</p>
  <p style="fontSize:9pt; marginBottom:6px">${remark}</p>

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

  // 落款:table
  <!-- 落款栏 -->
  <table style="width:100%; fontSize:8.5pt">
    <tr>
      <td style="width:33%; padding:5px; border:1px solid #C0D1D5">'申报人:'${declarer}</td>
      <td style="width:33%; padding:5px; border:1px solid #C0D1D5">'录入人:'${inputer}</td>
      <td style="padding:5px; border:1px solid #C0D1D5">'海关签章:'${customsOfficer}</td>
    </tr>
  </table>
</body>
</pdf>

More demos in this group

The PDF, preview image, template and source code on this page were all produced by a real JQuick-Pdf run and are free to copy into your own project.