Skip to content

Vehicle inspection — generate this PDF with Java (Template)

JQuick-PdfScenario Demos

Template2 页 A4 · 46 KB

Vehicle inspection report issued by a testing station.

Download the PDFView raw template fileBack to all demos

Vehicle inspection — Template
Rendered output

Output specs

PDF pages
2
Chart type
Template
Template lines
207
Source lines
135

Java source · JQuickBiz90VehicleInspection.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.scenario;

import com.github.paohaijiao.config.JPdfConfig;
import com.github.paohaijiao.executor.JQuickPdfFactory;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

public class JQuickBiz90VehicleInspection {

    private static final String PDF_DIR = "D:/test/pdf/";
    private static final String IMG_DIR = "D:/test/image/";
    private static final String OUT_FILE = PDF_DIR + "90_vehicle_inspection.pdf";
    private static final String TEMPLATE = "report/biz/90_vehicle_inspection.txt";
    private static final String SEAL = IMG_DIR + "90_seal.png";

    /** 检测项目:名称、标准要求、实测值、判定。 */
    private static final String[][] ITEMS = {
            {"唯一性认定", "VIN 与登记信息一致", "一致", "合格"},
            {"外观检查", "车身无明显变形、无非法改装", "符合", "合格"},
            {"外部照明和信号装置", "各灯具点亮正常", "正常", "合格"},
            {"制动性能(行车)", "制动力 ≥ 60% 轴荷", "68%", "合格"},
            {"制动性能(驻车)", "驻车制动力 ≥ 20%", "26%", "合格"},
            {"制动踏板自由行程", "10-30mm", "18mm", "合格"},
            {"转向轮侧滑量", "≤ 5m/km", "2.1m/km", "合格"},
            {"前照灯发光强度", "≥ 15000cd(近光)", "18600cd", "合格"},
            {"前照灯照射位置", "符合 GB 7258 要求", "符合", "合格"},
            {"车速表指示误差", "-5%~0%", "-2.4%", "合格"},
            {"喇叭声级", "90-115dB(A)", "102dB(A)", "合格"},
            {"排放(CO)", "≤ 0.6%", "0.42%", "合格"},
            {"排放(HC)", "≤ 80ppm", "62ppm", "合格"},
            {"底盘检查", "无渗漏、无松动", "左后减震渗油", "不合格"},
            {"轮胎胎冠花纹深度", "≥ 1.6mm", "3.2mm", "合格"},
            {"轮胎气压", "符合厂家规定", "符合", "合格"},
            {"悬架系统", "无断裂、无失效", "符合", "合格"},
            {"安全带", "齐全有效", "齐全", "合格"},
            {"安全玻璃", "无破损、标识齐全", "符合", "合格"},
            {"电动窗与门锁", "动作正常", "正常", "合格"}
    };

    public static void main(String[] args) throws IOException {
        new File(PDF_DIR).mkdirs();
        new File(IMG_DIR).mkdirs();
        generateSeal(SEAL);

        Map<String, Object> data = new LinkedHashMap<String, Object>();
        data.put("reportNo", "JC-2026-1019-0173");
        data.put("plateNo", "沪 A·D12345");
        data.put("vehicleType", "小型轿车(纯电动)");
        data.put("ownerName", "××物流有限公司");
        data.put("ownerPhone", "021-6123-8899");
        data.put("inspectDate", "2026年10月19日 10:40");
        data.put("inspectOrg", "××机动车检测有限公司");
        data.put("inspector", "孙磊");
        data.put("reviewer", "郑海");

        int failed = 0;
        for (int i = 0; i < ITEMS.length; i++) {
            String verdict = ITEMS[i][3];
            boolean pass = "合格".equals(verdict);
            if (!pass) {
                failed++;
            }
            int row = i + 1;
            data.put("item" + row + "_1", String.valueOf(row));
            data.put("item" + row + "_2", ITEMS[i][0]);
            data.put("item" + row + "_3", ITEMS[i][1]);
            data.put("item" + row + "_4", ITEMS[i][2]);
            data.put("item" + row + "_5", verdict);
            data.put("item" + row + "_5color", pass ? "#1B5E20" : "#B71C1C");
        }
        boolean allPass = failed == 0;
        data.put("conclusion", allPass ? "合格" : "不合格");
        data.put("conclusionBg", allPass ? "#F0F7F0" : "#FFF5F5");
        data.put("conclusionColor", allPass ? "#1B5E20" : "#B71C1C");
        data.put("totalCount", String.valueOf(ITEMS.length));
        data.put("passCount", String.valueOf(ITEMS.length - failed));
        data.put("failCount", String.valueOf(failed));

        JPdfConfig config = new JPdfConfig();
        config.getLayoutConfig().setFlexLayout(true);
        config.getDoc().setMargins(Arrays.asList(46, 48, 55, 48));
        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);
        FileOutputStream out = new FileOutputStream(OUT_FILE);
        out.write(pdf);
        out.close();
        System.out.println("已生成:" + OUT_FILE);
    }

    private static void generateSeal(String path) throws IOException {
        int size = 200;
        BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Color red = new Color(0xC6, 0x28, 0x28);
        g.setColor(red);
        g.setStroke(new BasicStroke(6f));
        g.drawOval(8, 8, size - 16, size - 16);
        g.setFont(new Font("Microsoft YaHei", Font.BOLD, 13));
        g.drawString("××机动车检测有限公司", 18, 58);
        g.setFont(new Font("Microsoft YaHei", Font.BOLD, 16));
        g.drawString("检测专用章", size / 2 - 40, size / 2 + 26);
        g.dispose();
        ImageIO.write(image, "png", new File(path));
    }
}

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("report/biz/90_vehicle_inspection.txt");

Template file · 90_vehicle_inspection.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>

// 抬头
<h1 style="fontSize:15pt; bold:true; color:#1F4E79; textAlignment:center; characterSpacing:3pt">${inspectOrg}</h1>
<h1 style="fontSize:17pt; bold:true; color:#1A2733; textAlignment:center; characterSpacing:4pt; marginTop:3px">'机动车安全技术检验报告'</h1>
<p style="fontSize:8.5pt; color:#5A6B7C; textAlignment:right; marginBottom:6px">'报告编号:'${reportNo}</p>

// 车辆与车主信息
<table style="width:100%; fontSize:9pt">
  <tr>
    <td style="width:76px; padding:5px; backgroundColor:#E8EDF2; bold:true; border:1px solid #C3CDD8">'号牌号码'</td>
    <td style="width:140px; padding:5px; border:1px solid #C3CDD8">${plateNo}</td>
    <td style="width:76px; padding:5px; backgroundColor:#E8EDF2; bold:true; border:1px solid #C3CDD8">'车辆类型'</td>
    <td style="padding:5px; border:1px solid #C3CDD8">${vehicleType}</td>
  </tr>
  <tr>
    <td style="padding:5px; backgroundColor:#E8EDF2; bold:true; border:1px solid #C3CDD8">'所有人'</td>
    <td style="padding:5px; border:1px solid #C3CDD8">${ownerName}</td>
    <td style="padding:5px; backgroundColor:#E8EDF2; bold:true; border:1px solid #C3CDD8">'联系电话'</td>
    <td style="padding:5px; border:1px solid #C3CDD8">${ownerPhone}</td>
  </tr>
  <tr>
    <td style="padding:5px; backgroundColor:#E8EDF2; bold:true; border:1px solid #C3CDD8">'检验日期'</td>
    <td style="padding:5px; border:1px solid #C3CDD8">${inspectDate}</td>
    <td style="padding:5px; backgroundColor:#E8EDF2; bold:true; border:1px solid #C3CDD8">'检验类别'</td>
    <td style="padding:5px; border:1px solid #C3CDD8">'定期检验(安全技术)'</td>
  </tr>
</table>

// 检测项目明细:每 20 行重复一次表头(一页 20 行)
<table style="width:100%; fontSize:8.5pt; marginTop:6px">
  <tr>
    <th style="width:32px; padding:4px; backgroundColor:#1F4E79; color:white; textAlign:center; border:1px solid #1F4E79">'序号'</th>
    <th style="width:26%; padding:4px; backgroundColor:#1F4E79; color:white; textAlign:center; border:1px solid #1F4E79">'检测项目'</th>
    <th style="width:29%; padding:4px; backgroundColor:#1F4E79; color:white; textAlign:center; border:1px solid #1F4E79">'标准要求'</th>
    <th style="padding:4px; backgroundColor:#1F4E79; color:white; textAlign:center; border:1px solid #1F4E79">'实测值'</th>
    <th style="width:57px; padding:4px; backgroundColor:#1F4E79; color:white; textAlign:center; border:1px solid #1F4E79">'判定'</th>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item1_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item1_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item1_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item1_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item1_5color}; border:1px solid #C3CDD8">${item1_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item2_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item2_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item2_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item2_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item2_5color}; border:1px solid #C3CDD8">${item2_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item3_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item3_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item3_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item3_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item3_5color}; border:1px solid #C3CDD8">${item3_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item4_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item4_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item4_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item4_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item4_5color}; border:1px solid #C3CDD8">${item4_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item5_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item5_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item5_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item5_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item5_5color}; border:1px solid #C3CDD8">${item5_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item6_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item6_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item6_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item6_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item6_5color}; border:1px solid #C3CDD8">${item6_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item7_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item7_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item7_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item7_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item7_5color}; border:1px solid #C3CDD8">${item7_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item8_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item8_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item8_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item8_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item8_5color}; border:1px solid #C3CDD8">${item8_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item9_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item9_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item9_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item9_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item9_5color}; border:1px solid #C3CDD8">${item9_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item10_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item10_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item10_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item10_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item10_5color}; border:1px solid #C3CDD8">${item10_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item11_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item11_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item11_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item11_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item11_5color}; border:1px solid #C3CDD8">${item11_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item12_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item12_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item12_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item12_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item12_5color}; border:1px solid #C3CDD8">${item12_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item13_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item13_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item13_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item13_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item13_5color}; border:1px solid #C3CDD8">${item13_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item14_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item14_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item14_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item14_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item14_5color}; border:1px solid #C3CDD8">${item14_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item15_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item15_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item15_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item15_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item15_5color}; border:1px solid #C3CDD8">${item15_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item16_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item16_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item16_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item16_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item16_5color}; border:1px solid #C3CDD8">${item16_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item17_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item17_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item17_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item17_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item17_5color}; border:1px solid #C3CDD8">${item17_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item18_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item18_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item18_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item18_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item18_5color}; border:1px solid #C3CDD8">${item18_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item19_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item19_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item19_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item19_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item19_5color}; border:1px solid #C3CDD8">${item19_5}</td>
  </tr>
  <tr>
    <td style="padding:4px; textAlign:center; border:1px solid #C3CDD8">${item20_1}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item20_2}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item20_3}</td>
    <td style="padding:4px; border:1px solid #C3CDD8">${item20_4}</td>
    <td style="padding:4px; textAlign:center; bold:true; color:${item20_5color}; border:1px solid #C3CDD8">${item20_5}</td>
  </tr>
</table>

// 检验结论
<table style="width:100%; fontSize:10pt; marginTop:4px">
  <tr>
    <td style="padding:8px; backgroundColor:${conclusionBg}; border:1px solid #C3CDD8; textAlignment:center; bold:true; color:${conclusionColor}">'检验结论:'${conclusion}</td>
  </tr>
</table>

<p style="fontSize:8.5pt; color:#5A6B7C; marginTop:6px">'本次共检验 '${totalCount}' 项,合格 '${passCount}' 项,不合格 '${failCount}' 项。'</p>

// 签章
<div style="display:flex; justifyContent:space-between; marginTop:16px">
  <div style="width:62%">
    <p style="fontSize:9pt; color:#5A6B7C">'检验员:'${inspector}'  审核人:'${reviewer}</p>
    <p style="fontSize:8.5pt; color:#8a939b; marginTop:4px">'本报告仅对所检车辆当次状态负责,报告有效期 6 个月。'</p>
    <p style="fontSize:8.5pt; color:#8a939b; marginTop:3px">'检验日期:'${inspectDate}</p>
  </div>
  <div style="width:34%; textAlignment:center">
    <image src='D:/test/image/90_seal.png' style="width:92px; height:92px"></image>
    <p style="fontSize:9pt; bold:true; color:#1A2733; textAlignment:center">${inspectOrg}</p>
    <p style="fontSize:8pt; color:#B71C1C; textAlignment:center">'检测专用章'</p>
  </div>
</div>

</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.