Internal receipt — generate this PDF with Java (Template)
Template1 页 A4 · 28 KB
Internal cash receipt stub layout.

Output specs
- PDF pages
- 1
- Chart type
- Template
- Template lines
- 134
- Source lines
- 196
Java source · JQuickBiz113InternalReceipt.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;
/**
* 单据 113:内部收款收据(finance 领域第 14 项)。
*
* <p>本类为独立可运行 Demo:自带 {@code main} 方法、不依赖任何公共工具类或实体类,
* 数据以 key-value 形式通过 {@link JQuickPdfFactory#bindAll(Map)} 注入,
* 版式全部落在模板文件 {@code demo/biz/finance/113_internal_receipt.txt} 中。</p>
*
* <p>视觉主题「琥珀·密排·竖栏」:主色 #939F10、辅色 #274F91、浅底 #F7F8EF;
* 版式为 side 抬头 + chip 信息区 + compact 明细表 + three 签章区 + table 落款,
* 与同领域其它单据互不重样。</p>
*
* <p>内部收款收据:交款人 / 收款部门、款项性质与单据张数、金额合计大小写,</p>
* <p>以及财务专用章与交款人签收栏占位。</p>
*
* <p>运行后输出:{@code D:/test/pdf/113_internal_receipt.pdf}。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickBiz113InternalReceipt {
private static final String PDF_DIR = "D:/test/pdf/";
private static final String OUT_FILE = PDF_DIR + "113_internal_receipt.pdf";
private static final String TEMPLATE = "demo/biz/finance/113_internal_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 = {
{"归还备用金", "2026 年 8 月差旅借款尾款", "2", "1260.00", "银行到账"},
{"归还备用金", "2026 年 9 月差旅借款尾款", "1", "840.00", "现金收讫"},
{"代垫款项收回", "代垫展会物料费", "3", "2150.00", "银行到账"},
{"资产赔偿款", "损坏办公设备赔偿", "1", "680.00", "现金收讫"},
{"其他往来款", "离职交接结算款", "1", "320.00", "银行到账"}
};
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("receiptNo", "SR-20261013-0166");
data.put("receiveDate", "2026年10月13日");
data.put("receiptType", "员工往来款收回");
data.put("payerName", "路承志(研发部)");
data.put("deptName", "××科技有限公司财务部");
data.put("payMethod", "银行转账 / 现金");
data.put("refNo", "借款单 JK-20260805-0092");
data.put("cashierName", "沈亦舟");
data.put("remark", "本收据仅限单位内部往来结算使用,不得作为对外经营性收款凭证,亦不得代替发票使用。");
data.put("auditorName", "柳文渊");
// 明细逐格展开,并累计金额
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("itemAmount" + n, "—");
continue;
}
data.put("itemName" + n, items[i][0]);
data.put("itemSpec" + n, items[i][1]);
data.put("itemUnit" + n, items[i][2]);
itemTotal = itemTotal.add(new BigDecimal(items[i][3]));
data.put("itemQty" + n, items[i][3]);
data.put("itemAmount" + n, items[i][4]);
}
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(40, 40, 40, 40));
config.getFontConfig().setDefaultFontName("Noto Sans CJK SC");
config.getHeaderConfig().setEnabled(true);
config.getHeaderConfig().setText("××科技有限公司 内部收款收据 SR-20261013-0166");
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 + " 字节)");
}
/** 人民币金额转票据大写(元角分,末尾补「整」)。 */
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/113_internal_receipt.txt");Template file · 113_internal_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>
// 113 内部收款收据(finance 领域第 14 项) 视觉主题:琥珀·密排·竖栏
// 版式组合:抬头=side 信息区=chip 明细表=compact 段落=bar 签章=three 落款=table
// 主色 #939F10 辅色 #274F91 浅底 #F7F8EF
// 内部收款收据:员工往来款、备用金归还、代垫款收回等非经营性内部结算。
// 抬头:side
<table style="width:100%; marginBottom:2px">
<tr>
<td style="width:5px; padding:0px; backgroundColor:#939F10">' '</td>
<td style="width:56%; padding:6px; bold:true; fontSize:14.5pt; color:#6B7402; characterSpacing:3pt">'内部收款收据'</td>
<td style="padding:6px; textAlign:right; fontSize:7.5pt; color:#78838C">'收据编号 '${receiptNo}' 收款日期 '${receiveDate}' 收据类型 '${receiptType}</td>
</tr>
</table>
<lineSeparator style="color:#E4E5DF; thickness:1f; marginBottom:8px"></lineSeparator>
// 信息区:chip
<table style="width:100%; fontSize:8.5pt; marginBottom:8px">
<tr>
<td style="width:25%; padding:4px; border:1px solid #D8DBBA">'收据编号:'${receiptNo}</td>
<td style="width:25%; padding:4px; border:1px solid #D8DBBA">'收款日期:'${receiveDate}</td>
<td style="width:25%; padding:4px; border:1px solid #D8DBBA">'收据类型:'${receiptType}</td>
<td style="padding:4px; border:1px solid #D8DBBA">'交款人:'${payerName}</td>
</tr>
<tr>
<td style="width:25%; padding:4px; border:1px solid #D8DBBA">'收款部门:'${deptName}</td>
<td style="width:25%; padding:4px; border:1px solid #D8DBBA">'收款方式:'${payMethod}</td>
<td style="width:25%; padding:4px; border:1px solid #D8DBBA">'关联单据:'${refNo}</td>
<td style="padding:4px; border:1px solid #D8DBBA">'收款人:'${cashierName}</td>
</tr>
</table>
<p style="fontSize:10pt; bold:true; color:#939F10; marginBottom:3px; characterSpacing:2pt">'收款明细'</p>
<table style="width:100%; fontSize:7.5pt; marginBottom:8px">
<tr>
<th style="width:26%; padding:2px; backgroundColor:#6B7402; color:white; bold:true; textAlign:center; border:1px solid #6B7402">'款项性质'</th>
<th style="width:28%; padding:2px; backgroundColor:#6B7402; color:white; bold:true; textAlign:center; border:1px solid #6B7402">'摘要说明'</th>
<th style="width:12%; padding:2px; backgroundColor:#6B7402; color:white; bold:true; textAlign:center; border:1px solid #6B7402">'单据张数'</th>
<th style="width:16%; padding:2px; backgroundColor:#6B7402; color:white; bold:true; textAlign:center; border:1px solid #6B7402">'金额'</th>
<th style="padding:2px; backgroundColor:#6B7402; color:white; bold:true; textAlign:center; border:1px solid #6B7402">'备注'</th>
</tr>
<tr>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemName1}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemSpec1}</td>
<td style="padding:2px; textAlign:center; border:1px solid #E4E5DF">${itemUnit1}</td>
<td style="padding:2px; textAlign:right; border:1px solid #E4E5DF">${itemQty1}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemAmount1}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemName2}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemSpec2}</td>
<td style="padding:2px; textAlign:center; border:1px solid #E4E5DF">${itemUnit2}</td>
<td style="padding:2px; textAlign:right; border:1px solid #E4E5DF">${itemQty2}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemAmount2}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemName3}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemSpec3}</td>
<td style="padding:2px; textAlign:center; border:1px solid #E4E5DF">${itemUnit3}</td>
<td style="padding:2px; textAlign:right; border:1px solid #E4E5DF">${itemQty3}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemAmount3}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemName4}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemSpec4}</td>
<td style="padding:2px; textAlign:center; border:1px solid #E4E5DF">${itemUnit4}</td>
<td style="padding:2px; textAlign:right; border:1px solid #E4E5DF">${itemQty4}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemAmount4}</td>
</tr>
<tr>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemName5}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemSpec5}</td>
<td style="padding:2px; textAlign:center; border:1px solid #E4E5DF">${itemUnit5}</td>
<td style="padding:2px; textAlign:right; border:1px solid #E4E5DF">${itemQty5}</td>
<td style="padding:2px; textAlign:left; border:1px solid #E4E5DF">${itemAmount5}</td>
</tr>
<tr>
<td style="padding:2px; bold:true; backgroundColor:#F7F8EF; textAlign:center; border:1px solid #939F10">'金额合计'</td>
<td style="padding:2px; backgroundColor:#F7F8EF; border:1px solid #939F10">'—'</td>
<td style="padding:2px; backgroundColor:#F7F8EF; border:1px solid #939F10">'—'</td>
<td style="padding:2px; bold:true; backgroundColor:#F7F8EF; textAlign:right; border:1px solid #939F10">'¥'${totalAmount}</td>
<td style="padding:2px; backgroundColor:#F7F8EF; border:1px solid #939F10">'—'</td>
</tr>
</table>
// 段落:bar
<table style="width:100%; marginBottom:2px">
<tr>
<td style="width:4px; padding:0px; backgroundColor:#274F91">' '</td>
<td style="padding:2px; bold:true; fontSize:10.5pt; color:#6B7402">'金额合计'</td>
</tr>
</table>
<p style="fontSize:9pt; marginBottom:6px">${totalLine}</p>
<table style="width:100%; marginBottom:2px">
<tr>
<td style="width:4px; padding:0px; backgroundColor:#274F91">' '</td>
<td style="padding:2px; bold:true; fontSize:10.5pt; color:#6B7402">'备注'</td>
</tr>
</table>
<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:#939F10; border:1px dashed #939F10">'(公章 / 财务专用章占位)'</td>
<td style="width:33%; padding:4px; bold:true; textAlign:center; color:#939F10; border:1px dashed #939F10">'(骑缝章 / 二维码占位)'</td>
<td style="width:33%; padding:4px; bold:true; textAlign:center; color:#939F10; border:1px dashed #939F10">'(二维码占位)'</td>
</tr>
<tr>
<td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #939F10">'单位名称:'${deptName}</td>
<td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #939F10">'骑缝章沿右边线骑缝加盖'</td>
<td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #939F10">'扫码验真'</td>
</tr>
<tr>
<td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #939F10">'签章日期:'${receiveDate}</td>
<td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #939F10">'二维码打印于右上角方框内'</td>
<td style="width:33%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #939F10">'尺寸 22mm×22mm'</td>
</tr>
</table>
// 落款:table
<!-- 落款栏 -->
<table style="width:100%; fontSize:8.5pt">
<tr>
<td style="width:33%; padding:5px; border:1px solid #D8DBBA">'收款人:'${cashierName}</td>
<td style="width:33%; padding:5px; border:1px solid #D8DBBA">'交款人:'${payerName}</td>
<td style="padding:5px; border:1px solid #D8DBBA">'复核:'${auditorName}</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.