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

合肥建设学校官网网站郴州排名优化

合肥建设学校官网网站,郴州排名优化,高端网络工程师培训,网站开发费待摊年限导读#xff0c;此工具类中包含以下功能#xff1a; 1、文件后缀判断 2、图片后缀判断 3、word后缀判断 4、Excel后缀判断 5、PDF后缀判断 6、使用pdfbox将整个pdf转换成图片 7、pdf2word 8、word2PDF 9、向PDF指定页插入图片 10、PDF指定位置覆盖 11、删除文件夹及以下文件此工具类中包含以下功能 1、文件后缀判断 2、图片后缀判断 3、word后缀判断 4、Excel后缀判断 5、PDF后缀判断 6、使用pdfbox将整个pdf转换成图片 7、pdf2word 8、word2PDF 9、向PDF指定页插入图片 10、PDF指定位置覆盖 11、删除文件夹及以下文件可能出现删不全的情况 12、zip文件返回 13、打压缩包 代码 package cn.org.enst.report.office.utils.processdocument;import cn.org.enst.common.exception.DbptException; import cn.org.enst.common.utils.StringUtils; import cn.org.enst.common.utils.file.FileUtils; import com.baomidou.mybatisplus.core.toolkit.ArrayUtils; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; import com.jacob.com.Variant; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageTree; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; import org.apache.pdfbox.rendering.PDFRenderer; import org.apache.pdfbox.text.PDFTextStripper;import javax.imageio.ImageIO; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.*; import java.util.List; import java.util.zip.CRC32; import java.util.zip.CheckedOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream;public class FileTypeUtils {/*** 文件后缀判断*/public static boolean verificationFile(String originFileName) {// 后缀String extName originFileName.substring(originFileName.lastIndexOf(.) 1);// 判断是不是图片、文档、excel、pdf、压缩包等文件后缀if (extName.matches((tif|gif|png|jpg|jpeg|bmp|doc|docx|pdf|xls|xlsx|rar|zip))) {return true;}// 文件格式错误return false;}/*** 图片后缀判断*/public static boolean verificationImage(String originFileName) {// 后缀String extName originFileName.substring(originFileName.lastIndexOf(.) 1);// 判断是不是图片后缀if (extName.matches((png|jpg|jpeg))) {return true;}// 文件格式错误return false;}/*** word后缀判断*/public static boolean verificationWord(String originFileName) {// 后缀String extName originFileName.substring(originFileName.lastIndexOf(.) 1);// 判断是不是图片后缀if (extName.matches((doc|docx))) {return true;}// 文件格式错误return false;}/*** Excel后缀判断*/public static boolean verificationExcel(String originFileName) {// 后缀String extName originFileName.substring(originFileName.lastIndexOf(.) 1);// 判断是不是图片后缀if (extName.matches((xls|xlsx))) {return true;}// 文件格式错误return false;}/*** PDF后缀判断*/public static boolean verificationPDF(String originFileName) {// 后缀String extName originFileName.substring(originFileName.lastIndexOf(.) 1);// 判断是不是图片后缀if (extName.matches((pdf))) {return true;}// 文件格式错误return false;}/*** 使用pdfbox将整个pdf转换成图片** param fileAddress 文件地址 如:C:\\Users\\user\\Desktop\\test* param filename PDF文件名不带后缀名* param type 图片类型 png 和jpg* param pathList 图片输出位置*/public static void pdf2png(String fileAddress, String filename, String type, ListString pathList) { // long startTime System.currentTimeMillis();// 将文件地址和文件名拼接成路径 注意线上环境不能使用\\拼接File file new File(fileAddress \\ filename .pdf);try {// 写入文件PDDocument doc PDDocument.load(file);PDFRenderer renderer new PDFRenderer(doc);int pageCount doc.getNumberOfPages();for (int i 0; i pageCount; i) {// dpi为144越高越清晰转换越慢BufferedImage image renderer.renderImageWithDPI(i, 144); // Windows native DPI// 将图片写出到该路径下pathList.add(fileAddress \\ filename _ (i 1) . type);ImageIO.write(image, type, new File(fileAddress \\ filename _ (i 1) . type));}long endTime System.currentTimeMillis(); // System.out.println(共耗时 ((endTime - startTime) / 1000.0) 秒); //转化用时} catch (IOException e) {e.printStackTrace();}}/*** param source 要转换的word文件* param target 要转换成为的pdf文件*/public static void pdf2word(String source, String target) {try {//将pdf加载到对象中去PDDocument doc PDDocument.load(new File(source));//得到pdf的页数int pagenumber doc.getNumberOfPages();//设置转换后的名字 // pdfFile pdfFile.substring(0, pdfFile.lastIndexOf(.)); // String fileName pdfFile .doc;File file new File(target);if (!file.exists()) {file.createNewFile();}FileOutputStream fos new FileOutputStream(target);//设置输出字符集为UTF-8 因此该word应该使用UTF-8格式打开 如果你出现乱码那么你可以自己修改一下这里的格式Writer writer new OutputStreamWriter(fos, UTF-8);PDFTextStripper stripper new PDFTextStripper();stripper.setSortByPosition(true);// 排序stripper.setStartPage(1);// 设置转换的开始页stripper.setEndPage(pagenumber);// 设置转换的结束页stripper.writeText(doc, writer);writer.close();doc.close();System.out.println(pdf转换word成功);} catch (IOException e) {e.printStackTrace();}}/*** \** param sourceUrl 要转换的word文件* param targetUrl 要转换成为的pdf文件*/public static void word2PDF(String sourceUrl, String targetUrl) {int wdFormatPDF 17;// PDF 格式ActiveXComponent app null;Dispatch doc null;try {app new ActiveXComponent(Word.Application);app.setProperty(Visible, new Variant(false));Dispatch docs app.getProperty(Documents).toDispatch();//转换前的文件路径String startFile sourceUrl;//转换后的文件路劲String overFile targetUrl;doc Dispatch.call(docs, Open, startFile).toDispatch();File tofile new File(overFile);if (tofile.exists()) {tofile.delete();}Dispatch.call(doc, SaveAs, overFile, wdFormatPDF);} catch (Exception e) {System.out.println(e.getMessage());} finally {Dispatch.call(doc, Close, false);if (app ! null)app.invoke(Quit, new Variant[]{});}//结束后关闭进程ComThread.Release();}/*** param tempContentPathString pdf文件路径* param tempSignPathList jpg图片路径集合* param i 图片放在pdf第几页(下标从0开始)* param pdfUrl pdf输出位置*/public static void PDFMergeJPGIndex(String tempContentPathString, ListString tempSignPathList, int i, String pdfUrl) throws Exception {new File(pdfUrl.substring(0,pdfUrl.lastIndexOf(File.separator))).mkdirs();//D:\\temp\\电力行标-报告.pdf//打开PDF文件PDDocument doc PDDocument.load(new FileInputStream(tempContentPathString));//获取所有页PDPageTree pages doc.getDocumentCatalog().getPages();//获取第一页PDPage pdPage0 pages.get(0);//获取第一页纸张信息PDRectangle mediaBox pdPage0.getMediaBox();float lowerLeftX mediaBox.getLowerLeftX();float lowerLeftY mediaBox.getLowerLeftY();float width mediaBox.getWidth();float height mediaBox.getHeight();//有几张照片循环几次for (String s : tempSignPathList) {// 根据第一个纸张信息创建一张空白页PDPage pageOne new PDPage(mediaBox);//获取照片PDImageXObject pdImage PDImageXObject.createFromFile(s, doc);// 获取此页内容流PDPageContentStream contentStream new PDPageContentStream(doc, pageOne, PDPageContentStream.AppendMode.APPEND, true);//照片写入contentStream.drawImage(pdImage, lowerLeftX, lowerLeftY, width, height);// 关闭内容流contentStream.close();pages.insertBefore(pageOne, pages.get(i tempSignPathList.indexOf(s)));}doc.save(new File(pdfUrl));doc.close();}/*** pdf遮盖不通用* pdfUrl pdf路径* type 文档类型区分不同文档类型区分覆盖位置*/public static void PDFFill(String pdfUrl, int type) throws Exception {//初始化数据float x 0; // 替换为您需要遮盖的区域的X轴坐标float y 0; // 替换为您需要遮盖的区域的Y轴坐标float w 0; // 替换为遮盖区域的宽度float h 0; // 替换为遮盖区域的高度//打开PDF文件PDDocument doc PDDocument.load(new FileInputStream(pdfUrl));PDPageTree pages doc.getDocumentCatalog().getPages();PDPage pdPage0 pages.get(0);PDRectangle mediaBox pdPage0.getMediaBox();// 创建内容流将第一页的内容绘制到新页上如果需要删除/遮盖某个区域请在此内容流中进行相应操作PDPageContentStream contentStream new PDPageContentStream(doc, pdPage0, PDPageContentStream.AppendMode.APPEND, true);// 设置填充颜色这里设置为白色您可以根据需要更改颜色contentStream.setNonStrokingColor(255, 255, 255); // 白色if (0 type) {//方案、测评表x 0f; // 替换为您需要遮盖的区域的X轴坐标y 200f; // 替换为您需要遮盖的区域的Y轴坐标w 500f; // 替换为遮盖区域的宽度h 300f; // 替换为遮盖区域的高度}else if(1 type){//调查表x 0f; // 替换为您需要遮盖的区域的X轴坐标y 145f; // 替换为您需要遮盖的区域的Y轴坐标w 600f; // 替换为遮盖区域的宽度h 150f; // 替换为遮盖区域的高度}// 绘制矩形遮盖指定区域contentStream.addRect(x, y, w, h);contentStream.fill();// 结束内容流contentStream.close();// 保存修改后的文档doc.save(pdfUrl);// 关闭文档doc.close();}/*** 删除文件夹及以下的文件*/public static void deleteFolder(File folder) {File[] files folder.listFiles();if (files ! null) {for (File file : files) {if (file.isDirectory()) {deleteFolder(file);} else {file.delete();}}}folder.delete();}/*** 文件返回*/public static void downloadZip(HttpServletRequest request, HttpServletResponse response, String zipPath) {//截取文件名String fileName zipPath.substring(zipPath.lastIndexOf(File.separator) 1);try {response.setCharacterEncoding(utf-8);// 导出使用application/octet-stream更标准response.setContentType(application/octet-stream);response.setHeader(Content-Disposition,attachment;filename FileUtils.setFileDownloadHeader(request, fileName));FileUtils.writeBytes(zipPath, response.getOutputStream());} catch (IOException e) {e.printStackTrace();throw new DbptException(StringUtils.format(导出文件 ({}) , fileName, e));}}/*** 打压缩包*/public static void compress(String fromPath, String toPath) throws Exception {File fromFile new File(fromPath);File toFile new File(toPath);if (!fromFile.exists()) {throw new DbptException(fromPath 不存在);}try (FileOutputStream outputStream new FileOutputStream(toFile); CheckedOutputStream checkedOutputStream new CheckedOutputStream(outputStream, new CRC32()); ZipOutputStream zipOutputStream new ZipOutputStream(checkedOutputStream)) {//区分重载方法无实际意义String baseDir ;//进行一次循环为了去除最外层文件夹File[] files fromFile.listFiles();for (File file : files) {compress(file, zipOutputStream, baseDir);}}}private static void compress(File file, ZipOutputStream zipOut, String baseDir) throws IOException {if (file.isDirectory()) {compressDirectory(file, zipOut, baseDir);} else {compressFile(file, zipOut, baseDir);}}private static void compressFile(File file, ZipOutputStream zipOut, String baseDir) throws IOException {if (!file.exists()) {return;}try (BufferedInputStream bis new BufferedInputStream(new FileInputStream(file))) {ZipEntry entry new ZipEntry(baseDir file.getName());zipOut.putNextEntry(entry);int count;byte[] data new byte[1024];while ((count bis.read(data, 0, 1024)) ! -1) {zipOut.write(data, 0, count);}}}private static void compressDirectory(File dir, ZipOutputStream zipOut, String baseDir) throws IOException {File[] files dir.listFiles();if (files ! null ArrayUtils.isNotEmpty(files)) {for (File file : files) {compress(file, zipOut, baseDir dir.getName() File.separator);}}} }
http://www.pierceye.com/news/115684/

