Asset warehouse receipt — generate this PDF with Java (Template)
Template1 页 A4 · 29 KB
Asset warehouse receipt for fixed-asset registration.

Output specs
- PDF pages
- 1
- Chart type
- Template
- Template lines
- 153
- Source lines
- 201
Java source · JQuickBiz123AssetWarehouseReceipt.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.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;
/**
* 单据 123:资产入库单(finance 领域第 24 项)。
*
* <p>本类为独立可运行 Demo:自带 {@code main} 方法、不依赖任何公共工具类或实体类,
* 数据以 key-value 形式通过 {@link JQuickPdfFactory#bindAll(Map)} 注入,
* 版式全部落在模板文件 {@code demo/biz/finance/123_asset_warehouse_receipt.txt} 中。</p>
*
* <p>视觉主题「松绿·密排·通栏」:主色 #287F23、辅色 #5A2791、浅底 #F1F6F1;
* 版式为 banner 抬头 + kv 信息区 + compact 明细表 + card 签章区 + plain 落款,
* 与同领域其它单据互不重样。</p>
*
* <p>资产入库单:入库部门与资产类别、供应商与关联采购订单、</p>
* <p>逐条资产编号与存放位置、入库金额合计与三方签字栏。</p>
*
* <p>运行后输出:{@code D:/test/pdf/123_asset_warehouse_receipt.pdf}。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickBiz123AssetWarehouseReceipt {
private static final String PDF_DIR = "D:/test/pdf/";
private static final String OUT_FILE = PDF_DIR + "123_asset_warehouse_receipt.pdf";
private static final String TEMPLATE = "demo/biz/finance/123_asset_warehouse_receipt.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 = {
{"ZC-2026-0188", "数控加工中心", "VMC-850", "2", "286000.00", "572000.00", "1 号车间 A 区"},
{"ZC-2026-0189", "精密磨床", "MG-1432", "1", "168000.00", "168000.00", "1 号车间 B 区"},
{"ZC-2026-0190", "三坐标测量仪", "CMM-1210", "1", "215000.00", "215000.00", "质检中心"},
{"ZC-2026-0191", "工业空调机组", "IAC-30P", "3", "18600.00", "55800.00", "1 号车间顶部"},
{"ZC-2026-0192", "叉车", "CPD-30", "1", "68000.00", "68000.00", "物流通道"}
};
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("inNo", "AST-IN-20261022-0033");
data.put("inDate", "2026年10月22日");
data.put("deptName", "生产制造部");
data.put("assetType", "机器设备");
data.put("supplierName", "××机床集团销售有限公司");
data.put("poNo", "PO-2026-0921");
data.put("invoiceNo", "10551882");
data.put("keeperName", "路承志");
data.put("remark", "资产入库须经使用部门、设备部与财务部三方验收;资产编号一经生成不得变更,作为后续折旧与盘点依据。");
data.put("payee", "闻仲平");
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, "—");
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(48, 48, 48, 48));
config.getFontConfig().setDefaultFontName("Noto Sans CJK SC");
config.getHeaderConfig().setEnabled(true);
config.getHeaderConfig().setText("××智能装备制造有限公司 资产入库单 AST-IN-20261022-0033");
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/finance/123_asset_warehouse_receipt.txt");Template file · 123_asset_warehouse_receipt.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>
// 123 资产入库单(finance 领域第 24 项) 视觉主题:松绿·密排·通栏
// 版式组合:抬头=banner 信息区=kv 明细表=compact 段落=plain 签章=card 落款=plain
// 主色 #287F23 辅色 #5A2791 浅底 #F1F6F1
// 资产入库单:资产编号、名称规格、存放位置与入库金额,三方验收签字。
// 抬头:banner
<table style="width:100%; marginBottom:6px">
<tr>
<td style="width:58%; padding:8px; backgroundColor:#287F23; color:white; bold:true; fontSize:15pt; characterSpacing:4pt">'资产入库单'</td>
<td style="padding:8px; backgroundColor:#125B0E; color:white; textAlign:right; fontSize:7.5pt">'入库单号 '${inNo}' 入库日期 '${inDate}' 入库部门 '${deptName}</td>
</tr>
</table>
// 信息区:kv
<table style="width:100%; fontSize:9pt; marginBottom:8px">
<tr>
<td style="width:22%; padding:5px; backgroundColor:#F1F6F1; bold:true; border:1px solid #C1D6BF">'入库单号'</td>
<td style="padding:5px; border:1px solid #C1D6BF">${inNo}</td>
</tr>
<tr>
<td style="width:22%; padding:5px; backgroundColor:#F1F6F1; bold:true; border:1px solid #C1D6BF">'入库日期'</td>
<td style="padding:5px; border:1px solid #C1D6BF">${inDate}</td>
</tr>
<tr>
<td style="width:22%; padding:5px; backgroundColor:#F1F6F1; bold:true; border:1px solid #C1D6BF">'入库部门'</td>
<td style="padding:5px; border:1px solid #C1D6BF">${deptName}</td>
</tr>
<tr>
<td style="width:22%; padding:5px; backgroundColor:#F1F6F1; bold:true; border:1px solid #C1D6BF">'资产类别'</td>
<td style="padding:5px; border:1px solid #C1D6BF">${assetType}</td>
</tr>
<tr>
<td style="width:22%; padding:5px; backgroundColor:#F1F6F1; bold:true; border:1px solid #C1D6BF">'供应商'</td>
<td style="padding:5px; border:1px solid #C1D6BF">${supplierName}</td>
</tr>
<tr>
<td style="width:22%; padding:5px; backgroundColor:#F1F6F1; bold:true; border:1px solid #C1D6BF">'关联采购订单'</td>
<td style="padding:5px; border:1px solid #C1D6BF">${poNo}</td>
</tr>
<tr>
<td style="width:22%; padding:5px; backgroundColor:#F1F6F1; bold:true; border:1px solid #C1D6BF">'关联发票号码'</td>
<td style="padding:5px; border:1px solid #C1D6BF">${invoiceNo}</td>
</tr>
<tr>
<td style="width:22%; padding:5px; backgroundColor:#F1F6F1; bold:true; border:1px solid #C1D6BF">'保管人'</td>
<td style="padding:5px; border:1px solid #C1D6BF">${keeperName}</td>
</tr>
</table>
<p style="fontSize:10pt; bold:true; color:#287F23; marginBottom:3px; characterSpacing:2pt">'资产入库明细'</p>
<table style="width:100%; fontSize:7.5pt; marginBottom:8px">
<tr>
<th style="width:16%; padding:2px; backgroundColor:#125B0E; color:white; bold:true; textAlign:center; border:1px solid #125B0E">'资产编号'</th>
<th style="width:20%; padding:2px; backgroundColor:#125B0E; color:white; bold:true; textAlign:center; border:1px solid #125B0E">'资产名称'</th>
<th style="width:14%; padding:2px; backgroundColor:#125B0E; color:white; bold:true; textAlign:center; border:1px solid #125B0E">'规格型号'</th>
<th style="width:8%; padding:2px; backgroundColor:#125B0E; color:white; bold:true; textAlign:center; border:1px solid #125B0E">'数量'</th>
<th style="width:14%; padding:2px; backgroundColor:#125B0E; color:white; bold:true; textAlign:center; border:1px solid #125B0E">'单价'</th>
<th style="width:14%; padding:2px; backgroundColor:#125B0E; color:white; bold:true; textAlign:center; border:1px solid #125B0E">'金额'</th>
<th style="padding:2px; backgroundColor:#125B0E; color:white; bold:true; textAlign:center; border:1px solid #125B0E">'存放位置'</th>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemName1}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE5DF">${itemSpec1}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemUnit1}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemQty1}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemPrice1}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemAmount1}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemTax1}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemName2}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE5DF">${itemSpec2}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemUnit2}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemQty2}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemPrice2}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemAmount2}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemTax2}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemName3}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE5DF">${itemSpec3}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemUnit3}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemQty3}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemPrice3}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemAmount3}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemTax3}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemName4}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE5DF">${itemSpec4}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemUnit4}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemQty4}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemPrice4}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemAmount4}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemTax4}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemName5}</td>
<td style="padding:2px; textAlign:left; border:1px solid #DFE5DF">${itemSpec5}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemUnit5}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemQty5}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemPrice5}</td>
<td style="padding:2px; textAlign:right; border:1px solid #DFE5DF">${itemAmount5}</td>
<td style="padding:2px; textAlign:center; border:1px solid #DFE5DF">${itemTax5}</td>
</tr>
<tr>
<td style="padding:2px; bold:true; backgroundColor:#F1F6F1; textAlign:center; border:1px solid #287F23">'入库金额合计'</td>
<td style="padding:2px; backgroundColor:#F1F6F1; border:1px solid #287F23">'—'</td>
<td style="padding:2px; backgroundColor:#F1F6F1; border:1px solid #287F23">'—'</td>
<td style="padding:2px; backgroundColor:#F1F6F1; border:1px solid #287F23">'—'</td>
<td style="padding:2px; backgroundColor:#F1F6F1; border:1px solid #287F23">'—'</td>
<td style="padding:2px; bold:true; backgroundColor:#F1F6F1; textAlign:right; border:1px solid #287F23">'¥'${totalAmount}</td>
<td style="padding:2px; backgroundColor:#F1F6F1; border:1px solid #287F23">'—'</td>
</tr>
</table>
// 段落:plain
<p style="fontSize:10.5pt; bold:true; color:#125B0E; marginBottom:3px">'入库金额合计'</p>
<p style="fontSize:9pt; marginBottom:6px">${totalLine}</p>
<p style="fontSize:10.5pt; bold:true; color:#125B0E; marginBottom:3px">'备注'</p>
<p style="fontSize:9pt; marginBottom:6px">${remark}</p>
// 签章区:card
<!-- 签章占位区:后续加盖电子公章 / 骑缝章 / 打印二维码 -->
<table style="width:100%; fontSize:8pt; marginBottom:8px">
<tr>
<td style="width:50%; padding:4px; backgroundColor:#F1F6F1; textAlign:center; color:#287F23; border:1px solid #C1D6BF">'(公章 / 财务专用章占位)'</td>
<td style="padding:4px; backgroundColor:#F1F6F1; textAlign:center; color:#287F23; border:1px solid #C1D6BF">'(骑缝章 / 二维码占位)'</td>
</tr>
<tr>
<td style="width:50%; padding:4px; backgroundColor:#F1F6F1; textAlign:center; color:#78838C; border:1px solid #C1D6BF">'单位名称:'${deptName}</td>
<td style="padding:4px; backgroundColor:#F1F6F1; textAlign:center; color:#78838C; border:1px solid #C1D6BF">'骑缝章沿右边线骑缝加盖'</td>
</tr>
<tr>
<td style="width:50%; padding:4px; backgroundColor:#F1F6F1; textAlign:center; color:#78838C; border:1px solid #C1D6BF">'签章日期:'${inDate}</td>
<td style="padding:4px; backgroundColor:#F1F6F1; textAlign:center; color:#78838C; border:1px solid #C1D6BF">'二维码打印于右上角方框内'</td>
</tr>
</table>
// 落款:plain
<!-- 落款栏 -->
<table style="width:100%; fontSize:9pt; marginTop:6px">
<tr>
<td style="width:33%; padding:4px; color:#125B0E; borderBottom:1px solid #C1D6BF">'保管人:'${keeperName}</td>
<td style="width:33%; padding:4px; color:#125B0E; borderBottom:1px solid #C1D6BF">'使用部门:'${payee}</td>
<td style="padding:4px; color:#125B0E; borderBottom:1px solid #C1D6BF">'财务确认:'${drawer}</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.