Travel expense list — generate this PDF with Java (Template)
Template1 页 A4 · 31 KB
Travel expense detail list with itinerary and receipt totals.

Output specs
- PDF pages
- 1
- Chart type
- Template
- Template lines
- 180
- Source lines
- 203
Java source · JQuickBiz116TravelExpenseList.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;
/**
* 单据 116:差旅报销清单 / 费用明细清单(finance 领域第 17 项)。
*
* <p>本类为独立可运行 Demo:自带 {@code main} 方法、不依赖任何公共工具类或实体类,
* 数据以 key-value 形式通过 {@link JQuickPdfFactory#bindAll(Map)} 注入,
* 版式全部落在模板文件 {@code demo/biz/finance/116_travel_expense_list.txt} 中。</p>
*
* <p>视觉主题「秋香·素雅·公文」:主色 #78A714、辅色 #273691、浅底 #F5F8EF;
* 版式为 doc 抬头 + grid2 信息区 + light 明细表 + two 签章区 + right 落款,
* 与同领域其它单据互不重样。</p>
*
* <p>差旅报销清单:出差期间、出差人与随行人员、出差事由、逐日逐项费用明细,</p>
* <p>差旅费用合计大小写与审批签字栏。</p>
*
* <p>运行后输出:{@code D:/test/pdf/116_travel_expense_list.pdf}。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickBiz116TravelExpenseList {
private static final String PDF_DIR = "D:/test/pdf/";
private static final String OUT_FILE = PDF_DIR + "116_travel_expense_list.pdf";
private static final String TEMPLATE = "demo/biz/finance/116_travel_expense_list.txt";
/** 模板固定明细行数,不足时补空行,避免占位符原样输出。 */
private static final int ITEM_ROWS = 8;
public static void main(String[] args) throws IOException {
new File(PDF_DIR).mkdirs();
// ---------- 1. 数据(无实体类,直接 bind)----------
String[][] items = {
{"09-05", "××市", "交通费", "高铁二等座 ××→××", "1", "553.00"},
{"09-05", "××市", "住宿费", "××酒店 标准间", "1", "480.00"},
{"09-06", "××市", "市内交通", "网约车 6 次", "6", "268.00"},
{"09-06", "××市", "业务招待", "客户商务午餐 3 人", "1", "860.00"},
{"09-07", "××市", "住宿费", "××酒店 标准间", "1", "480.00"},
{"09-08", "××市", "交通费", "高铁二等座 ××→××", "1", "553.00"},
{"09-08", "××市", "补助", "出差补助 4 天 × 120 元", "1", "480.00"},
{"09-09", "××市", "其他", "资料打印 / 快递", "3", "186.00"}
};
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("listNo", "TRV-20261016-0412");
data.put("period", "2026年09月05日 — 2026年09月09日");
data.put("traveler", "崔行知 销售部 客户经理");
data.put("destination", "××市 / ××市");
data.put("purpose", "客户年度框架协议洽谈与项目交付验收");
data.put("companions", "路承志(技术支持)");
data.put("approvalNo", "TRV-APP-20260903-0018");
data.put("attachCount", "24");
data.put("deptName", "销售部");
data.put("remark", "出差补助按公司差旅制度 120 元 / 天计算,共 4 天;住宿费凭增值税普通发票据实报销。");
data.put("deptHead", "闻仲平");
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("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]);
itemTotal = itemTotal.add(new BigDecimal(items[i][5]));
data.put("itemAmount" + n, items[i][5]);
}
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(36, 36, 36, 36));
config.getFontConfig().setDefaultFontName("Noto Sans CJK SC");
config.getHeaderConfig().setEnabled(true);
config.getHeaderConfig().setText("××科技有限公司 差旅报销清单 TRV-20261016-0412");
config.getHeaderConfig().setFontSize(8.5f);
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 + " 字节)");
}
/** 人民币金额转票据大写(元角分,末尾补「整」)。 */
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/116_travel_expense_list.txt");Template file · 116_travel_expense_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>
// 116 差旅报销清单 / 费用明细清单(finance 领域第 17 项) 视觉主题:秋香·素雅·公文
// 版式组合:抬头=doc 信息区=grid2 明细表=light 段落=bar 签章=two 落款=right
// 主色 #78A714 辅色 #273691 浅底 #F5F8EF
// 差旅报销清单 / 费用明细清单:按日期城市逐笔列示交通、住宿、市内交通、补助与其他费用。
// 抬头:doc
<p style="fontSize:20pt; bold:true; color:#78A714; textAlignment:center; characterSpacing:9pt; marginBottom:2px">'差旅报销清单 / 费用明细清单'</p>
<p style="fontSize:8pt; color:#78838C; textAlignment:center; marginBottom:4px">'清单编号 '${listNo}' 出差期间 '${period}' 出差人 '${traveler}</p>
<lineSeparator style="color:#78A714; thickness:2f; marginBottom:8px"></lineSeparator>
// 信息区:grid2
<table style="width:100%; fontSize:8.5pt; marginBottom:8px">
<tr>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; bold:true; border:1px solid #D0DABB">'清单编号'</td>
<td style="width:34%; padding:4px; border:1px solid #D0DABB">${listNo}</td>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; bold:true; border:1px solid #D0DABB">'出差期间'</td>
<td style="padding:4px; border:1px solid #D0DABB">${period}</td>
</tr>
<tr>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; bold:true; border:1px solid #D0DABB">'出差人'</td>
<td style="width:34%; padding:4px; border:1px solid #D0DABB">${traveler}</td>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; bold:true; border:1px solid #D0DABB">'出差地点'</td>
<td style="padding:4px; border:1px solid #D0DABB">${destination}</td>
</tr>
<tr>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; bold:true; border:1px solid #D0DABB">'出差事由'</td>
<td style="width:34%; padding:4px; border:1px solid #D0DABB">${purpose}</td>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; bold:true; border:1px solid #D0DABB">'随行人员'</td>
<td style="padding:4px; border:1px solid #D0DABB">${companions}</td>
</tr>
<tr>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; bold:true; border:1px solid #D0DABB">'审批单号'</td>
<td style="width:34%; padding:4px; border:1px solid #D0DABB">${approvalNo}</td>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; bold:true; border:1px solid #D0DABB">'附件张数'</td>
<td style="padding:4px; border:1px solid #D0DABB">${attachCount}</td>
</tr>
<tr>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; bold:true; border:1px solid #D0DABB">'所属部门'</td>
<td style="width:34%; padding:4px; border:1px solid #D0DABB">${deptName}</td>
<td style="width:16%; padding:4px; backgroundColor:#F5F8EF; border:1px solid #D0DABB">' '</td>
<td style="padding:4px; border:1px solid #D0DABB">' '</td>
</tr>
</table>
<table style="width:100%; marginBottom:3px">
<tr>
<td style="padding:4px; backgroundColor:#F5F8EF; bold:true; fontSize:10pt; color:#588004">'差旅费用明细'</td>
</tr>
</table>
<table style="width:100%; fontSize:8.5pt; marginBottom:8px">
<tr>
<th style="width:12%; padding:4px; backgroundColor:#F5F8EF; color:#588004; bold:true; textAlign:center; border:1px solid #D0DABB">'日期'</th>
<th style="width:12%; padding:4px; backgroundColor:#F5F8EF; color:#588004; bold:true; textAlign:center; border:1px solid #D0DABB">'城市'</th>
<th style="width:18%; padding:4px; backgroundColor:#F5F8EF; color:#588004; bold:true; textAlign:center; border:1px solid #D0DABB">'项目'</th>
<th style="width:24%; padding:4px; backgroundColor:#F5F8EF; color:#588004; bold:true; textAlign:center; border:1px solid #D0DABB">'说明'</th>
<th style="width:9%; padding:4px; backgroundColor:#F5F8EF; color:#588004; bold:true; textAlign:center; border:1px solid #D0DABB">'票据数'</th>
<th style="padding:4px; backgroundColor:#F5F8EF; color:#588004; bold:true; textAlign:center; border:1px solid #D0DABB">'金额'</th>
</tr>
<tr>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemName1}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemSpec1}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemUnit1}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemQty1}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemPrice1}</td>
<td style="padding:4px; textAlign:right; border:1px solid #E3E5DF">${itemAmount1}</td>
</tr>
<tr>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemName2}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemSpec2}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemUnit2}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemQty2}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemPrice2}</td>
<td style="padding:4px; textAlign:right; border:1px solid #E3E5DF">${itemAmount2}</td>
</tr>
<tr>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemName3}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemSpec3}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemUnit3}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemQty3}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemPrice3}</td>
<td style="padding:4px; textAlign:right; border:1px solid #E3E5DF">${itemAmount3}</td>
</tr>
<tr>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemName4}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemSpec4}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemUnit4}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemQty4}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemPrice4}</td>
<td style="padding:4px; textAlign:right; border:1px solid #E3E5DF">${itemAmount4}</td>
</tr>
<tr>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemName5}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemSpec5}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemUnit5}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemQty5}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemPrice5}</td>
<td style="padding:4px; textAlign:right; border:1px solid #E3E5DF">${itemAmount5}</td>
</tr>
<tr>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemName6}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemSpec6}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemUnit6}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemQty6}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemPrice6}</td>
<td style="padding:4px; textAlign:right; border:1px solid #E3E5DF">${itemAmount6}</td>
</tr>
<tr>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemName7}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemSpec7}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemUnit7}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemQty7}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemPrice7}</td>
<td style="padding:4px; textAlign:right; border:1px solid #E3E5DF">${itemAmount7}</td>
</tr>
<tr>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemName8}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemSpec8}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemUnit8}</td>
<td style="padding:4px; textAlign:left; border:1px solid #E3E5DF">${itemQty8}</td>
<td style="padding:4px; textAlign:center; border:1px solid #E3E5DF">${itemPrice8}</td>
<td style="padding:4px; textAlign:right; border:1px solid #E3E5DF">${itemAmount8}</td>
</tr>
<tr>
<td style="padding:4px; bold:true; backgroundColor:#F5F8EF; textAlign:center; border:1px solid #78A714">'差旅费用合计'</td>
<td style="padding:4px; backgroundColor:#F5F8EF; border:1px solid #78A714">'—'</td>
<td style="padding:4px; backgroundColor:#F5F8EF; border:1px solid #78A714">'—'</td>
<td style="padding:4px; backgroundColor:#F5F8EF; border:1px solid #78A714">'—'</td>
<td style="padding:4px; backgroundColor:#F5F8EF; border:1px solid #78A714">'—'</td>
<td style="padding:4px; bold:true; backgroundColor:#F5F8EF; textAlign:right; border:1px solid #78A714">'¥'${totalAmount}</td>
</tr>
</table>
// 段落:bar
<table style="width:100%; marginBottom:2px">
<tr>
<td style="width:4px; padding:0px; backgroundColor:#273691">' '</td>
<td style="padding:2px; bold:true; fontSize:10.5pt; color:#588004">'差旅费用合计'</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:#273691">' '</td>
<td style="padding:2px; bold:true; fontSize:10.5pt; color:#588004">'备注'</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:#78A714; border:1px dashed #78A714">'(公章 / 财务专用章占位)'</td>
<td style="padding:4px; textAlign:center; color:#78A714; border:1px dashed #78A714">'(骑缝章 / 二维码占位)'</td>
</tr>
<tr>
<td style="width:50%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #78A714">'单位名称:'${deptName}</td>
<td style="padding:4px; textAlign:center; color:#78838C; border:1px dashed #78A714">'骑缝章沿右边线骑缝加盖'</td>
</tr>
<tr>
<td style="width:50%; padding:4px; textAlign:center; color:#78838C; border:1px dashed #78A714">'签章日期:'${period}</td>
<td style="padding:4px; textAlign:center; color:#78838C; border:1px dashed #78A714">'二维码打印于右上角方框内'</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:#588004">'出差人:'${traveler}</td>
<td style="width:38%; padding:4px; textAlign:center; color:#588004">'部门负责人:'${deptHead}</td>
<td style="padding:4px; textAlign:center; color:#588004">'财务审核:'${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.