相关文章:

  • 网站运营与数据分析网站开发学习什么
  • 上海网站备案在哪里查询网站建设哪家稳妥
  • 建设网站做什么赚钱网站制作.
  • 小企业公司网站怎么建做网站英文编辑有前途吗
  • 优化图片传网站wordpress背景图片
  • 网站服务器哪家好些外包做网站不付尾款
  • 建站系统wordpress下载哪个公司的微信商城系统
  • 网站建设app开发合同深圳企业网站制作设计方案
  • 免费网站整站模板下载寻找做网站
  • 做此广告的网站做家纺的网站
  • 湖南畅想网站建设个人网站建设基本定位
  • 建站公司外包钓鱼网站怎么做
  • 个人网站logo需要备案吗鑫灵锐做网站多少钱
  • .xyz做网站怎么样网站产品预算
  • 建网站先要申请网址吗做网站给文件不侵权
  • 一元夺宝网站建设Wordpress 普通图片裁剪
  • 网站推广都有哪些自己有网站怎么优化
  • 宠物交易网站模板更改wordpress后台登录地址
  • 有电脑网站怎样建手机正规网络游戏平台
  • 网站抓取QQ获取系统cms监控手机客户端
  • 郑州网站推广价格优礼品网站模板
  • 百度指数不高的网站怎么优化网站图片类型
  • 北京专业做网站怎么样app软件开发摄像头
  • 网站建设导向erp系统软件免费版
  • 手表网站网站开发毕业设计文献综述
  • 台州网站制作维护关于微网站策划ppt怎么做
  • 网站建设中期目标开发app找那个公司
  • 跨境自建站模板网站内容和功能清单
  • 平面设计找素材的网站电子商务网站建设的步骤一般为(
  • 一个服务器可以备案几个网站凡科门店通怎么样