java利用joup,imageio,base64来实现简历下载为html格式。
来源:互联网 发布:手机淘宝帐号管理在哪 编辑:程序博客网 时间:2024/06/02 21:39
1 需要的依赖包
<!--html操作工具--><dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.10.2</version></dependency>
2 远程图片转为base64编码
import sun.misc.BASE64Encoder;import javax.imageio.ImageIO;import java.awt.image.BufferedImage;import java.io.*;import java.net.MalformedURLException;import java.net.URL;public class ImagesToBase64{ public static String encodeImgageToBase64(URL imageUrl) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 ByteArrayOutputStream outputStream = null; try { BufferedImage bufferedImage = ImageIO.read(imageUrl); outputStream = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "jpg", outputStream); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // 对字节数组Base64编码 BASE64Encoder encoder = new BASE64Encoder(); return encoder.encode(outputStream.toByteArray());// 返回Base64编码过的字节数组字符串 }}
Base64 在CSS中的使用
.demoImg{background-image:url("data:image/jpg;base64,/9j/4QMZRXhpZgAASUkqAAgAAAAL....");}
Base64 在HTML中的使用
<img width="40" height="30" src="data:image/jpg;base64,/9j/4QMZRXhpZgAASUkqAAgAAAAL...." />
这是本人自己整合的请多指教
3 使用springmv来接收请求并打开浏览器下载框(不支持ajax请求)
/** * * 下载简历为html * author Miss Xiao * date 2017.04.25 20:21 */@RequestMapping("downloadFile")public void downloadFile(HttpServletResponse response, HttpServletRequest request){ //基础信息 RmResumeBasiVo rmResumeBasiVo = rmResumeBasiService.selectResumeBaseVoByType(super.getUseNo(),1); if (null!=rmResumeBasiVo) { Long resumeNo = rmResumeBasiVo.getResumeNo(); //意向行业 RmResumeIntentionVo rmResumeIntentionVo = rmResumeIntentionService.findOneVo(resumeNo); RmResumeJobVo jobVo = new RmResumeJobVo(); jobVo.setResumeNo(resumeNo); //工作经验集合 List<RmResumeJobVo> jobVos = rmResumeJobService.findListVo(jobVo); //教育背景 RmResumeEducationVo rmResumeEducationVo = rmResumeEducationService.findOneVo(resumeNo); Date date = new Date(); //打开下载框(谷歌无效) response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName="+date.getTime()+".html"); String url = request.getServletContext().getRealPath("/WEB-INF/pages/common/resume_template.html"); try { File file=new File(url); InputStream inputStream=new FileInputStream(file); //获取html Document doc = Jsoup.parse(inputStream,"UTF-8","http://www.oschina.net/"); //插入基础信息 doc.getElementById("realName").text(rmResumeBasiVo.getRealName()); doc.getElementById("headPortrait").attr("src", "data:image/jpg;base64,"+ImagesToBase64.encodeImgageToBase64(new URL(rmResumeBasiVo.getHeadPortrait()))); doc.getElementById("age").text("24"); doc.getElementById("nowLive").text(rmResumeBasiVo.getNowLive()); doc.getElementById("mobilePhone").text(rmResumeBasiVo.getMobilePhone()); doc.getElementById("email").text(rmResumeBasiVo.getEmail()); //插入意向行业信息 if (null!=rmResumeIntentionVo){ doc.getElementById("industry").text(rmResumeIntentionVo.getIndustry()); doc.getElementById("post").text(rmResumeIntentionVo.getPost()); doc.getElementById("region").text(rmResumeIntentionVo.getRegion()); doc.getElementById("salary").text(rmResumeIntentionVo.getSalary().toString()); String housing = rmResumeIntentionVo.getHousing()==0?"不提供住宿":"提供住宿"; String arrivalTime = rmResumeIntentionVo.getArrivalTime()==0?"随时上岗":"电话通知"; doc.getElementById("housing").text(housing); doc.getElementById("arrivalTime").text(arrivalTime); }else { doc.getElementById("job_intension").attr("hidden","hidden"); } //插入教育背景信息 if (null!=rmResumeEducationVo){ doc.getElementById("graduateTime").text(new SimpleDateFormat("yyyy.MM.dd").format(rmResumeEducationVo.getGraduateTime())); doc.getElementById("school").text(rmResumeEducationVo.getSchool()); String edu = "暂无"; if (rmResumeEducationVo.getEducation()=="0"){ edu = "大专以下"; }else if (rmResumeEducationVo.getEducation()=="1"){ edu = "大专"; }else if (rmResumeEducationVo.getEducation()=="2"){ edu = "本科"; }else if (rmResumeEducationVo.getEducation()=="3"){ edu = "硕士"; }else if (rmResumeEducationVo.getEducation()=="4"){ edu = "博士"; } doc.getElementById("education").text(edu); doc.getElementById("describes").text(rmResumeEducationVo.getDescribes()); }else { doc.getElementById("educational_background").attr("hidden","hidden"); } //插入工作经验信息 if (jobVos.size()>0){ for (RmResumeJobVo lis:jobVos){ String htm = " <dd class=\"clearfix resume_append_area\">\n" + " <div class=\"conTitle\">\n" + " 在岗时间:\n" + " <i contenteditable=\"true\" class=\"resume_time\">"+new SimpleDateFormat("yyyy.MM.dd").format(lis.getBeginTime())+"</i> 至\n" + " <i contenteditable=\"true\" class=\"resume_time\">"+new SimpleDateFormat("yyyy.MM.dd").format(lis.getEndTime())+"</i>\n" + " 公司名称:\n" + " <i contenteditable=\"true\" class=\"resume_unit\">"+lis.getEnterpriseName()+"</i>\n" + " 职位:\n" + " <i contenteditable=\"true\" class=\"resume_job\">"+lis.getIndustry()+"</i>\n" + " </div>\n" + " <div >\n" + " 工作描述: \n" + " <i class=\"resume_value\">"+lis.getJopDescribes()+"</i>\n" + " </div>\n" + " </dd>"; doc.getElementById("work_experiences").append(htm); } }else { doc.getElementById("work_experience").attr("hidden","hidden"); } ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(doc.html().toString().getBytes()); OutputStream os=response.getOutputStream(); byte[] b=new byte[1024]; int length; while((length=byteArrayInputStream.read(b))>0){ os.write(b,0,length); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }}
这是本人自己整合的请多指教
1 0
- java利用joup,imageio,base64来实现简历下载为html格式。
- Java实现Base64转码为迅雷等下载链接
- HTML 解析 joup
- joup 解析html文档
- JAVA 实现下载功能 保存为EXCEL格式
- 利用Java实现Base64加解密
- java文件下载格式为html和mht后覆盖原来的页签?
- 图片转化为Base64格式
- HTML内容转换为PDF格式------java
- RTF转换为HTML格式(java)
- 利用TCPDF将html页面转换为PDF格式
- wget下载jdk为html格式的解决方法
- 利用Java实现对文件的简易Base64编码
- 利用java自带的base64实现加密、解密
- 利用java自带的base64实现加密、解密
- 利用java自带的base64实现加密、解密
- 【转载】利用java自带的base64实现加密、解密
- 利用java自带的base64实现加密、解密
- java常见面试题
- 重读 阿里中供系前世今生:马云最神秘的子弟兵二
- Deep Learning 之 参数初始化
- hashmap原理及与hashtable区别
- EditText限制 只能输入0.00 -100保留两位小数
- java利用joup,imageio,base64来实现简历下载为html格式。
- DBCP和C3P0连接MySQL数据库
- CDN技术原理以及所用技术介绍
- 对jqueryValidate的使用心得 这个例子和bootstrap联合用的
- 数字格式化xx,xxx,xxx
- 关于ValueAnimator无作用
- FormData 的方法说明
- 看设计师大牛如何将用户体验与建站融会贯通
- 运行pythonp 提示:please select a valid interpreter