Commodity inspection report — generate this PDF with Java (Template)
Template1 页 A4 · 33 KB
Import/export commodity inspection and quarantine report.

Output specs
- PDF pages
- 1
- Chart type
- Template
- Template lines
- 155
- Source lines
- 125
Java source · JQuickBiz133CommodityInspectionReport.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;
/**
* 单据 133:进出口商品检验 / 检疫检验报告(customs 领域第 9 项)。
*
* <p>本类为独立可运行 Demo:自带 {@code main} 方法、不依赖任何公共工具类或实体类,
* 数据以 key-value 形式通过 {@link JQuickPdfFactory#bindAll(Map)} 注入,
* 版式全部落在模板文件 {@code demo/biz/customs/133_commodity_inspection_report.txt} 中。</p>
*
* <p>视觉主题「宝蓝·密排·下线」:主色 #153580、辅色 #913F27、浅底 #F0F2F7;
* 版式为 underline 抬头 + chip 信息区 + compact 明细表 + two 签章区 + table 落款,
* 与同领域其它单据互不重样。</p>
*
* <p>进出口商检 / 检疫检验报告:报检单位与货物信息、检验依据、</p>
* <p>逐项检验项目与判定结果、检验结论与检验机构签章栏。</p>
*
* <p>运行后输出:{@code D:/test/pdf/133_commodity_inspection_report.pdf}。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickBiz133CommodityInspectionReport {
private static final String PDF_DIR = "D:/test/pdf/";
private static final String OUT_FILE = PDF_DIR + "133_commodity_inspection_report.pdf";
private static final String TEMPLATE = "demo/biz/customs/133_commodity_inspection_report.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", "安全性能检验", "GB/T 14711 耐压 1500V", "通过,无击穿", "合格", "—"},
{"4", "电磁兼容检验", "GB 4343.1 限值内", "符合 A 级限值", "合格", "—"},
{"5", "木质包装检疫", "IPPC 标识有效", "标识清晰有效", "合格", "—"},
{"6", "动植物检疫", "无土壤、无活体", "未检出", "合格", "—"}
};
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("reportNo", "CIQ-20261011-0091");
data.put("checkDate", "2026年10月11日");
data.put("orgName", "××海关技术中心 ××出入境检验检疫局");
data.put("applicant", "××国际贸易有限公司");
data.put("regNo", "3301-CIQ-008812");
data.put("goodsName", "伺服电机、精密齿轮箱等机电产品");
data.put("quantityInfo", "46 件 / 12140 kg");
data.put("countryInfo", "SINGAPORE → CHINA");
data.put("standard", "GB/T 14711-2013 及合同技术条款");
data.put("conclusion", "所检项目符合标准要求");
data.put("remark", "本报告仅对来样负责;未经检验机构书面批准,不得部分复制本报告。");
data.put("inspector", "路承志");
data.put("reviewer", "闻仲平");
data.put("issuer", "××海关技术中心");
// 明细逐格展开
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("××海关技术中心 进出口商品检验报告 CIQ-20261011-0091");
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 + " 字节)");
}
}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/133_commodity_inspection_report.txt");Template file · 133_commodity_inspection_report.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>
// 133 进出口商品检验 / 检疫检验报告(customs 领域第 9 项) 视觉主题:宝蓝·密排·下线
// 版式组合:抬头=underline 信息区=chip 明细表=compact 段落=box 签章=two 落款=table
// 主色 #153580 辅色 #913F27 浅底 #F0F2F7
// 进出口商检单与检疫检验报告:检验项目、标准要求、检验结果与判定。
// 抬头:underline
<table style="width:100%; marginBottom:1px">
<tr>
<td style="width:62%; padding:2px; bold:true; fontSize:15pt; color:#061E57; characterSpacing:3pt">'进出口商品检验 / 检疫检验报告'</td>
<td style="padding:2px; textAlign:right; fontSize:7.5pt; color:#78838C">'报告编号 '${reportNo}' 检验日期 '${checkDate}' 检验机构 '${orgName}</td>
</tr>
</table>
<lineSeparator style="color:#153580; thickness:2.5f; marginBottom:8px"></lineSeparator>
// 信息区:strip
<table style="width:100%; fontSize:8.5pt; marginBottom:8px">
<tr>
<td style="width:25%; padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'报告编号 / REPORT NO.'</td>
<td style="width:25%; padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'检验日期 / DATE'</td>
<td style="width:25%; padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'检验机构'</td>
<td style="padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'申请人 / APPLICANT'</td>
</tr>
<tr>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #BDC5D9">${reportNo}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #BDC5D9">${checkDate}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #BDC5D9">${orgName}</td>
<td style="padding:3px; textAlign:center; border:1px solid #BDC5D9">${applicant}</td>
</tr>
<tr>
<td style="width:25%; padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'报检单位注册号'</td>
<td style="width:25%; padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'货物名称'</td>
<td style="width:25%; padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'报检数量 / 重量'</td>
<td style="padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'输出 / 输入国家'</td>
</tr>
<tr>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #BDC5D9">${regNo}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #BDC5D9">${goodsName}</td>
<td style="width:25%; padding:3px; textAlign:center; border:1px solid #BDC5D9">${quantityInfo}</td>
<td style="padding:3px; textAlign:center; border:1px solid #BDC5D9">${countryInfo}</td>
</tr>
<tr>
<td style="width:50%; padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'检验依据'</td>
<td style="padding:3px; backgroundColor:#F0F2F7; bold:true; textAlign:center; border:1px solid #BDC5D9">'检验结论'</td>
</tr>
<tr>
<td style="width:50%; padding:3px; textAlign:center; border:1px solid #BDC5D9">${standard}</td>
<td style="padding:3px; textAlign:center; border:1px solid #BDC5D9">${conclusion}</td>
</tr>
</table>
<p style="fontSize:10pt; bold:true; color:#153580; marginBottom:3px; characterSpacing:2pt">'检验项目明细'</p>
<table style="width:100%; fontSize:7.5pt; marginBottom:8px">
<tr>
<th style="width:8%; padding:2px; backgroundColor:#061E57; color:white; bold:true; textAlign:center; border:1px solid #061E57">'序号'</th>
<th style="width:22%; padding:2px; backgroundColor:#061E57; color:white; bold:true; textAlign:center; border:1px solid #061E57">'检验项目'</th>
<th style="width:22%; padding:2px; backgroundColor:#061E57; color:white; bold:true; textAlign:center; border:1px solid #061E57">'标准要求'</th>
<th style="width:20%; padding:2px; backgroundColor:#061E57; color:white; bold:true; textAlign:center; border:1px solid #061E57">'检验结果'</th>
<th style="width:12%; padding:2px; backgroundColor:#061E57; color:white; bold:true; textAlign:center; border:1px solid #061E57">'判定'</th>
<th style="padding:2px; backgroundColor:#061E57; color:white; bold:true; textAlign:center; border:1px solid #061E57">'备注'</th>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemName1}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemSpec1}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemUnit1}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemQty1}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemPrice1}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemAmount1}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemName2}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemSpec2}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemUnit2}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemQty2}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemPrice2}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemAmount2}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemName3}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemSpec3}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemUnit3}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemQty3}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemPrice3}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemAmount3}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemName4}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemSpec4}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemUnit4}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemQty4}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemPrice4}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemAmount4}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemName5}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemSpec5}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemUnit5}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemQty5}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemPrice5}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemAmount5}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemName6}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemSpec6}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemUnit6}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE1E5">${itemQty6}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemPrice6}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE1E5">${itemAmount6}</td>
</tr>
</table>
// 段落:box
<table style="width:100%; marginBottom:6px">
<tr>
<td style="width:150px; padding:5px; backgroundColor:#F0F2F7; bold:true; fontSize:9.5pt; color:#061E57; border:1px solid #BDC5D9">'检验结论 / CONCLUSION'</td>
<td style="padding:5px; fontSize:9pt; border:1px solid #BDC5D9">${conclusion}</td>
</tr>
</table>
<table style="width:100%; marginBottom:6px">
<tr>
<td style="width:150px; padding:5px; backgroundColor:#F0F2F7; bold:true; fontSize:9.5pt; color:#061E57; border:1px solid #BDC5D9">'备注 / REMARKS'</td>
<td style="padding:5px; fontSize:9pt; border:1px solid #BDC5D9">${remark}</td>
</tr>
</table>
// 签章区:two
<!-- 签章占位区:后续加盖电子公章 / 骑缝章 / 打印二维码 -->
<table style="width:100%; fontSize:8pt; marginBottom:8px">
<tr>
<td style="width:50%; padding:4px; textAlign:center; color:#153580; border:1px dashed #153580">'(报关专用章 / 海关验讫章占位)'</td>
<td style="padding:4px; textAlign:center; color:#153580; border:1px dashed #153580">'(骑缝章 / 二维码占位)'</td>
</tr>
<tr>
<td style="width:50%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #153580">'申报单位:'${orgName}</td>
<td style="padding:4px; textAlign:center; color:#78838C; border:1px dashed #153580">'骑缝章沿右边线骑缝加盖'</td>
</tr>
<tr>
<td style="width:50%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #153580">'签章日期:'${checkDate}</td>
<td style="padding:4px; textAlign:center; color:#78838C; border:1px dashed #153580">'二维码打印于右上角方框内'</td>
</tr>
</table>
// 落款:table
<!-- 落款栏 -->
<table style="width:100%; fontSize:8.5pt">
<tr>
<td style="width:33%; padding:5px; border:1px solid #BDC5D9">'检验员:'${inspector}</td>
<td style="width:33%; padding:5px; border:1px solid #BDC5D9">'审核:'${reviewer}</td>
<td style="padding:5px; border:1px solid #BDC5D9">'签发:'${issuer}</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.