Skip to content

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

JQuick-PdfCustoms & Trade Demos

Template1 页 A4 · 32 KB

Bonded warehouse in/out list / transit cargo list.

Download the PDFView raw template fileBack to all demos

Bonded warehouse list — Template
Rendered output

Output specs

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

Java source · JQuickBiz138BondedWarehouseList.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;

/**
 * 单据 138:保税仓出入库清单 / 中转货物清单(customs 领域第 14 项)。
 *
 * <p>本类为独立可运行 Demo:自带 {@code main} 方法、不依赖任何公共工具类或实体类,
 * 数据以 key-value 形式通过 {@link JQuickPdfFactory#bindAll(Map)} 注入,
 * 版式全部落在模板文件 {@code demo/biz/customs/138_bonded_warehouse_list.txt} 中。</p>
 *
 * <p>视觉主题「紫棠·密排·票式」:主色 #2D0F7F、辅色 #917C27、浅底 #F2EFF8;
 * 版式为 ticket 抬头 + strip 信息区 + compact 明细表 + three 签章区 + right 落款,
 * 与同领域其它单据互不重样。</p>
 *
 * <p>保税仓出入库清单 / 中转货物清单:E 账册编号与库位区间、作业类型,</p>
 * <p>逐项商品数量金额与在库状态、库存金额合计与三方签字栏。</p>
 *
 * <p>运行后输出:{@code D:/test/pdf/138_bonded_warehouse_list.pdf}。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickBiz138BondedWarehouseList {

    private static final String PDF_DIR = "D:/test/pdf/";
    private static final String OUT_FILE = PDF_DIR + "138_bonded_warehouse_list.pdf";
    private static final String TEMPLATE = "demo/biz/customs/138_bonded_warehouse_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", "进口婴幼儿配方奶粉 800g", "入库", "1200 罐", "A-01 ~ A-06", "321600.00", "在库"},
                {"2", "进口保健食品 60 粒装", "入库", "860 瓶", "A-07 ~ A-12", "159960.00", "在库"},
                {"3", "进口化妆品套装", "入库", "540 套", "A-13 ~ A-18", "177120.00", "在库"},
                {"4", "进口纸尿裤 L 码", "中转出库", "2000 包", "T-中转区", "192000.00", "已出库"},
                {"5", "进口宠物食品 5kg", "入库", "680 袋", "A-19 ~ A-24", "107440.00", "在库"},
                {"6", "进口小家电配件", "中转出库", "320 件", "T-中转区", "27520.00", "已出库"}
        };

        Map<String, Object> data = new LinkedHashMap<String, Object>();
        data.put("listNo", "BW-20261016-0112");
        data.put("operateDate", "2026年10月16日");
        data.put("warehouseName", "××综合保税区 B 区 2 号库");
        data.put("accountNo", "E2026000088");
        data.put("operatorName", "××保税物流有限公司");
        data.put("operateType", "入库 + 中转出库");
        data.put("transport", "苏A·D72K18 / 集装箱 COSU 3312880");
        data.put("refRecordNo", "BS-20261012-0166");
        data.put("locationRange", "A-01 ~ A-24 / T-中转区");
        data.put("keeper", "路承志");
        data.put("remark", "保税仓储货物须账册平衡,出入库须实时核注;中转货物在监管区内流转,不得擅自运离监管区。");
        data.put("reviewer", "柳文渊");
        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]);
            itemTotal = itemTotal.add(new BigDecimal(items[i][5]));
            data.put("itemAmount" + n, items[i][5]);
            data.put("itemTax" + n, items[i][6]);
        }

        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(44, 44, 44, 44));
        config.getFontConfig().setDefaultFontName("Noto Sans CJK SC");
        config.getHeaderConfig().setEnabled(true);
        config.getHeaderConfig().setText("××综合保税区 保税仓出入库清单 BW-20261016-0112");
        config.getHeaderConfig().setFontSize(7.5f);
        config.getHeaderConfig().setHeight(30);
        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/138_bonded_warehouse_list.txt");

Template file · 138_bonded_warehouse_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>
  // 138 保税仓出入库清单 / 中转货物清单(customs 领域第 14 项) 视觉主题:紫棠·密排·票式
  // 版式组合:抬头=ticket 信息区=strip 明细表=compact 段落=plain 签章=three 落款=right
  // 主色 #2D0F7F 辅色 #917C27 浅底 #F2EFF8
  // 保税仓出入库清单与中转货物清单:库位、作业类型、在库状态与金额。

  // 抬头:ticket
  <h1 style="fontSize:19pt; bold:true; color:#2D0F7F; textAlignment:center; characterSpacing:10pt; marginBottom:2px">'保税仓出入库清单 / 中转货物清单'</h1>
  <p style="fontSize:7.5pt; color:#78838C; textAlignment:center">'清单编号 '${listNo}'  作业日期 '${operateDate}'  仓库 '${warehouseName}</p>
  <lineSeparator style="color:#2D0F7F; thickness:2f"></lineSeparator>
  <lineSeparator style="color:#2D0F7F; thickness:0.5f; marginBottom:8px"></lineSeparator>

  // 信息区:grid2
  <table style="width:100%; fontSize:8.5pt; marginBottom:8px">
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'清单编号 / LIST NO.'</td>
      <td style="width:34%; padding:4px; border:1px solid #C3BBDA">${listNo}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'作业日期 / DATE'</td>
      <td style="padding:4px; border:1px solid #C3BBDA">${operateDate}</td>
    </tr>
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'保税仓库'</td>
      <td style="width:34%; padding:4px; border:1px solid #C3BBDA">${warehouseName}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'账册编号 / E 账册'</td>
      <td style="padding:4px; border:1px solid #C3BBDA">${accountNo}</td>
    </tr>
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'经营单位'</td>
      <td style="width:34%; padding:4px; border:1px solid #C3BBDA">${operatorName}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'作业类型'</td>
      <td style="padding:4px; border:1px solid #C3BBDA">${operateType}</td>
    </tr>
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'运输工具'</td>
      <td style="width:34%; padding:4px; border:1px solid #C3BBDA">${transport}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'关联备案编号'</td>
      <td style="padding:4px; border:1px solid #C3BBDA">${refRecordNo}</td>
    </tr>
    <tr>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'库位区间'</td>
      <td style="width:34%; padding:4px; border:1px solid #C3BBDA">${locationRange}</td>
      <td style="width:16%; padding:4px; backgroundColor:#F2EFF8; bold:true; border:1px solid #C3BBDA">'仓库保管员'</td>
      <td style="padding:4px; border:1px solid #C3BBDA">${keeper}</td>
    </tr>
  </table>

  <p style="fontSize:10pt; bold:true; color:#2D0F7F; marginBottom:3px; characterSpacing:2pt">'出入库 / 中转明细'</p>
  <table style="width:100%; fontSize:7.5pt; marginBottom:8px">
    <tr>
      <th style="width:7%; padding:2px; backgroundColor:#180254; color:white; bold:true; textAlign:center; border:1px solid #180254">'序号'</th>
      <th style="width:24%; padding:2px; backgroundColor:#180254; color:white; bold:true; textAlign:center; border:1px solid #180254">'商品名称规格'</th>
      <th style="width:12%; padding:2px; backgroundColor:#180254; color:white; bold:true; textAlign:center; border:1px solid #180254">'作业类型'</th>
      <th style="width:13%; padding:2px; backgroundColor:#180254; color:white; bold:true; textAlign:center; border:1px solid #180254">'数量 / 单位'</th>
      <th style="width:12%; padding:2px; backgroundColor:#180254; color:white; bold:true; textAlign:center; border:1px solid #180254">'库位'</th>
      <th style="width:14%; padding:2px; backgroundColor:#180254; color:white; bold:true; textAlign:center; border:1px solid #180254">'金额(CNY)'</th>
      <th style="padding:2px; backgroundColor:#180254; color:white; bold:true; textAlign:center; border:1px solid #180254">'状态'</th>
    </tr>
    <tr>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemName1}</td>
      <td style="padding:2px; textAlign:left; border:1px solid #E0DFE5">${itemSpec1}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemUnit1}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemQty1}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemPrice1}</td>
      <td style="padding:2px; textAlign:right; border:1px solid #E0DFE5">${itemAmount1}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemTax1}</td>
    </tr>
    <tr>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemName2}</td>
      <td style="padding:2px; textAlign:left; border:1px solid #E0DFE5">${itemSpec2}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemUnit2}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemQty2}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemPrice2}</td>
      <td style="padding:2px; textAlign:right; border:1px solid #E0DFE5">${itemAmount2}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemTax2}</td>
    </tr>
    <tr>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemName3}</td>
      <td style="padding:2px; textAlign:left; border:1px solid #E0DFE5">${itemSpec3}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemUnit3}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemQty3}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemPrice3}</td>
      <td style="padding:2px; textAlign:right; border:1px solid #E0DFE5">${itemAmount3}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemTax3}</td>
    </tr>
    <tr>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemName4}</td>
      <td style="padding:2px; textAlign:left; border:1px solid #E0DFE5">${itemSpec4}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemUnit4}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemQty4}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemPrice4}</td>
      <td style="padding:2px; textAlign:right; border:1px solid #E0DFE5">${itemAmount4}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemTax4}</td>
    </tr>
    <tr>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemName5}</td>
      <td style="padding:2px; textAlign:left; border:1px solid #E0DFE5">${itemSpec5}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemUnit5}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemQty5}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemPrice5}</td>
      <td style="padding:2px; textAlign:right; border:1px solid #E0DFE5">${itemAmount5}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemTax5}</td>
    </tr>
    <tr>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemName6}</td>
      <td style="padding:2px; textAlign:left; border:1px solid #E0DFE5">${itemSpec6}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemUnit6}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemQty6}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemPrice6}</td>
      <td style="padding:2px; textAlign:right; border:1px solid #E0DFE5">${itemAmount6}</td>
      <td style="padding:2px; textAlign:center; border:1px solid #E0DFE5">${itemTax6}</td>
    </tr>
    <tr>
      <td style="padding:2px; bold:true; backgroundColor:#F2EFF8; textAlign:center; border:1px solid #2D0F7F">'金额合计'</td>
      <td style="padding:2px; backgroundColor:#F2EFF8; border:1px solid #2D0F7F">'—'</td>
      <td style="padding:2px; backgroundColor:#F2EFF8; border:1px solid #2D0F7F">'—'</td>
      <td style="padding:2px; backgroundColor:#F2EFF8; border:1px solid #2D0F7F">'—'</td>
      <td style="padding:2px; backgroundColor:#F2EFF8; border:1px solid #2D0F7F">'—'</td>
      <td style="padding:2px; bold:true; backgroundColor:#F2EFF8; textAlign:right; border:1px solid #2D0F7F">'¥'${totalAmount}</td>
      <td style="padding:2px; backgroundColor:#F2EFF8; border:1px solid #2D0F7F">'—'</td>
    </tr>
  </table>

  // 段落:plain
  <p style="fontSize:10.5pt; bold:true; color:#180254; marginBottom:3px">'库存金额合计'</p>
  <p style="fontSize:9pt; marginBottom:6px">${totalLine}</p>
  <p style="fontSize:10.5pt; bold:true; color:#180254; marginBottom:3px">'备注 / REMARKS'</p>
  <p style="fontSize:9pt; marginBottom:6px">${remark}</p>

  // 签章区:three
  <!-- 签章占位区:后续加盖电子公章 / 骑缝章 / 打印二维码 -->
  <table style="width:100%; fontSize:8pt; marginBottom:8px">
    <tr>
      <td style="width:33%; padding:4px; bold:true; textAlign:center; color:#2D0F7F; border:1px dashed #2D0F7F">'(报关专用章 / 海关验讫章占位)'</td>
      <td style="width:33%; padding:4px; bold:true; textAlign:center; color:#2D0F7F; border:1px dashed #2D0F7F">'(骑缝章 / 二维码占位)'</td>
      <td style="width:33%; padding:4px; bold:true; textAlign:center; color:#2D0F7F; border:1px dashed #2D0F7F">'(二维码占位)'</td>
    </tr>
    <tr>
      <td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D0F7F">'申报单位:'${warehouseName}</td>
      <td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D0F7F">'骑缝章沿右边线骑缝加盖'</td>
      <td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D0F7F">'扫码验真'</td>
    </tr>
    <tr>
      <td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D0F7F">'签章日期:'${operateDate}</td>
      <td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D0F7F">'二维码打印于右上角方框内'</td>
      <td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D0F7F">'尺寸 22mm×22mm'</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:#180254">'仓库保管员:'${keeper}</td>
      <td style="width:38%; padding:4px; textAlign:center; color:#180254">'复核:'${reviewer}</td>
      <td style="padding:4px; textAlign:center; color:#180254">'海关监管:'${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.