| | |
| | | package com.ruoyi.web.controller.archive; |
| | | |
| | | import com.aspose.cells.PdfCompliance; |
| | | import com.aspose.words.License; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.itextpdf.text.*; |
| | | import com.itextpdf.text.Font; |
| | | import com.itextpdf.text.pdf.BaseFont; |
| | | import com.itextpdf.text.pdf.PdfPCell; |
| | | import com.itextpdf.text.pdf.PdfPTable; |
| | | import com.itextpdf.text.pdf.PdfWriter; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelExp; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.utils.poi.ExcelUtilManySheet; |
| | | import com.ruoyi.common.utils.poi.ExcelUtilManySheetSecond; |
| | | import com.ruoyi.common.utils.poi.*; |
| | | import com.ruoyi.domain.ArchiveRecords; |
| | | import com.ruoyi.domain.DocumentMaterials; |
| | | import com.ruoyi.domain.vo.*; |
| | | import com.ruoyi.framework.web.domain.server.Sys; |
| | | import com.ruoyi.service.IArchiveRecordsService; |
| | | import com.ruoyi.service.IDocumentMaterialsService; |
| | | import com.ruoyi.service.impl.BarcodeService; |
| | | import com.ruoyi.service.impl.pdfGenerateService; |
| | | import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; |
| | | import org.apache.poi.hssf.usermodel.HSSFCell; |
| | | import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellUtil; |
| | | import org.apache.poi.xssf.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
| | | import org.springframework.core.io.support.ResourcePatternResolver; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.lang.reflect.Field; |
| | | import java.net.URLEncoder; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.stream.Collectors; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipFile; |
| | | import java.util.zip.ZipInputStream; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | | import static org.apache.poi.hssf.usermodel.HSSFCell.*; |
| | | // 导入ByteArrayOutputStream用于临时存储PDF数据 |
| | | import java.io.ByteArrayOutputStream; |
| | | |
| | | @RestController |
| | | @RequestMapping("/system/archiveAllExport") |
| | | public class archiveAllExportController { |
| | | // 存储当天导出序号的Map,键为日期(yyyyMMdd),值为当前序号 |
| | | private static Map<String, Integer> dailySequenceMap = new ConcurrentHashMap<>(); |
| | | |
| | | @Autowired |
| | | private pdfGenerateService pdfGenerateService; |
| | |
| | | @Autowired |
| | | private IArchiveRecordsService iArchiveRecordsService; |
| | | |
| | | // 用于生成当天导出序号的方法 |
| | | private String generateDailySequence(String date) { |
| | | // 使用synchronized确保线程安全 |
| | | synchronized (dailySequenceMap) { |
| | | // 获取当前日期的序号,如果不存在则初始化为0 |
| | | int sequence = dailySequenceMap.getOrDefault(date, 0); |
| | | // 序号递增 |
| | | sequence++; |
| | | // 更新Map中的序号 |
| | | dailySequenceMap.put(date, sequence); |
| | | // 格式化为三位字符串,不足三位补前导零 |
| | | return String.format("%03d", sequence); |
| | | } |
| | | } |
| | | |
| | | public boolean getLicense() { |
| | | boolean result = false; |
| | | try { |
| | | InputStream is = null; |
| | | |
| | | ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); |
| | | org.springframework.core.io.Resource[] resources = resolver.getResources("classpath:words.xml"); |
| | | is = resources[0].getInputStream(); |
| | | // ��Ŀ��lincense.xml��·�� |
| | | License aposeLic = new License(); |
| | | aposeLic.setLicense(is); |
| | | result = true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public boolean getLicenseExcel() { |
| | | boolean result = false; |
| | | InputStream is = null; |
| | | try { |
| | | ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); |
| | | org.springframework.core.io.Resource[] resources = resolver.getResources("classpath:license.xml"); |
| | | is = resources[0].getInputStream(); |
| | | com.aspose.cells.License aposeLic = new com.aspose.cells.License(); |
| | | aposeLic.setLicense(is); |
| | | result = true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if (is != null) { |
| | | try { |
| | | is.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 将Excel指定子sheet转换为PDF并下载 |
| | | * @param response 响应对象 |
| | | * @param excelPath Excel文件路径 |
| | | * @param sheetName 子sheet名称 |
| | | * @throws Exception 异常信息 |
| | | */ |
| | | @PostMapping("/exportSheetToPdf") |
| | | public void exportSheetToPdf(HttpServletResponse response, String excelPath, String sheetName) throws Exception { |
| | | // 设置响应头 |
| | | response.setContentType(MediaType.APPLICATION_PDF_VALUE); |
| | | response.setHeader("Content-Disposition", "attachment; filename=sheet.pdf"); |
| | | |
| | | try { |
| | | // 使用Aspose.Cells读取Excel文件 |
| | | com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(excelPath); |
| | | |
| | | // 获取指定名称的子sheet |
| | | com.aspose.cells.Worksheet sheet = wb.getWorksheets().get(sheetName); |
| | | |
| | | // 如果需要获取索引方式的子sheet,可以使用以下代码 |
| | | // com.aspose.cells.Worksheet sheet = wb.getWorksheets().get(0); // 获取第一个sheet |
| | | |
| | | // 创建一个新的Workbook,只包含指定的sheet |
| | | com.aspose.cells.Workbook newWorkbook = new com.aspose.cells.Workbook(); |
| | | newWorkbook.getWorksheets().clear(); |
| | | newWorkbook.getWorksheets().addCopy(sheet.getName()); |
| | | |
| | | // 将Excel转换为PDF字节数组 |
| | | java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); |
| | | newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF); |
| | | byte[] pdfBytes = baos.toByteArray(); |
| | | |
| | | // 将PDF输出到响应流 |
| | | try (ServletOutputStream os = response.getOutputStream()) { |
| | | os.write(pdfBytes); |
| | | os.flush(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将Excel所有子sheet转换为PDF并打包下载 |
| | | * @param response 响应对象 |
| | | * @param excelPath Excel文件路径 |
| | | * @throws Exception 异常信息 |
| | | */ |
| | | @PostMapping("/exportAllSheetsToPdf") |
| | | public void exportAllSheetsToPdf(HttpServletResponse response, String excelPath) throws Exception { |
| | | // 设置响应头 |
| | | response.setContentType("application/zip"); |
| | | response.setHeader("Content-Disposition", "attachment; filename=all_sheets.zip"); |
| | | |
| | | try (ServletOutputStream os = response.getOutputStream(); |
| | | ZipOutputStream zos = new ZipOutputStream(os)) { |
| | | |
| | | // 使用Aspose.Cells读取Excel文件 |
| | | com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(excelPath); |
| | | |
| | | // 获取所有sheet |
| | | com.aspose.cells.WorksheetCollection sheets = wb.getWorksheets(); |
| | | |
| | | // 遍历所有sheet |
| | | for (int i = 0; i < sheets.getCount(); i++) { |
| | | com.aspose.cells.Worksheet sheet = sheets.get(i); |
| | | String sheetName = sheet.getName(); |
| | | |
| | | // 创建一个新的Workbook,只包含当前sheet |
| | | com.aspose.cells.Workbook newWorkbook = new com.aspose.cells.Workbook(); |
| | | newWorkbook.getWorksheets().clear(); |
| | | newWorkbook.getWorksheets().addCopy(sheet.getName()); |
| | | |
| | | // 创建临时字节输出流 |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | |
| | | // 将新的Workbook保存为PDF到临时流 |
| | | newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF); |
| | | byte[] pdfBytes = baos.toByteArray(); |
| | | |
| | | // 获取PDF总页数 |
| | | |
| | | // 将PDF添加到ZIP文件 |
| | | ZipEntry entry = new ZipEntry(sheetName + ".pdf"); |
| | | zos.putNextEntry(entry); |
| | | zos.write(pdfBytes); |
| | | zos.closeEntry(); |
| | | |
| | | System.out.println("Excel子sheet \"" + sheetName + "\" 转换为PDF成功"); |
| | | } |
| | | |
| | | System.out.println("Excel所有子sheet转换为PDF并打包成功"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | } |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) throws IOException |
| | | { |
| | | |
| | | |
| | | if (!getLicense()) { |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | |
| | | // 获取 Word 模板所在路径 |
| | | String filepath = "09-备考表.docx"; |
| | | // 通过 XWPFTemplate 编译文件并渲染数据到模板中 |
| | | XWPFTemplate template = XWPFTemplate.compile(filepath).render( |
| | | new HashMap<String, Object>(){{ |
| | | put("pages", 67); |
| | | |
| | | }}); |
| | | |
| | | String renderedDocPath = "rendered_output.docx"; |
| | | File renderedFile = new File(renderedDocPath); |
| | | |
| | | |
| | | |
| | | try { |
| | | // 将完成数据渲染的文档写出 |
| | | template.writeAndClose(new FileOutputStream(renderedFile)); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | File file = new File("test1.pdf"); |
| | | FileOutputStream os = new FileOutputStream(file); |
| | | com.aspose.words.Document doc = new com.aspose.words.Document("rendered_output.docx"); |
| | | |
| | | doc.save(os, com.aspose.words.SaveFormat.PDF);//ȫ��֧��DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF �ת�� |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | if (!getLicenseExcel()) { |
| | | System.out.println("授权失败"); |
| | | return ; |
| | | } |
| | | String inpath= "案卷封面.xls"; |
| | | long old = System.currentTimeMillis(); |
| | | |
| | | // 设置响应头 |
| | | response.setContentType("application/pdf"); |
| | | response.setHeader("Content-Disposition", "attachment; filename=import_template.pdf"); |
| | | |
| | | try { |
| | | // 读取Excel文件 |
| | | com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(inpath); |
| | | |
| | | // 获取需要导出的sheet(索引从0开始) |
| | | int targetSheetIndex = 1; |
| | | com.aspose.cells.Worksheet targetSheet = wb.getWorksheets().get(targetSheetIndex); |
| | | targetSheet.autoFitRows(true); |
| | | System.out.println("当前sheet名称:" + targetSheet.getName()); |
| | | System.out.println("当前sheet索引:" + targetSheet.getIndex()); |
| | | |
| | | // 隐藏所有其他工作表 |
| | | for (int i = 0; i < wb.getWorksheets().getCount(); i++) { |
| | | if (i != targetSheetIndex) { |
| | | wb.getWorksheets().get(i).setVisible(false); |
| | | } |
| | | } |
| | | |
| | | // 设置活动工作表为目标工作表 |
| | | wb.getWorksheets().setActiveSheetIndex(targetSheetIndex); |
| | | |
| | | // 创建PDF保存选项 |
| | | com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions(); |
| | | |
| | | // 设置页面类型为A4 |
| | | |
| | | |
| | | // 确保所有列在一页上 |
| | | pdfSaveOptions.setAllColumnsInOnePagePerSheet(true); |
| | | |
| | | // 设置打印页面类型为默认 |
| | | pdfSaveOptions.setCompliance(PdfCompliance.PDF_A_1_B); // 设置 PDF 兼容性标准 |
| | | |
| | | // 直接将原始工作簿保存为PDF(只包含可见的工作表) |
| | | wb.save(response.getOutputStream(), pdfSaveOptions); |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // 打印详细错误信息 |
| | | System.err.println("转换失败:" + e.getMessage()); |
| | | e.printStackTrace(System.err); |
| | | |
| | | // 返回错误信息 |
| | | response.reset(); |
| | | response.setContentType("text/plain;charset=utf-8"); |
| | | response.getWriter().write("导出失败:" + e.getMessage()); |
| | | response.getWriter().flush(); |
| | | } |
| | | |
| | | //导出卷面封面代码 |
| | | |
| | | ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(55L); |
| | |
| | | @PostMapping("/exportChooseArchive/{ids}") |
| | | public void exportChooseArchive(HttpServletResponse response, @PathVariable Long[] ids)throws Exception |
| | | { |
| | | //计算文件的大小 |
| | | Double siz = 0.0; |
| | | for(int i = 0; i < ids.length; i++) { |
| | | |
| | | // 获取文件的保存位置,读取数据库, |
| | | DocumentMaterials documentMaterials = new DocumentMaterials(); |
| | | documentMaterials.setRecordId(ids[i]); |
| | | List<DocumentMaterialsVoLarge> docs = documentMaterialsService.selectDocumentMaterialsAllByRecordId(ids[i]); |
| | | System.out.println(docs.size()+"----009"); |
| | | for (DocumentMaterialsVoLarge dc : docs) { |
| | | if(dc!=null) |
| | | siz += dc.getFileSize()!=null?dc.getFileSize():0; |
| | | } |
| | | } |
| | | System.out.println(siz/1000); |
| | | //判断是否大于4G,是的话,直接抛出异常 |
| | | long maxSize = 4L * 1024 * 1024 * 1024; // 4GB in bytes |
| | | if (siz > maxSize) { |
| | | throw new RuntimeException("文件总大小超过4GB,无法导出"); |
| | | } |
| | | System.out.println("092939932"); |
| | | String zipFileName ="test" +".zip"; |
| | | //生成压缩包存储地址(最后会删掉) |
| | |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); |
| | | String formattedDate = date.format(formatter); |
| | | System.out.println(formattedDate); |
| | | String fna = "GH"+20250908+"/"; |
| | | |
| | | // 生成当天导出序号 |
| | | String sequence = generateDailySequence(formattedDate); |
| | | String fna = "GH" + formattedDate + sequence + "/"; |
| | | zos.putNextEntry(new ZipEntry(fna)); |
| | | |
| | | |
| | |
| | | archiveRecords.setIds(ids); |
| | | List<ArchiveRecords> lis = iArchiveRecordsService.selectArchiveRecordsList(archiveRecords); |
| | | //案卷目录导出 |
| | | ZipEntry entry = new ZipEntry("案卷目录" + ".xls"); |
| | | ZipEntry entry = new ZipEntry(fna + "案卷目录" + ".xls"); |
| | | ExcelUtil<ArchiveRecords> util = new ExcelUtil<ArchiveRecords>(ArchiveRecords.class); |
| | | |
| | | zos.putNextEntry(entry); |
| | |
| | | //移交清单 |
| | | List<ArchiveRecordSmall> lrs = iArchiveRecordsService.findByIds(archiveRecords); |
| | | System.out.println(lrs); |
| | | ZipEntry entry1 = new ZipEntry("移交清单" + ".xls"); |
| | | System.out.println("99999999990000"); |
| | | ZipEntry entry1 = new ZipEntry(fna + "移交清单" + ".xls"); |
| | | ExcelUtil<ArchiveRecordSmall> util1 = new ExcelUtil<ArchiveRecordSmall>(ArchiveRecordSmall.class); |
| | | |
| | | |
| | | |
| | | ExcelExp e6 = new ExcelExp("移交清单","GH" + formattedDate + sequence, lrs, ArchiveRecordSmall.class); |
| | | // ExcelExp e4 = new ExcelExp("案卷封面", arsi, recordId1, imgr1,sedcode, ArchiveInfoVo.class); |
| | | List<ExcelExp> mysheet6 = new ArrayList<ExcelExp>(); |
| | | mysheet6.add(e6); |
| | | // mysheet1.add(e4); |
| | | ByteOutputStream bos6 = new ByteOutputStream(); |
| | | ExcelUtilManySheetThird<List<ExcelExp>> util6 = new ExcelUtilManySheetThird<List<ExcelExp>>(mysheet6); |
| | | |
| | | util6.exportExcelManySheet(bos6, mysheet6); |
| | | |
| | | // System.out.println(bos2); |
| | | zos.putNextEntry(entry1); |
| | | ByteOutputStream bos1 = new ByteOutputStream(); |
| | | util1.byteOutputStreamExcel(bos1, lrs,"移交清单", ""); |
| | | bos1.writeTo(zos); |
| | | // ByteOutputStream bos1 = new ByteOutputStream(); |
| | | // util6.byteOutputStreamExcel(bos1, lrs,"移交清单", ""); |
| | | bos6.writeTo(zos); |
| | | |
| | | |
| | | |
| | | |
| | | System.out.println(ids.length); |
| | | System.out.println("------------------"); |
| | | |
| | | for(int i = 0; i < ids.length; i++) { |
| | | System.out.println(ids[i]); |
| | | |
| | | // 获取文件的保存位置,读取数据库, |
| | | DocumentMaterials documentMaterials = new DocumentMaterials(); |
| | | documentMaterials.setRecordId(ids[i]); |
| | | List<DocumentMaterialsVoLarge> docs = documentMaterialsService.selectDocumentMaterialsAllByRecordId(ids[i]); |
| | | System.out.println(docs.size()+"----009"); |
| | | System.out.println(docs.size()+"----7777"); |
| | | |
| | | |
| | | //.selectDocumentMaterialsList(documentMaterials); |
| | | List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(ids[i].toString()); |
| | | ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(ids[i]); |
| | | |
| | | System.out.println(aIV.getInquiryNumber()); |
| | | System.out.println(aIV.getRecordId()); |
| | | String adir = aIV.getInquiryNumber() + " " + aIV.getRecordId(); |
| | | System.out.println(adir); |
| | | System.out.println(fna+adir); |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/")); |
| | | |
| | |
| | | } |
| | | //添加07 的pdf |
| | | //pdf目录封面 |
| | | String pdfPathF = "07-卷面封面.pdf"; |
| | | pdfGenerateService.generatePdf(pdfPathF, ids[i]); |
| | | // 2. 压缩PDF到ZIP文件 |
| | | // 添加PDF文件到ZIP |
| | | ZipEntry zipEntry2 = new ZipEntry(fna + adir +"/"+pdfPathF); |
| | | zos.putNextEntry(zipEntry2); |
| | | // String pdfPathF = "07-案卷封面.pdf"; |
| | | // pdfGenerateService.generatePdf(pdfPathF, ids[i]); |
| | | // // 2. 压缩PDF到ZIP文件 |
| | | // // 添加PDF文件到ZIP |
| | | // ZipEntry zipEntry2 = new ZipEntry(fna + adir +"/"+pdfPathF); |
| | | // zos.putNextEntry(zipEntry2); |
| | | // |
| | | // // 读取PDF文件内容并写入ZIP |
| | | // try (FileInputStream fis = new FileInputStream(pdfPathF)) { |
| | | // byte[] buffer = new byte[1024]; |
| | | // int len; |
| | | // while ((len = fis.read(buffer)) > 0) { |
| | | // zos.write(buffer, 0, len); |
| | | // } |
| | | // } |
| | | |
| | | // 读取PDF文件内容并写入ZIP |
| | | try (FileInputStream fis = new FileInputStream(pdfPathF)) { |
| | | byte[] buffer = new byte[1024]; |
| | | int len; |
| | | while ((len = fis.read(buffer)) > 0) { |
| | | zos.write(buffer, 0, len); |
| | | |
| | | |
| | | |
| | | |
| | | //09-备考表.pdf |
| | | |
| | | |
| | | |
| | | |
| | | // pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), ids[i]); |
| | | // // 2. 压缩PDF到ZIP文件 |
| | | // // 添加PDF文件到ZIP |
| | | // ZipEntry zipEntry4 = new ZipEntry(fna + adir +"/"+pdf09Path); |
| | | // zos.putNextEntry(zipEntry4); |
| | | // |
| | | // // 读取PDF文件内容并写入ZIP |
| | | // try (FileInputStream fis = new FileInputStream(pdf09Path)) { |
| | | // byte[] buffer = new byte[1024]; |
| | | // int len; |
| | | // while ((len = fis.read(buffer)) > 0) { |
| | | // zos.write(buffer, 0, len); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | //09-备考表.pdf |
| | | String pdf09Path = "09-备考表.pdf"; |
| | | // pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), id); |
| | | //拿到相关数据 |
| | | List<DocumentMaterialFileStyle> dmfs = documentMaterialsService.findFileStyleInfo(Math.toIntExact(ids[i])); |
| | | |
| | | LocalDate currentDate = LocalDate.now(); |
| | | |
| | | |
| | | String cdt = currentDate.getYear()+"年"+currentDate.getMonthValue()+"月"+currentDate.getDayOfMonth()+"日"; |
| | | |
| | | HashMap<String, Object> hs = new HashMap<String, Object>(); |
| | | int allPages = 0; |
| | | int texPages = 0; |
| | | int picPages = 0; |
| | | int patPages = 0; |
| | | if(!dmfs.isEmpty()) |
| | | { |
| | | for(DocumentMaterialFileStyle documentMaterialFileStyle:dmfs) |
| | | { |
| | | if(documentMaterialFileStyle.getFileStyle().equals("文字材料")) |
| | | texPages = documentMaterialFileStyle.getCnt(); |
| | | if(documentMaterialFileStyle.getFileStyle().equals("图样材料")) |
| | | patPages = documentMaterialFileStyle.getCnt(); |
| | | if(documentMaterialFileStyle.getFileStyle().equals("照片材料")) |
| | | picPages = documentMaterialFileStyle.getCnt(); |
| | | } |
| | | } |
| | | allPages = texPages + picPages + patPages; |
| | | hs.put("pages", allPages); |
| | | hs.put("patPages", patPages); |
| | | hs.put("picPages", picPages); |
| | | hs.put("texPages", texPages); |
| | | hs.put("volumeNumber", aIV.getRecordId()); |
| | | hs.put("time", cdt); |
| | | |
| | | if (!getLicense()) { |
| | | System.out.println("没有相关证书!"); |
| | | } |
| | | |
| | | |
| | | try { |
| | | |
| | | // 获取 Word 模板所在路径 |
| | | String filepath = "09-备考表.docx"; |
| | | // 通过 XWPFTemplate 编译文件并渲染数据到模板中 |
| | | XWPFTemplate template = XWPFTemplate.compile(filepath).render(hs |
| | | ); |
| | | |
| | | String renderedDocPath = "rendered_output.docx"; |
| | | File renderedFile = new File(renderedDocPath); |
| | | try { |
| | | // 将完成数据渲染的文档写出 |
| | | template.writeAndClose(new FileOutputStream(renderedFile)); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | com.aspose.words.Document doc = new com.aspose.words.Document("rendered_output.docx"); |
| | | // 创建临时字节输出流 |
| | | ByteArrayOutputStream baobk = new ByteArrayOutputStream(); |
| | | // 将Word文档转换为PDF字节数组 |
| | | doc.save(baobk, com.aspose.words.SaveFormat.PDF);//ȫ��֧��DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF �ת�� |
| | | ZipEntry zipEntry4 = new ZipEntry(fna + adir +"/"+pdf09Path); |
| | | zos.putNextEntry(zipEntry4); |
| | | baobk.writeTo(zos); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | |
| | | // com.aspose.words.Document doc = new com.aspose.words.Document("09-备考表.docx"); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //excel 卷内封面导出zip |
| | | ZipEntry entryiv = new ZipEntry(fna + adir +"/"+"案卷封面" + ".xls"); |
| | | |
| | | List<ArchiveInfoVo> arsi = new ArrayList<>(); |
| | | arsi.add(aIV); |
| | | |
| | | String recordId1 = aIV.getRecordId(); |
| | | byte[] imgr1 = barcodeService.generateBarcodeImage(recordId1); |
| | | byte[] sedcode = pdfGenerateService.createQrCodeN(recordId1, 30, 30); |
| | | ExcelExp e3 = new ExcelExp("案卷封面数据",arsi, ArchiveInfoVo.class); |
| | | ExcelExp e4 = new ExcelExp("案卷封面", arsi, recordId1, imgr1,sedcode, ArchiveInfoVo.class); |
| | | List<ExcelExp> mysheet1 = new ArrayList<ExcelExp>(); |
| | | mysheet1.add(e3); |
| | | mysheet1.add(e4); |
| | | ByteOutputStream bos2 = new ByteOutputStream(); |
| | | ExcelUtilManySheetSecond<List<ExcelExp>> util3 = new ExcelUtilManySheetSecond<List<ExcelExp>>(mysheet1); |
| | | |
| | | util3.exportExcelManySheet(bos2, mysheet1); |
| | | |
| | | // System.out.println(bos2); |
| | | zos.putNextEntry(entryiv); |
| | | |
| | | |
| | | bos2.writeTo(zos); |
| | | |
| | | |
| | | //pdf目录封面 |
| | | String pdfPathF = "07-案卷封面.pdf"; |
| | | // pdfGenerateService.generatePdf(pdfPathF, id); |
| | | |
| | | try { |
| | | if (!getLicenseExcel()) { |
| | | System.out.println("授权失败"); |
| | | // return ; |
| | | } |
| | | // 读取Excel文件 |
| | | com.aspose.cells.Workbook wb = poiToAspose(util3.getWb()); |
| | | |
| | | // 获取需要导出的sheet(索引从0开始) |
| | | int targetSheetIndex = 1; |
| | | com.aspose.cells.Worksheet targetSheet = wb.getWorksheets().get(targetSheetIndex); |
| | | targetSheet.autoFitRows(true); |
| | | System.out.println("当前sheet名称:" + targetSheet.getName()); |
| | | System.out.println("当前sheet索引:" + targetSheet.getIndex()); |
| | | |
| | | // 隐藏所有其他工作表 |
| | | for (int j = 0; j < wb.getWorksheets().getCount(); j++) { |
| | | if (j != targetSheetIndex) { |
| | | wb.getWorksheets().get(j).setVisible(false); |
| | | } |
| | | } |
| | | |
| | | // 设置活动工作表为目标工作表 |
| | | wb.getWorksheets().setActiveSheetIndex(targetSheetIndex); |
| | | // 创建PDF保存选项 |
| | | com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions(); |
| | | pdfSaveOptions.setCompliance(com.aspose.cells.PdfCompliance.PDF_A_1_B); |
| | | // 创建临时字节输出流 |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | |
| | | // 将新的Workbook保存为PDF到临时流 |
| | | // newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF); |
| | | wb.save(baos, pdfSaveOptions); |
| | | |
| | | // 将PDF添加到ZIP文件 |
| | | ZipEntry entry07 = new ZipEntry(fna + adir +"/"+pdfPathF); |
| | | zos.putNextEntry(entry07); |
| | | zos.write(baos.toByteArray()); |
| | | // zos.closeEntry(); |
| | | // 直接将原始工作簿保存为PDF(只包含可见的工作表) |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | // System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // 打印详细错误信息 |
| | | System.err.println("转换失败:" + e.getMessage()); |
| | | e.printStackTrace(System.err); |
| | | } |
| | | |
| | | // ExcelUtil<ArchiveInfoVo> utilsv = new ExcelUtil<ArchiveInfoVo>(ArchiveInfoVo.class); |
| | | // |
| | | // |
| | | // ByteOutputStream boss = new ByteOutputStream(); |
| | | // List<ArchiveInfoVo> aivs = new ArrayList<>(); |
| | | // aivs.add(aIV); |
| | | // utilsv.byteOutputStreamExcel(boss, aivs,"Date List", ""); |
| | | |
| | | |
| | | |
| | | |
| | | //写入电子目录 xsxl |
| | | |
| | | ZipEntry entry5 = new ZipEntry(fna + adir +"/"+"电子文件目录" + ".xls"); |
| | | ExcelUtil<DocumentMaterialsVoLarge> util5 = new ExcelUtil<DocumentMaterialsVoLarge>(DocumentMaterialsVoLarge.class); |
| | | |
| | | zos.putNextEntry(entry5); |
| | | ByteOutputStream bos5 = new ByteOutputStream(); |
| | | util5.byteOutputStreamExcel(bos5, docs,"电子文件目录", ""); |
| | | bos5.writeTo(zos); |
| | | |
| | | //拿到卷内目录的excel |
| | | List<DocumentMaterialsVoSmall> list2 = dsvs.stream().map(res1 -> new DocumentMaterialsVoSmall(res1.getNum(), res1.getDocumentNumber(),res1.getCreator(), |
| | | res1.getTitle(), res1.getDate(), res1.getPageNumber(), res1.getRemarks())).collect(Collectors.toList()); |
| | | if(!dsvs.isEmpty()) { |
| | | String recordId = dsvs.get(0).getRecordId(); |
| | | byte[] imgr = barcodeService.generateBarcodeImage(recordId); |
| | | ExcelExp e1 = new ExcelExp("卷内目录数据", dsvs, DocumentMaterialsVo.class); |
| | | ExcelExp e2 = new ExcelExp("卷内数据", list2, recordId, imgr, DocumentMaterialsVoSmall.class); |
| | | List<ExcelExp> mysheet = new ArrayList<ExcelExp>(); |
| | | mysheet.add(e1); |
| | | mysheet.add(e2); |
| | | ExcelUtilManySheet<List<ExcelExp>> util2 = new ExcelUtilManySheet<List<ExcelExp>>(mysheet); |
| | | ZipEntry entr = new ZipEntry(fna + adir + "/" + "卷内目录" + ".xls"); |
| | | // ExcelUtil<DocumentMaterialsVo> util1 = new ExcelUtil<DocumentMaterialsVo>(DocumentMaterialsVo.class); |
| | | System.out.println(dsvs); |
| | | zos.putNextEntry(entr); |
| | | ByteOutputStream bos8 = new ByteOutputStream(); |
| | | |
| | | util2.exportExcelManySheet(bos8, mysheet); |
| | | |
| | | // util1.byteOutputStreamExcel(bos1, dsvs,"Date List", ""); |
| | | bos8.writeTo(zos); |
| | | |
| | | |
| | | |
| | | |
| | | //08-卷内卷内目录的pdf |
| | | String pdf08Path= "08-卷内目录.pdf"; |
| | | try { |
| | | if (!getLicenseExcel()) { |
| | | System.out.println("授权失败"); |
| | | // return ; |
| | | } |
| | | // 读取Excel文件 |
| | | com.aspose.cells.Workbook wb1 = poiToAspose(util2.getWb()); |
| | | |
| | | // 获取需要导出的sheet(索引从0开始) |
| | | int targetSheetIndex = 1; |
| | | com.aspose.cells.Worksheet targetSheet = wb1.getWorksheets().get(targetSheetIndex); |
| | | targetSheet.autoFitRows(true); |
| | | System.out.println("当前sheet名称:" + targetSheet.getName()); |
| | | System.out.println("当前sheet索引:" + targetSheet.getIndex()); |
| | | |
| | | // 隐藏所有其他工作表 |
| | | for (int j = 0; j < wb1.getWorksheets().getCount(); j++) { |
| | | if (j != targetSheetIndex) { |
| | | wb1.getWorksheets().get(j).setVisible(false); |
| | | } |
| | | } |
| | | |
| | | // 设置活动工作表为目标工作表 |
| | | wb1.getWorksheets().setActiveSheetIndex(targetSheetIndex); |
| | | // 创建PDF保存选项 |
| | | com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions(); |
| | | pdfSaveOptions.setCompliance(com.aspose.cells.PdfCompliance.PDF_A_1_B); |
| | | // 创建临时字节输出流 |
| | | ByteArrayOutputStream baosm = new ByteArrayOutputStream(); |
| | | |
| | | // 将新的Workbook保存为PDF到临时流 |
| | | // newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF); |
| | | wb1.save(baosm, pdfSaveOptions); |
| | | |
| | | // 将PDF添加到ZIP文件 |
| | | ZipEntry entry2 = new ZipEntry(fna + adir +"/"+pdf08Path); |
| | | zos.putNextEntry(entry2); |
| | | zos.write(baosm.toByteArray()); |
| | | // zos.closeEntry(); |
| | | // 直接将原始工作簿保存为PDF(只包含可见的工作表) |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | // System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // 打印详细错误信息 |
| | | System.err.println("转换失败:" + e.getMessage()); |
| | | e.printStackTrace(System.err); |
| | | } |
| | | |
| | | |
| | | } |
| | | //把excel转为pdf |
| | | |
| | | // |
| | | // //08-卷内卷内目录的pdf |
| | | // String pdf08Path= "08-卷内目录.pdf"; |
| | | // List<DocumentMaterialsVo> list3 = dsvs; |
| | | // if(list3.size()>0) { |
| | | // pdfGenerateService.generateFileDirectoryPdf(pdf08Path, list3); |
| | | // ZipEntry zipEntry3 = new ZipEntry(fna + adir +"/"+pdf08Path); |
| | | // zos.putNextEntry(zipEntry3); |
| | | // |
| | | // // 读取PDF文件内容并写入ZIP |
| | | // try (FileInputStream fis = new FileInputStream(pdf08Path)) { |
| | | // byte[] buffer = new byte[1024]; |
| | | // int len; |
| | | // while ((len = fis.read(buffer)) > 0) { |
| | | // zos.write(buffer, 0, len); |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // |
| | | |
| | | |
| | | |
| | | byte[] buf = new byte[1024]; |
| | | for (DocumentMaterialsVoLarge dc : docs) { |
| | | String filePath = dc.getUrl(); |
| | |
| | | //在压缩包中添加文件夹 |
| | | |
| | | //得到文件名frontCompWithZore(4, dc.get)+ |
| | | String fname = frontCompWithZore(4, dc.getFileNumber().intValue())+"-"+dc.getTitle()+"-"+frontCompWithZore(4,dc.getPageNumber().intValue())+"." |
| | | +dc.getUrl().split("\\.")[1]; |
| | | if(dc.getStage().equals("01-申请材料")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/01-申请材料/"+fname)); |
| | | else if(dc.getStage().equals("02-办案过程材料")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/02-办案过程材料/"+fname)); |
| | | else if(dc.getStage().equals("03-结论性文件")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/03-结论性文件/"+fname)); |
| | | else if(dc.getStage().equals("04-其他材料")) { |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/04-其他材料/" + fname)); |
| | | } |
| | | else if(dc.getStage().equals("05-档案变更材料")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/05-档案变更材料/"+fname)); |
| | | else if(dc.getStage().equals("06-业务数据")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/06-业务数据/"+fname)); |
| | | else |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/"+fname)); |
| | | |
| | | String fname = ""; |
| | | if(dc.getFileNumber()!=null&&dc.getPageNumber()!=null) { |
| | | fname = frontCompWithZore(4, dc.getFileNumber().intValue()) + "-" + dc.getTitle() + "-" + frontCompWithZore(4, dc.getPageNumber().intValue()) + "." |
| | | + dc.getUrl().split("\\.")[1]; |
| | | if (dc.getStage().equals("01-申请材料")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/01-申请材料/" + fname)); |
| | | else if (dc.getStage().equals("02-办案过程材料")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/02-办案过程材料/" + fname)); |
| | | else if (dc.getStage().equals("03-结论性文件")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/03-结论性文件/" + fname)); |
| | | else if (dc.getStage().equals("04-其他材料")) { |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/04-其他材料/" + fname)); |
| | | } else if (dc.getStage().equals("05-档案变更材料")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/05-档案变更材料/" + fname)); |
| | | else if (dc.getStage().equals("06-业务数据")) |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/06-业务数据/" + fname)); |
| | | else |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/" + fname)); |
| | | |
| | | |
| | | int len; |
| | | FileInputStream in = new FileInputStream(tempFile); |
| | | while ((len = in.read(buf)) != -1){ |
| | | zos.write(buf, 0, len); |
| | | } |
| | | // zos.putNextEntry(new ZipEntry("04-其他材料")); |
| | | zos.closeEntry(); |
| | | in.close(); |
| | | } |
| | | |
| | | int len; |
| | | FileInputStream in = new FileInputStream(tempFile); |
| | | while ((len = in.read(buf)) != -1){ |
| | | zos.write(buf, 0, len); |
| | | } |
| | | // zos.putNextEntry(new ZipEntry("04-其他材料")); |
| | | zos.closeEntry(); |
| | | in.close(); |
| | | } |
| | | System.out.println(file.getName()); |
| | | writeFileToRes(response, file.getName(), file); |
| | | } |
| | | |
| | | //删除压缩包 |
| | | // if(file.exists()){ |
| | | // file.delete(); |
| | | // } |
| | | |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | System.out.println(file.getName()); |
| | | System.out.println(file.getTotalSpace()); |
| | | // file. |
| | | writeFileToRes(response, file.getName(), file); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | //.selectDocumentMaterialsList(documentMaterials); |
| | | List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString()); |
| | | if(dsvs==null||dsvs.isEmpty()) |
| | | { |
| | | throw new RuntimeException("电子文件信息没有上传,请补充!"); |
| | | } |
| | | ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(id); |
| | | |
| | | System.out.println(dsvs.size()); |
| | | List<String> paths = new ArrayList<>(); |
| | | // System.out.println(docs); |
| | | if (docs.size() == 1) { // 直接下载 |
| | |
| | | |
| | | String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); |
| | | String filePath = RuoYiConfig.getDownloadPath() + fileName; |
| | | |
| | | |
| | | if(file.exists()) |
| | | System.out.println("322329323232323"); |
| | | System.out.println(filePath+"0009999999999"); |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, realFileName); |
| | | // response.addHeader("Content-Disposition", "attachment;filename=fileName" + ".xls"); |
| | | |
| | | FileUtils.writeBytes(filePath, response.getOutputStream()); |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | public com.aspose.cells.Workbook poiToAspose(org.apache.poi.ss.usermodel.Workbook poiWorkbook) throws Exception { |
| | | // 临时文件路径 |
| | | String tempFilePath = "temp_workbook.xlsx"; |
| | | |
| | | try { |
| | | // 1. 将Apache POI Workbook保存为临时文件 |
| | | try (FileOutputStream fos = new FileOutputStream(tempFilePath)) { |
| | | poiWorkbook.write(fos); |
| | | } |
| | | |
| | | // 2. 使用Aspose加载临时文件 |
| | | com.aspose.cells.Workbook asposeWorkbook = new com.aspose.cells.Workbook(tempFilePath); |
| | | |
| | | return asposeWorkbook; |
| | | |
| | | } finally { |
| | | // 清理临时文件 |
| | | File tempFile = new File(tempFilePath); |
| | | if (tempFile.exists()) { |
| | | tempFile.delete(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | //压缩文件 |
| | | zos = new ZipOutputStream(os); |
| | | |
| | | //pdf目录封面 |
| | | String pdfPathF = "07-卷面封面.pdf"; |
| | | pdfGenerateService.generatePdf(pdfPathF, 55L); |
| | | // 2. 压缩PDF到ZIP文件 |
| | | // 添加PDF文件到ZIP |
| | | ZipEntry zipEntry = new ZipEntry(pdfPathF); |
| | | zos.putNextEntry(zipEntry); |
| | | |
| | | // 读取PDF文件内容并写入ZIP |
| | | try (FileInputStream fis = new FileInputStream(pdfPathF)) { |
| | | byte[] buffer = new byte[1024]; |
| | | int len; |
| | | while ((len = fis.read(buffer)) > 0) { |
| | | zos.write(buffer, 0, len); |
| | | } |
| | | } |
| | | //08-卷内卷内目录的pdf |
| | | String pdf08Path= "08-卷内目录.pdf"; |
| | | List<DocumentMaterialsVo> list3 = dsvs; |
| | | pdfGenerateService.generateFileDirectoryPdf(pdf08Path, list3); |
| | | ZipEntry zipEntry2 = new ZipEntry(pdf08Path); |
| | | zos.putNextEntry(zipEntry2); |
| | | |
| | | // 读取PDF文件内容并写入ZIP |
| | | try (FileInputStream fis = new FileInputStream(pdf08Path)) { |
| | | byte[] buffer = new byte[1024]; |
| | | int len; |
| | | while ((len = fis.read(buffer)) > 0) { |
| | | zos.write(buffer, 0, len); |
| | | } |
| | | } |
| | | //09-备考表.pdf |
| | | String pdf09Path = "09-备考表.pdf"; |
| | | pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), id); |
| | | // 2. 压缩PDF到ZIP文件 |
| | | // 添加PDF文件到ZIP |
| | | ZipEntry zipEntry1 = new ZipEntry(pdf09Path); |
| | | zos.putNextEntry(zipEntry1); |
| | | // pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), id); |
| | | //拿到相关数据 |
| | | List<DocumentMaterialFileStyle> dmfs = documentMaterialsService.findFileStyleInfo(Math.toIntExact(id)); |
| | | |
| | | // 读取PDF文件内容并写入ZIP |
| | | try (FileInputStream fis = new FileInputStream(pdf09Path)) { |
| | | byte[] buffer = new byte[1024]; |
| | | int len; |
| | | while ((len = fis.read(buffer)) > 0) { |
| | | zos.write(buffer, 0, len); |
| | | LocalDate currentDate = LocalDate.now(); |
| | | |
| | | |
| | | String cdt = currentDate.getYear()+"年"+currentDate.getMonthValue()+"月"+currentDate.getDayOfMonth()+"日"; |
| | | |
| | | HashMap<String, Object> hs = new HashMap<String, Object>(); |
| | | int allPages = 0; |
| | | int texPages = 0; |
| | | int picPages = 0; |
| | | int patPages = 0; |
| | | if(!dmfs.isEmpty()) |
| | | { |
| | | for(DocumentMaterialFileStyle documentMaterialFileStyle:dmfs) |
| | | { |
| | | if(documentMaterialFileStyle.getFileStyle().equals("文字材料")) |
| | | texPages = documentMaterialFileStyle.getCnt(); |
| | | if(documentMaterialFileStyle.getFileStyle().equals("图样材料")) |
| | | patPages = documentMaterialFileStyle.getCnt(); |
| | | if(documentMaterialFileStyle.getFileStyle().equals("照片材料")) |
| | | picPages = documentMaterialFileStyle.getCnt(); |
| | | } |
| | | } |
| | | allPages = texPages + picPages + patPages; |
| | | hs.put("pages", allPages); |
| | | hs.put("patPages", patPages); |
| | | hs.put("picPages", picPages); |
| | | hs.put("texPages", texPages); |
| | | hs.put("volumeNumber", aIV.getRecordId()); |
| | | hs.put("time", cdt); |
| | | |
| | | if (!getLicense()) { |
| | | System.out.println("没有相关证书!"); |
| | | } |
| | | |
| | | |
| | | try { |
| | | |
| | | // 获取 Word 模板所在路径 |
| | | String filepath = "09-备考表.docx"; |
| | | // 通过 XWPFTemplate 编译文件并渲染数据到模板中 |
| | | XWPFTemplate template = XWPFTemplate.compile(filepath).render(hs |
| | | ); |
| | | |
| | | String renderedDocPath = "rendered_output.docx"; |
| | | File renderedFile = new File(renderedDocPath); |
| | | try { |
| | | // 将完成数据渲染的文档写出 |
| | | template.writeAndClose(new FileOutputStream(renderedFile)); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | com.aspose.words.Document doc = new com.aspose.words.Document("rendered_output.docx"); |
| | | // 创建临时字节输出流 |
| | | ByteArrayOutputStream baobk = new ByteArrayOutputStream(); |
| | | |
| | | // 将Word文档转换为PDF字节数组 |
| | | doc.save(baobk, com.aspose.words.SaveFormat.PDF);//ȫ��֧��DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF �ת�� |
| | | // byte[] pdfBytes = baobk.toByteArray(); |
| | | |
| | | // 获取PDF总页数 |
| | | |
| | | |
| | | // 将PDF添加到ZIP文件 |
| | | ZipEntry entry09 = new ZipEntry(pdf09Path); |
| | | zos.putNextEntry(entry09); |
| | | baobk.writeTo(zos); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | |
| | | com.aspose.words.Document doc = new com.aspose.words.Document("09-备考表.docx"); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // // 压缩PDF到ZIP文件 |
| | | // // 添加PDF文件到ZIP |
| | | // ZipEntry zipEntry1 = new ZipEntry(pdf09Path); |
| | | // zos.putNextEntry(zipEntry1); |
| | | // |
| | | // // 读取PDF文件内容并写入ZIP |
| | | // try (FileInputStream fis = new FileInputStream(pdf09Path)) { |
| | | // byte[] buffer = new byte[1024]; |
| | | // int len; |
| | | // while ((len = fis.read(buffer)) > 0) { |
| | | // zos.write(buffer, 0, len); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | |
| | | |
| | | //excel 卷内封面导出zip |
| | | ZipEntry entryiv = new ZipEntry("卷内封面" + ".xls"); |
| | | ZipEntry entryiv = new ZipEntry("案卷封面" + ".xls"); |
| | | |
| | | List<ArchiveInfoVo> arsi = new ArrayList<>(); |
| | | arsi.add(aIV); |
| | |
| | | // System.out.println(bos2); |
| | | zos.putNextEntry(entryiv); |
| | | |
| | | // ExcelUtil<ArchiveInfoVo> utilsv = new ExcelUtil<ArchiveInfoVo>(ArchiveInfoVo.class); |
| | | // |
| | | bos2.writeTo(zos); |
| | | |
| | | |
| | | //pdf目录封面 |
| | | String pdfPathF = "07-案卷封面.pdf"; |
| | | // pdfGenerateService.generatePdf(pdfPathF, id); |
| | | |
| | | try { |
| | | if (!getLicenseExcel()) { |
| | | System.out.println("授权失败"); |
| | | // return ; |
| | | } |
| | | // 读取Excel文件 |
| | | com.aspose.cells.Workbook wb = poiToAspose(util3.getWb()); |
| | | |
| | | // 获取需要导出的sheet(索引从0开始) |
| | | int targetSheetIndex = 1; |
| | | com.aspose.cells.Worksheet targetSheet = wb.getWorksheets().get(targetSheetIndex); |
| | | targetSheet.autoFitRows(true); |
| | | System.out.println("当前sheet名称:" + targetSheet.getName()); |
| | | System.out.println("当前sheet索引:" + targetSheet.getIndex()); |
| | | |
| | | // 隐藏所有其他工作表 |
| | | for (int i = 0; i < wb.getWorksheets().getCount(); i++) { |
| | | if (i != targetSheetIndex) { |
| | | wb.getWorksheets().get(i).setVisible(false); |
| | | } |
| | | } |
| | | |
| | | // 设置活动工作表为目标工作表 |
| | | wb.getWorksheets().setActiveSheetIndex(targetSheetIndex); |
| | | // 创建PDF保存选项 |
| | | com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions(); |
| | | pdfSaveOptions.setCompliance(com.aspose.cells.PdfCompliance.PDF_A_1_B); |
| | | // 创建临时字节输出流 |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | |
| | | // 将新的Workbook保存为PDF到临时流 |
| | | // newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF); |
| | | wb.save(baos, pdfSaveOptions); |
| | | |
| | | // 将PDF添加到ZIP文件 |
| | | ZipEntry entry = new ZipEntry(pdfPathF); |
| | | zos.putNextEntry(entry); |
| | | zos.write(baos.toByteArray()); |
| | | // zos.closeEntry(); |
| | | // 直接将原始工作簿保存为PDF(只包含可见的工作表) |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | // System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // 打印详细错误信息 |
| | | System.err.println("转换失败:" + e.getMessage()); |
| | | e.printStackTrace(System.err); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // |
| | | // ByteOutputStream boss = new ByteOutputStream(); |
| | | // List<ArchiveInfoVo> aivs = new ArrayList<>(); |
| | | // aivs.add(aIV); |
| | | // utilsv.byteOutputStreamExcel(boss, aivs,"Date List", ""); |
| | | bos2.writeTo(zos); |
| | | |
| | | //写入电子目录 xsxl |
| | | |
| | | ZipEntry entry = new ZipEntry("电子文件目录" + ".xls"); |
| | |
| | | String recordId = dsvs.get(0).getRecordId(); |
| | | byte[] imgr = barcodeService.generateBarcodeImage(recordId); |
| | | ExcelExp e1 = new ExcelExp("卷内目录数据",dsvs, DocumentMaterialsVo.class); |
| | | ExcelExp e2 = new ExcelExp("卷内数据", list2, recordId, imgr, DocumentMaterialsVoSmall.class); |
| | | ExcelExp e2 = new ExcelExp("卷内目录", list2, recordId, imgr, DocumentMaterialsVoSmall.class); |
| | | List<ExcelExp> mysheet = new ArrayList<ExcelExp>(); |
| | | mysheet.add(e1); |
| | | mysheet.add(e2); |
| | |
| | | bos1.writeTo(zos); |
| | | //把excel转为pdf |
| | | |
| | | //08-卷内卷内目录的pdf |
| | | String pdf08Path= "08-卷内目录.pdf"; |
| | | try { |
| | | if (!getLicenseExcel()) { |
| | | System.out.println("授权失败"); |
| | | // return ; |
| | | } |
| | | // 读取Excel文件 |
| | | com.aspose.cells.Workbook wb1 = poiToAspose(util2.getWb()); |
| | | |
| | | // 获取需要导出的sheet(索引从0开始) |
| | | int targetSheetIndex = 1; |
| | | com.aspose.cells.Worksheet targetSheet = wb1.getWorksheets().get(targetSheetIndex); |
| | | targetSheet.autoFitRows(true); |
| | | System.out.println("当前sheet名称:" + targetSheet.getName()); |
| | | System.out.println("当前sheet索引:" + targetSheet.getIndex()); |
| | | |
| | | // 隐藏所有其他工作表 |
| | | for (int i = 0; i < wb1.getWorksheets().getCount(); i++) { |
| | | if (i != targetSheetIndex) { |
| | | wb1.getWorksheets().get(i).setVisible(false); |
| | | } |
| | | } |
| | | |
| | | // 设置活动工作表为目标工作表 |
| | | wb1.getWorksheets().setActiveSheetIndex(targetSheetIndex); |
| | | // 创建PDF保存选项 |
| | | com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions(); |
| | | pdfSaveOptions.setCompliance(com.aspose.cells.PdfCompliance.PDF_A_1_B); |
| | | // 创建临时字节输出流 |
| | | ByteArrayOutputStream baosm = new ByteArrayOutputStream(); |
| | | |
| | | // 将新的Workbook保存为PDF到临时流 |
| | | // newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF); |
| | | wb1.save(baosm, pdfSaveOptions); |
| | | |
| | | // 将PDF添加到ZIP文件 |
| | | ZipEntry entry2 = new ZipEntry(pdf08Path); |
| | | zos.putNextEntry(entry2); |
| | | zos.write(baosm.toByteArray()); |
| | | // zos.closeEntry(); |
| | | // 直接将原始工作簿保存为PDF(只包含可见的工作表) |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | // System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // 打印详细错误信息 |
| | | System.err.println("转换失败:" + e.getMessage()); |
| | | e.printStackTrace(System.err); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //List<DocumentMaterialsVo> list3 = dsvs; |
| | | |
| | | |
| | | // pdfGenerateService.generateFileDirectoryPdf(pdf08Path, list3); |
| | | // ZipEntry zipEntry2 = new ZipEntry(pdf08Path); |
| | | // zos.putNextEntry(zipEntry2); |
| | | // |
| | | // // 读取PDF文件内容并写入ZIP |
| | | // try (FileInputStream fis = new FileInputStream(pdf08Path)) { |
| | | // byte[] buffer = new byte[1024]; |
| | | // int len; |
| | | // while ((len = fis.read(buffer)) > 0) { |
| | | // zos.write(buffer, 0, len); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | |
| | | System.out.println(filePath); |
| | | File tempFile = new File(filePath); |
| | | |
| | | //在压缩包中添加文件夹 |
| | | if(res) { |
| | | zos.putNextEntry(new ZipEntry("01-申请材料/")); |
| | |
| | | res = false; |
| | | } |
| | | //得到文件名frontCompWithZore(4, dc.get)+ |
| | | String fname = frontCompWithZore(4, dc.getFileNumber().intValue())+"-"+dc.getTitle()+"-"+frontCompWithZore(4,dc.getPageNumber().intValue())+"." |
| | | +dc.getUrl().split("\\.")[1]; |
| | | if(dc.getStage().equals("01-申请材料")) |
| | | zos.putNextEntry(new ZipEntry("01-申请材料/"+fname)); |
| | | else if(dc.getStage().equals("02-办案过程材料")) |
| | | zos.putNextEntry(new ZipEntry("02-办案过程材料/"+fname)); |
| | | else if(dc.getStage().equals("03-结论性文件")) |
| | | zos.putNextEntry(new ZipEntry("03-结论性文件/"+fname)); |
| | | else if(dc.getStage().equals("04-其他材料")) { |
| | | zos.putNextEntry(new ZipEntry("04-其他材料/" + fname)); |
| | | String fname = ""; |
| | | if(dc.getFileNumber()!=null&&dc.getPageNumber()!=null) { |
| | | fname = frontCompWithZore(4, dc.getFileNumber().intValue()) + "-" + dc.getTitle() + "-" + frontCompWithZore(4, dc.getPageNumber().intValue()) + "." |
| | | + dc.getUrl().split("\\.")[1]; |
| | | if (dc.getStage().equals("01-申请材料")) |
| | | zos.putNextEntry(new ZipEntry("01-申请材料/" + fname)); |
| | | else if (dc.getStage().equals("02-办案过程材料")) |
| | | zos.putNextEntry(new ZipEntry("02-办案过程材料/" + fname)); |
| | | else if (dc.getStage().equals("03-结论性文件")) |
| | | zos.putNextEntry(new ZipEntry("03-结论性文件/" + fname)); |
| | | else if (dc.getStage().equals("04-其他材料")) { |
| | | zos.putNextEntry(new ZipEntry("04-其他材料/" + fname)); |
| | | } else if (dc.getStage().equals("05-档案变更材料")) |
| | | zos.putNextEntry(new ZipEntry("05-档案变更材料/" + fname)); |
| | | else if (dc.getStage().equals("06-业务数据")) |
| | | zos.putNextEntry(new ZipEntry("06-业务数据/" + fname)); |
| | | else |
| | | zos.putNextEntry(new ZipEntry(fname)); |
| | | |
| | | } |
| | | else if(dc.getStage().equals("05-档案变更材料")) |
| | | zos.putNextEntry(new ZipEntry("05-档案变更材料/"+fname)); |
| | | else if(dc.getStage().equals("06-业务数据")) |
| | | zos.putNextEntry(new ZipEntry("06-业务数据/"+fname)); |
| | | else |
| | | zos.putNextEntry(new ZipEntry(fname)); |
| | | |
| | | |
| | | |
| | | int len; |
| | | FileInputStream in = new FileInputStream(tempFile); |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |