当前位置: 首页 > news >正文

wordpress火车头长沙seo行者seo09

wordpress火车头,长沙seo行者seo09,软件技术用什么软件,惠州外贸网站建设前言 最近公司让写一个数据页面生成pdf的功能,找了一些市面代码感觉都太麻烦,就自己综合性整合了一个便捷的工具类,开发只需简单组装数据直接调用即可快速生成pdf文件。望大家一起学习!!! 代码获取方式&am…

前言

最近公司让写一个数据页面生成pdf的功能,找了一些市面代码感觉都太麻烦,就自己综合性整合了一个便捷的工具类,开发只需简单组装数据直接调用即可快速生成pdf文件。望大家一起学习!!!
代码获取方式:

  1. 资源下载
  2. 后台私信(一键三连哦!!!)

二、前期准备

1、html模版(放置接口所在项目的resourcess/templates/

需要准备一个要看到的pdf模版,利用html代码形式简单输出,其中需要动态填充的地方需要用变量进行填充
比如页面显示:
姓名:韩云中
性别:男

<div>姓名:${name}性别:${sex}
</div>

2、数据实体

AbstractDocumentVo 必须继承 会有个findPrimaryKey方法需要实现,return一个你这条数据的标识即可
实体字段名称必须与html${}内容一致

public class User extends AbstractDocumentVo {private String name;private String sex;@Overridepublic String findPrimaryKey() {// 数据标识  id或则其它均可return this.name;}
}

三、代码开发

实现接口

@GetMapping("/testCreatePdf")
public void testCreatePdf(HttpServletResponse response) {// 方式一:前端直接给你传递这个对象// 方式二:通过前端传递的标识,自行去库中进行数据获取// ** 两种方式都需要保证html用到的字段不能存在null 不然报错User user = new User();user.setName("");user.setSex("");// 生成pdf路径PdfDocumentGenerator pdfGenerator = new PdfDocumentGenerator();// 生成pdf  // 参数一:classpath中templates下对应要用的模版名称 // 参数二:模板数据 // 参数三:生成pdf名称// 参数四:responsepdfGenerator.generate("overseaAssistance.html", overseaVo, "2.pdf", response);
}

四、结果

得到自己想要的pdf文件
在这里插入图片描述

测试数据

java实体

package com.yxy.aob.controller;import com.yxy.common.core.utils.file.pdf.AbstractDocumentVo;
import lombok.Data;
import lombok.EqualsAndHashCode;/*** @Description:* @Author: Hyz* @Date: 2024/10/11 11:22* @Version:1.0*/
@EqualsAndHashCode(callSuper = true)
@Data
public class OverseaVo extends AbstractDocumentVo {/*** 标识*/private String policyNo;/*** 投保人姓名*/private String holderName;/*** 投被保人关系*/private String relation;/*** 投保人联络地址*/private String holderAdress;/*** 投保人邮编*/private String holderPostCode;/*** 被保险人姓名*/private String insuredName;/*** 被保险人姓名拼音*/private String insuredPingyinName;/*** 被保险人护照号码*/private String insuredPassportNo;/*** 被保险人性别*/private String insuredSex;/*** 被保险人出生日期*/private String insuredBirthday;/*** 被保险人电话*/private String insuredPhone;/*** 被保险人证件号码*/private String insuredIDNo;/*** 前往国家或地区*/private String destination;/*** 受益人姓名*/private String beneficiaryName;/*** 备注*/private String remarks;/*** 保险期间*/private String period;/*** 境外意外伤害或残疾保额*/private String accidentalSumInsured;/*** 紧急救援医疗保额*/private String emergencySumInsured;/*** 附加境外紧急救援医保额*/private String medicalSumInsured;/*** 总保费*/private String premium;/*** 签发日期*/private String issueDate;/*** 省份*/private String branchName;/*** 合作公司名称*/private String companyName;@Overridepublic String findPrimaryKey() {return this.policyNo;}
}

html模版

<html>
<head><title></title><style type="text/css">body {margin-left: 45px;margin-right: 45px;font-family: Arial Unicode MS;font-size: 10px;}table {margin: auto;width: 100%;border-collapse: collapse;border: 1px solid #444444;}th,td {border: 1px solid #444444;font-size: 10px;margin-left: 5px;}.mcContent {line-height: 180%;padding: 20px;}.logo {text-align: center;}.title {text-align: center;font-weight: bold;font-size: 20px;}.notes {font-weight: normal;margin-left: 5px;margin-right: 5px;line-height: 18px;}.text_content {margin-left: 5px;margin-right: 5px;line-height: 18px;}.sum_insured_first_row {width: 20%;}.sum_insured_span {font-size: 10px;}.special_agreements_div {page-break-before: always;font-size: 14px;margin-top: 20px;}.special_agreements_div .special_agreements {font-size: 18px;font-weight: bold;}.title_right {width: 100%;margin: 0 auto;}.title_right p {text-align: left;margin: 0;margin-left: 50%;padding: 0;}@page {size: 8.5in 11in;@bottom-center{content:"page "counter(page)" of  "counter(pages);}.signature {margin: 0 auto;clear: both;font-size: 16px;font-weight: bold;}.signature_table {/*     font-size: 16px; */font-weight: bold;}</style>
</head>
<body>
<div><div class="title">测试PDF生成--<p>测试单号:${policyNo}</p></div><div class="insurance_info"><table class="insurance_info_table" cellpadding="0" cellspacing="0"width="100%"><tr><td width="20%" colspan="3">投保人<br /> Policyholder</td><td width="43%" colspan="3">${holderName}<br /></td><td width="15%">与被保险人关系<br /> Relationship with the Insured</td><td >${relation}</td></tr><tr><td width="20%" colspan="3">联络地址<br /> Correspondence Address</td><td width="43%" colspan="3">${holderAdress}</td><td width="15%">邮编<br /> Postal Code</td><td >${holderPostCode}</td></tr><tr class="td_width1"><td width="20%" colspan="3">被保险人姓名<br /> Name of the Insured</td><td width="13%">${holderName}</td><td width="10%">(拼音)<br /> (Pinyin)</td><td width="18%">${insuredPingyinName}</td><td width="15%">护照号码<br /> Passport No</td><td>${insuredPassportNo}</td></tr><tr><td width="5%">性别<br /> Sex</td><td width="5%">${insuredSex}</td><td width="10%">出生日期<br /> Date of Birth</td><td width="13%">${insuredBirthday}</td><td width="10%">电话<br /> Telephone No.</td><td width="18%">${insuredPhone}</td><td width="15%">证件号码 <br />ID No.</td><td >${insuredIDNo}</td></tr><tr><td colspan="3">请详细列明前往国家或地区<br /> Destination</td><td colspan="3">${destination}</td><td>受益人姓名<br /> Beneficiary</td><td>${beneficiaryName}</td></tr><tr><td class="address_class" colspan="3">备注 <br /> Remarks</td><td colspan="5">${remarks}</td></tr><tr><td class="address_class" colspan="3">保险期间 <br /> Insuranceperiod</td><td colspan="5">${period}</td></tr></table></div><div class="signature"><br /> <br /><table class="signature_table" style="border: 0; width: 100%;"><tr><thstyle="border: 0; font-size: 12px; font-weight: bold; text-align: left; width: 17%;">总经理签名:<br /> <span style="font-size:10px">Authorized Signature</span></th><tdstyle="border: 0; font-size: 12px; font-weight: bold; text-align: left; width: 17%;"></td><thstyle="border: 0; font-size: 12px; font-weight: bold; text-align: left; width: 17%;">公司签章:<br /><span style="font-size:10px">Company Stamp</span></th><tdstyle="border: 0; font-size: 12px; font-weight: bold; text-align: left; width: 17%;"></td><thstyle="border: 0; font-size: 12px; font-weight: bold; text-align: left; width: 16%;">签发日期:<br /><span style="font-size:10px">Issue Date</span></th><tdstyle="border: 0; font-size: 12px; font-weight: bold; text-align: left; width: 16%;">${issueDate}</td></tr></table></div><div class="text_content"><br /> 我从来不是那样的人,不能耐心地拾起一地碎片,把它们凑合在一起,然后对自己说,这个修补好了的东西,跟新的完全一样。一样东西破碎了就是破碎了,我宁愿记住它最好时的模样,而不想把它修补好,然后终生看着那些碎了的地方。</div></div>
</body>
</html>
http://www.ds6.com.cn/news/38278.html

相关文章:

  • 建网站排名网页设计大作业
  • 美国专门做特卖的网站有哪些网站关键词优化教程
  • WordPress整站搬家插件时事政治2023最新热点事件
  • 国内投资咨询网站 html模板今日最新新闻
  • 浙江省建设局网站提高工作效率
  • 编程训练网站百度短链接在线生成
  • 外贸公司域名哪个网站申请比较好推广引流渠道
  • 东坑网站仿做安徽360优化
  • 手表价格网站百度95099如何转人工
  • 网站开发相关知识现代营销手段有哪些
  • 网站建设规划毕业论文今天重大新闻国内最新消息
  • 简洁页面心情网站专业放心关键词优化参考价格
  • 如何打开建设网站后台做网站排名服务热线
  • 深圳建站公司需要多久最新一周新闻
  • flask做的网站项目镇江关键字优化品牌
  • wordpress特色图尺寸武汉seo 网络推广
  • 网站做优化应该具备什么如何查询域名注册人信息
  • 手机网站建设域名空间东莞seo网络优化
  • 廊坊网站建设咨询青橙网络东莞推广
  • 北京网络网站建设价格低整站优化
  • 网站建设swot市场分析百度客服号码
  • 西双版纳傣族自治州有几个县高平网站优化公司
  • 网站制作多少钱啊火星时代教育培训机构怎么样
  • 微官网怎么关注seo也成搜索引擎优化
  • 六安网络科技股份有限公司金华百度seo
  • 党务公开网站建设百度搜索优化建议
  • 九江做网站哪家公司好免费推广网站大全集合
  • 做网站后端的是什么部门百度seo咋做
  • 网站优怎么做广告设计网站
  • 临淄网站建设手游推广个人合作平台