Inspection notice — generate this PDF with Java (Template)
Template1 页 A4 · 30 KB
Goods inspection notice / inspection result sheet.

Output specs
- PDF pages
- 1
- Chart type
- Template
- Template lines
- 167
- Source lines
- 126
Java source · JQuickBiz137GoodsInspectionNotice.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.nio.file.Files;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 单据 137:货物查验通知单 / 查验结果单(customs 领域第 13 项)。
*
* <p>本类为独立可运行 Demo:自带 {@code main} 方法、不依赖任何公共工具类或实体类,
* 数据以 key-value 形式通过 {@link JQuickPdfFactory#bindAll(Map)} 注入,
* 版式全部落在模板文件 {@code demo/biz/customs/137_goods_inspection_notice.txt} 中。</p>
*
* <p>视觉主题「群青·疏朗·竖栏」:主色 #2D3194、辅色 #915C27、浅底 #F1F1F6;
* 版式为 side 抬头 + chip 信息区 + airy 明细表 + two 签章区 + plain 落款,
* 与同领域其它单据互不重样。</p>
*
* <p>货物查验通知单 / 查验结果单:通知单号与查验地点、查验类型与到场要求,</p>
* <p>逐项查验项目与判定处置、查验结论与双方签收栏。</p>
*
* <p>运行后输出:{@code D:/test/pdf/137_goods_inspection_notice.pdf}。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickBiz137GoodsInspectionNotice {
private static final String PDF_DIR = "D:/test/pdf/";
private static final String OUT_FILE = PDF_DIR + "137_goods_inspection_notice.pdf";
private static final String TEMPLATE = "demo/biz/customs/137_goods_inspection_notice.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", "品名规格查验", "核对申报品名与实物一致性", "一致", "正常", "放行"},
{"2", "数量重量查验", "过磅 / 开箱清点", "46 件 / 12140 kg", "正常", "放行"},
{"3", "原产地查验", "核对原产地证书与实物标识", "一致", "正常", "放行"},
{"4", "价格质疑核查", "核对成交价格申报合理性", "申报价合理", "正常", "放行"},
{"5", "归类质疑核查", "核对 HS 编码归类", "归类正确", "正常", "放行"},
{"6", "木质包装查验", "IPPC 标识与除害处理", "标识有效", "正常", "放行"}
};
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("noticeNo", "INS-20261015-0077");
data.put("noticeDate", "2026年10月15日");
data.put("checkPlace", "××海关××查验中心 5 号台");
data.put("declarationNo", "220120261012003388");
data.put("conclusion", "单货相符,予以放行");
data.put("consignee", "××国际贸易有限公司");
data.put("checkType", "随机抽查 / 指定查验");
data.put("arriveTime", "2026年10月16日 09:30");
data.put("contactInfo", "崔行知 / 021-66××××××");
data.put("officer", "闻仲平 执法证号 3301××××");
data.put("feedbackDate", "2026年10月18日");
data.put("customsOffice", "××海关");
data.put("remark", "收发货人或其代理人须按通知时间到场协助查验;逾期不到场,海关可径行查验。");
data.put("consigneeSign", "崔行知");
data.put("inputer", "苏见宁");
// 明细逐格展开
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]);
data.put("itemAmount" + n, items[i][5]);
}
// ---------- 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("××海关 货物查验通知单 INS-20261015-0077");
config.getHeaderConfig().setFontSize(8.5f);
config.getHeaderConfig().setHeight(28);
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 + " 字节)");
}
}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/137_goods_inspection_notice.txt");Template file · 137_goods_inspection_notice.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>
// 137 货物查验通知单 / 查验结果单(customs 领域第 13 项) 视觉主题:群青·疏朗·竖栏
// 版式组合:抬头=side 信息区=chip 明细表=airy 段落=bar 签章=two 落款=plain
// 主色 #2D3194 辅色 #915C27 浅底 #F1F1F6
// 货物查验通知单与查验结果单:查验项目、要求、结果与处置意见。
// 抬头:side
<table style="width:100%; marginBottom:2px">
<tr>
<td style="width:5px; padding:0px; backgroundColor:#2D3194">' '</td>
<td style="width:56%; padding:6px; bold:true; fontSize:14.5pt; color:#151874; characterSpacing:3pt">'货物查验通知单 / 查验结果单'</td>
<td style="padding:6px; textAlign:right; fontSize:7.5pt; color:#78838C">'通知单号 '${noticeNo}' 下达日期 '${noticeDate}' 查验地点 '${checkPlace}</td>
</tr>
</table>
<lineSeparator style="color:#DFDFE5; thickness:1f; marginBottom:8px"></lineSeparator>
// 信息区:strip
<table style="width:100%; fontSize:8.5pt; marginBottom:8px">
<tr>
<td style="width:25%; padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'通知单号 / NO.'</td>
<td style="width:25%; padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'下达日期 / DATE'</td>
<td style="width:25%; padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'查验地点'</td>
<td style="padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'报关单号'</td>
</tr>
<tr>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #C0C1D5">${noticeNo}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #C0C1D5">${noticeDate}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #C0C1D5">${checkPlace}</td>
<td style="padding:3px; textAlign:center; border:1px solid #C0C1D5">${declarationNo}</td>
</tr>
<tr>
<td style="width:25%; padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'查验结论'</td>
<td style="width:25%; padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'收发货人'</td>
<td style="width:25%; padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'查验类型'</td>
<td style="padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'要求到场时间'</td>
</tr>
<tr>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #C0C1D5">${conclusion}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #C0C1D5">${consignee}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #C0C1D5">${checkType}</td>
<td style="padding:3px; textAlign:center; border:1px solid #C0C1D5">${arriveTime}</td>
</tr>
<tr>
<td style="width:25%; padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'联系人 / 电话'</td>
<td style="width:25%; padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'查验执法人员'</td>
<td style="width:25%; padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'结果反馈期限'</td>
<td style="padding:3px; backgroundColor:#F1F1F6; bold:true; textAlign:center; border:1px solid #C0C1D5">'查验海关'</td>
</tr>
<tr>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #C0C1D5">${contactInfo}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #C0C1D5">${officer}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #C0C1D5">${feedbackDate}</td>
<td style="padding:3px; textAlign:center; border:1px solid #C0C1D5">${customsOffice}</td>
</tr>
</table>
<table style="width:100%; marginBottom:3px">
<tr>
<td style="width:4px; padding:0px; backgroundColor:#915C27">' '</td>
<td style="padding:3px; bold:true; fontSize:10.5pt; color:#151874">'查验项目与结果'</td>
</tr>
</table>
<table style="width:100%; fontSize:8.5pt; marginBottom:8px">
<tr>
<th style="width:7%; padding:5px; backgroundColor:#F1F1F6; color:#151874; bold:true; textAlign:center; border:1px solid #C0C1D5">'序号'</th>
<th style="width:22%; padding:5px; backgroundColor:#F1F1F6; color:#151874; bold:true; textAlign:center; border:1px solid #C0C1D5">'查验项目'</th>
<th style="width:24%; padding:5px; backgroundColor:#F1F1F6; color:#151874; bold:true; textAlign:center; border:1px solid #C0C1D5">'查验要求'</th>
<th style="width:20%; padding:5px; backgroundColor:#F1F1F6; color:#151874; bold:true; textAlign:center; border:1px solid #C0C1D5">'查验结果'</th>
<th style="width:12%; padding:5px; backgroundColor:#F1F1F6; color:#151874; bold:true; textAlign:center; border:1px solid #C0C1D5">'判定'</th>
<th style="padding:5px; backgroundColor:#F1F1F6; color:#151874; bold:true; textAlign:center; border:1px solid #C0C1D5">'处置'</th>
</tr>
<tr>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemName1}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemSpec1}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemUnit1}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemQty1}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemPrice1}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemAmount1}</td>
</tr>
<tr>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemName2}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemSpec2}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemUnit2}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemQty2}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemPrice2}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemAmount2}</td>
</tr>
<tr>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemName3}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemSpec3}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemUnit3}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemQty3}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemPrice3}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemAmount3}</td>
</tr>
<tr>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemName4}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemSpec4}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemUnit4}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemQty4}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemPrice4}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemAmount4}</td>
</tr>
<tr>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemName5}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemSpec5}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemUnit5}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemQty5}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemPrice5}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemAmount5}</td>
</tr>
<tr>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemName6}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemSpec6}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemUnit6}</td>
<td style="padding:5px; textAlign:left; border:1px solid #E8EBEE">${itemQty6}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemPrice6}</td>
<td style="padding:5px; textAlign:center; border:1px solid #E8EBEE">${itemAmount6}</td>
</tr>
</table>
// 段落:bar
<table style="width:100%; marginBottom:2px">
<tr>
<td style="width:4px; padding:0px; backgroundColor:#915C27">' '</td>
<td style="padding:2px; bold:true; fontSize:10.5pt; color:#151874">'查验结论 / CONCLUSION'</td>
</tr>
</table>
<p style="fontSize:9pt; marginBottom:6px">${conclusion}</p>
<table style="width:100%; marginBottom:2px">
<tr>
<td style="width:4px; padding:0px; backgroundColor:#915C27">' '</td>
<td style="padding:2px; bold:true; fontSize:10.5pt; color:#151874">'备注 / REMARKS'</td>
</tr>
</table>
<p style="fontSize:9pt; marginBottom:6px">${remark}</p>
// 签章区:two
<!-- 签章占位区:后续加盖电子公章 / 骑缝章 / 打印二维码 -->
<table style="width:100%; fontSize:8pt; marginBottom:8px">
<tr>
<td style="width:50%; padding:4px; textAlign:center; color:#2D3194; border:1px dashed #2D3194">'(报关专用章 / 海关验讫章占位)'</td>
<td style="padding:4px; textAlign:center; color:#2D3194; border:1px dashed #2D3194">'(骑缝章 / 二维码占位)'</td>
</tr>
<tr>
<td style="width:50%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D3194">'申报单位:'${customsOffice}</td>
<td style="padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D3194">'骑缝章沿右边线骑缝加盖'</td>
</tr>
<tr>
<td style="width:50%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D3194">'签章日期:'${noticeDate}</td>
<td style="padding:4px; textAlign:center; color:#78838C; border:1px dashed #2D3194">'二维码打印于右上角方框内'</td>
</tr>
</table>
// 落款:plain
<!-- 落款栏 -->
<table style="width:100%; fontSize:9pt; marginTop:6px">
<tr>
<td style="width:33%; padding:4px; color:#151874; borderBottom:1px solid #C0C1D5">'查验关员:'${officer}</td>
<td style="width:33%; padding:4px; color:#151874; borderBottom:1px solid #C0C1D5">'收发货人签收:'${consigneeSign}</td>
<td style="padding:4px; color:#151874; borderBottom:1px solid #C0C1D5">'录入人:'${inputer}</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.