- Java锁的逻辑(结合对象头和ObjectMonitor)
- 还在用饼状图?来瞧瞧这些炫酷的百分比可视化新图形(附代码实现)⛵
- 自动注册实体类到EntityFrameworkCore上下文,并适配ABP及ABPVNext
- 基于Sklearn机器学习代码实战
github代码地址 | https://github.com/Tom-shushu/work-study |
接口文档有道云 | https://note.youdao.com/s/GShGsYE8 |
接口文档离线版本 | https://files.cnblogs.com/files/Tom-shushu/%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3.rar?t=1682958343&download=true |
怎么说呢,从去年十二月份(就是我发最后一篇文章时间)到现在已经四五个月了,这段时间感觉生活很乱,我在安安心心上班、边上班边学习新知识新技术然后跳槽到大厂、边上班边考《系统架构设计师》这三件事情之间徘徊犹豫一直持续到现在,所以导致一样事情也没有干好 ------- 总结一句:为什么没有更博客呢?一个字,就是懒,嘿嘿~ 。
还有一个原因:就是最近朋友给介绍了一个对象,比较忙(*^▽^*) 。
为什么发布这篇文档转换的文章呢?因为上周我要将一个PDF转换为Word,结果百度谷歌了所有文章,最终的结果都是“能转换,但是只能转换一点点,多了就要收费”,于是乎我突发奇想、心血来潮在放假的那天打算开发一款小程序实现各种文档的转换,在百度了一下午后发现目前都是借助Aspose实现的,但是好像要收费,在我新建项目时偶然间发现原来Maven仓库里面居然有人将破解好的Jar包上传到Maven中央仓库了,于是我测试了一下,哈哈真香,于是就有了这篇文章。至于小程序做的怎么样了呢?暂时又搁置了,因为我调查了一下已经有现成的好多优秀的微信小程序可以实现各种文档转换了,还有就是个人小程序没法上线,可能暂时不会做小程序了,大家有想法的可以按照自己的想法使用我的源码,直接和前端对接做出优秀的小程序.
<dependency> <groupId>com.luhuiguo</groupId> <artifactId>aspose-pdf</artifactId> <version>23.1</version> </dependency>
/** * @description: 获取文件保存地址 * @return : java.lang.String * @author : zhouhong * @date: 2023/4/30 12:36 */ public String getSavePath() { ApplicationHome applicationHome = new ApplicationHome( this .getClass()); // 保存目录位置根据项目需求可随意更改 return applicationHome.getDir().getParentFile() .getParentFile().getAbsolutePath() + "\\src\\main\\resources\\templates\\" ; } /** * @description: 上传文件到阿里云OSS * @return : java.lang.String * @author : zhouhong * @date: 2023/5/1 22:55 */ public String uploadOssFile(String fileName, File file){ // 创建OSSClient实例。 OSS ossClient = ossConfig.getOssClient(); try { // 创建PutObjectRequest对象。 PutObjectRequest putObjectRequest = new PutObjectRequest(ossConfig.getBucketName(), fileName, file); putObjectRequest.setProcess( "true" ); // 上传文件。 PutObjectResult result = ossClient.putObject(putObjectRequest); // 如果上传成功,则返回200。 if (result.getResponse().getStatusCode() == 200 ) { return result.getResponse().getUri(); } } catch (OSSException oe) { } catch (ClientException ce) { } finally { if (ossClient != null ) { ossClient.shutdown(); } } return null ; }
/** * @description: PDF 转其他文件 * @return : java.util.List<java.lang.String> * @author : zhouhong * @date: 2023/5/1 23:34 */ @Override public List<String> pdfToFile(MultipartFile file,String type) { List <String> res = new ArrayList<> (); String checkType = FilenameUtils.getExtension(file.getOriginalFilename()); if (!"pdf" .equals(checkType)) { throw new ServiceException(1, "输入文件不是PDF文件!" ); } try { switch (type.toUpperCase()) { case "WORD" : { return switchFile(file, com.aspose.pdf.SaveFormat.DocX, "docx" ); } case "XML" : { return switchFile(file, SaveFormat.PdfXml, "xml" ); } case "EXCEL" : { return switchFile(file, com.aspose.pdf.SaveFormat.Excel, "xlsx" ); } case "PPT" : { return switchFile(file, com.aspose.pdf.SaveFormat.Pptx, "pptx" ); } case "PNG" : { // 图片类型的需要获取每一页PDF,一张一张转换 Document pdfDocument = new Document(file.getInputStream()); // 分辨率 Resolution resolution = new Resolution(130 ); PngDevice pngDevice = new PngDevice(resolution); // if (pdfDocument.getPages().size() <= 10 ) { for ( int index = 0; index < pdfDocument.getPages().size(); index++ ) { String fileName = UUID.randomUUID() + ".png" ; String filePath = ossUpLoadTools.getSavePath() + "/" + fileName; File tmpFile = new File(filePath); FileOutputStream fileOS = new FileOutputStream(tmpFile); pngDevice.process(pdfDocument.getPages().get_Item(index), fileOS); res.add(ossUpLoadTools.uploadOssFile(fileName, tmpFile)); fileOS.close(); tmpFile.delete(); } } else { throw new ServiceException(2, "抱歉超过10页暂时无法转图片" ); } return res; } case "HTML" : { String fileName = UUID.randomUUID() + ".html" ; String filePath = ossUpLoadTools.getSavePath() + "/" + fileName; Document doc = new Document(file.getInputStream()); HtmlSaveOptions saveOptions = new HtmlSaveOptions(); saveOptions.setFixedLayout( true ); saveOptions.setSplitIntoPages( false ); saveOptions.setRasterImagesSavingMode(HtmlSaveOptions.RasterImagesSavingModes.AsExternalPngFilesReferencedViaSvg); doc.save(filePath , saveOptions); doc.close(); File outputfile = new File(filePath); res.add(ossUpLoadTools.uploadOssFile(fileName, outputfile)); outputfile.delete(); return res; } default :{} } } catch (Exception e) { e.printStackTrace(); } return null ; } private List<String> switchFile(MultipartFile file, SaveFormat saveFormat, String suffix) { List <String> resUrl = new ArrayList<> (); try { long old = System.currentTimeMillis(); // 输出路径 String fileName = UUID.randomUUID() + "." + suffix; String filePath = ossUpLoadTools.getSavePath() + "/" + fileName; FileOutputStream os = new FileOutputStream(filePath); Document doc = new Document(file.getInputStream()); doc.save(os, saveFormat); os.close(); doc.close(); File outputfile = new File(filePath); resUrl.add(ossUpLoadTools.uploadOssFile(fileName, outputfile)); outputfile.delete(); long now = System.currentTimeMillis(); log.info( "共耗时:" + ((now - old) / 1000.0) + "秒" ); } catch (IOException e) { e.printStackTrace(); } return resUrl; }
/** * @description: 合并两个PDF文件 * @return : java.lang.String * @author : zhouhong * @date: 2023/5/1 23:40 */ @Override public String mergeTwoPdfFile(MultipartFile file1, MultipartFile file2) { try { Document doc1 = new Document(file1.getInputStream()); Document doc2 = new Document(file2.getInputStream()); doc1.getPages().add(doc2.getPages()); String fileName = UUID.randomUUID() + ".pdf" ; String filePath = ossUpLoadTools.getSavePath() + "/" + fileName; doc1.save(filePath); doc1.close(); File outputfile = new File(filePath); String res = ossUpLoadTools.uploadOssFile(fileName, outputfile); outputfile.delete(); return res; } catch (IOException e){ e.printStackTrace(); } return null ; } /** * @description: 合并对个PDF文件 * @return : java.lang.String * @author : zhouhong * @date: 2023/5/1 23:40 */ @Override public String mergeMorePdfFile(MultipartFile ... file) { try { String mergeFileName = UUID.randomUUID() + ".pdf" ; String mergePdfPath = ossUpLoadTools.getSavePath() + "/" + mergeFileName; String[] chilPdfPath = new String[file.length]; // 读取PDF并获取路径 for ( int i = 0; i < file.length; i++ ) { String fileName = UUID.randomUUID() + ".pdf" ; String filePath = ossUpLoadTools.getSavePath() + "/" + fileName; FileOutputStream os = new FileOutputStream(filePath); Document doc = new Document(file[i].getInputStream()); doc.save(os); chilPdfPath[i] = filePath; os.close(); doc.close(); } // 合并多个PDF PdfFileEditor pdfFileEditor = new PdfFileEditor(); pdfFileEditor.concatenate(chilPdfPath, mergePdfPath); // 读取文件上传OSS File outputfile = new File(mergePdfPath); String resUrl = ossUpLoadTools.uploadOssFile(mergeFileName, outputfile); outputfile.delete(); return resUrl; } catch (Exception e) { e.printStackTrace(); } return null ; }
<dependency> <groupId>com.luhuiguo</groupId> <artifactId>aspose-cells</artifactId> <version>22.10</version> </dependency>
/** * @description: Excel转其他文件 * @return : java.lang.String * @author : zhouhong * @date: 2023/5/1 23:44 */ @Override public String excelToFile(MultipartFile file, String type) { String checkType = FilenameUtils.getExtension(file.getOriginalFilename()); if (!"xlsx".equals(checkType) && !"xls" .equals(checkType)) { throw new ServiceException(1, "输入文件不是Excel文件!" ); } try { switch (type.toUpperCase()) { /** ****************** 文档类型 ************** */ case "WORD" : { return SwitchFile(file, com.aspose.cells.SaveFormat.DOCX, "docx" ); } case "PDF" : { return SwitchFile(file, com.aspose.cells.SaveFormat.PDF, "pdf" ); } case "PPT" : { return SwitchFile(file, com.aspose.cells.SaveFormat.PPTX, "pptx" ); } case "HTML" : { return SwitchFile(file, com.aspose.cells.SaveFormat.HTML, "html" ); } case "JSON" : { return SwitchFile(file, com.aspose.cells.SaveFormat.JSON, ".json" ); } case "MARKDOWN" : { return SwitchFile(file, com.aspose.cells.SaveFormat.MARKDOWN, "md" ); } /** *************** 图片类型 (注意图片格式的默认只转换第一个 Sheet1)******************** */ case "PNG" : { return SwitchFile(file, com.aspose.cells.SaveFormat.PNG, "png" ); } case "JPG" : { return SwitchFile(file, com.aspose.cells.SaveFormat.JPG, "jpg" ); } case "BMP" : { return SwitchFile(file, com.aspose.cells.SaveFormat.BMP, "bmp" ); } case "CSV" : { return SwitchFile(file, com.aspose.cells.SaveFormat.CSV, "csv" ); } case "SVG" : { return SwitchFile(file, com.aspose.cells.SaveFormat.SVG, "svg" ); } // 好像有问题,有需要大家自己调试一下 // case "XML" : { // return SwitchFile(file, com.aspose.cells.SaveFormat.XML, "xml"); // } default :{} } } catch (Exception e) { e.printStackTrace(); } return null ; } private String SwitchFile(MultipartFile file, int saveFormat, String suffix) { String url = "" ; try { long old = System.currentTimeMillis(); String fileName = UUID.randomUUID() + "." + suffix; String filePath = ossUpLoadTools.getSavePath() + "/" + fileName; FileOutputStream os = new FileOutputStream(filePath); // 加载源文件数据 Workbook excel = new Workbook(file.getInputStream()); // 设置转换文件类型并转换 excel.save(os, saveFormat); os.close(); File outputfile = new File(filePath); url = ossUpLoadTools.uploadOssFile(fileName, outputfile); outputfile.delete(); long now = System.currentTimeMillis(); log.info( "共耗时:" + ((now - old) / 1000.0) + "秒" ); } catch (Exception e) { e.printStackTrace(); } return url; }
<dependency> <groupId>com.luhuiguo</groupId> <artifactId>aspose-words</artifactId> <version>23.1</version> </dependency>
@Override public String wordToFile(MultipartFile file, String type) { String checkType = FilenameUtils.getExtension(file.getOriginalFilename()); if (!"doc".equals(checkType) && !"docx" .equals(checkType)) { throw new ServiceException(1, "输入文件不是Word文件!" ); } try { switch (type.toUpperCase()) { case "TEXT" : { return switchFile(file, SaveFormat.TEXT, "txt" ); } case "PDF" : { return switchFile(file, com.aspose.words.SaveFormat.PDF, "pdf" ); } /** ************* 需要操作每一页Word文件,一般Word类的直接电脑操作,应该用不上*********** */ // case "PNG" : { // return switchFile(file, com.aspose.words.SaveFormat.PNG, "png"); // } // case "JPG" : { // return switchFile(file, com.aspose.words.SaveFormat.JPEG, "jpg"); // } default :{} } } catch (Exception e) { e.printStackTrace(); } return null ; } private String switchFile(MultipartFile file, int saveFormat, String suffix){ String url = "" ; try { long old = System.currentTimeMillis(); // 输出路径 String fileName = UUID.randomUUID() + "." + suffix; String filePath = ossUpLoadTools.getSavePath() + "/" + fileName; FileOutputStream os = new FileOutputStream(filePath); com.aspose.words.Document doc = new com.aspose.words.Document(file.getInputStream()); doc.save(os, saveFormat); os.close(); File outputfile = new File(filePath); url = ossUpLoadTools.uploadOssFile(fileName, outputfile); outputfile.delete(); long now = System.currentTimeMillis(); log.info( "共耗时:" + ((now - old) / 1000.0) + "秒" ); } catch (Exception e) { e.printStackTrace(); } return url; }
<groupId>com.luhuiguo</groupId>
<artifactId>aspose-slides</artifactId>
<version>23.1</version>
</dependency>
@Override public String PptToFile(MultipartFile file, String type) { // 获取文件后缀名 String checkType = FilenameUtils.getExtension(file.getOriginalFilename()); if (!"ppt".equals(checkType) && !"pptx" .equals(checkType)) { throw new ServiceException(1, "输入文件不是PPT文件!" ); } try { switch (type.toUpperCase()) { case "HTML" : { return SwitchFile(file, com.aspose.slides.SaveFormat.Html, "html" ); } case "HTML5" : { return SwitchFile(file, com.aspose.slides.SaveFormat.Html5, "html" ); } case "PDF" : { return SwitchFile(file, com.aspose.slides.SaveFormat.Pdf, "pdf" ); } default :{} } } catch (Exception e) { e.printStackTrace(); } return null ; } private String SwitchFile(MultipartFile file, int saveFormat, String suffix) { String url = "" ; try { long old = System.currentTimeMillis(); String fileName = UUID.randomUUID() + "." + suffix; String filePath = ossUpLoadTools.getSavePath() + "/" + fileName; FileOutputStream os = new FileOutputStream(filePath); // 加载源文件数据 Presentation ppt = new Presentation(file.getInputStream()); // 设置转换文件类型并转换 ppt.save(os, saveFormat); os.close(); File outputfile = new File(filePath); url = ossUpLoadTools.uploadOssFile(fileName, outputfile); // 删除临时文件 outputfile.delete(); long now = System.currentTimeMillis(); log.info( "共耗时:" + ((now - old) / 1000.0) + "秒" ); return url; } catch (IOException e) { e.printStackTrace(); } return url; }
我有一个 cs.pdf 的PDF文件,通过调用PDF 转其他文件的接口,将其转换为 Wprd 形式 。
通过访问返回的地址就可以发现,文件已经被转换为Word格式的文件啦~ 。
。
最后此篇关于用Aspose-Java免费实现PDF、Word、Excel、Word互相转换并将转换过得文件上传OSS,返回转换后的文件路径的文章就讲到这里了,如果你想了解更多关于用Aspose-Java免费实现PDF、Word、Excel、Word互相转换并将转换过得文件上传OSS,返回转换后的文件路径的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我想制作一个引用另一个 excel 文件中的单元格的公式。我已经弄清楚了,如下所示: ='C:\Users\17\Desktop\[JAN-11 2011.xlsx]1'!$H$44 但由于此工作表中
有谁知道是否可以在 Excel 中生成缺少地址门牌号的报告? 例如,我们在 Apple St (no.5, 9, 11) 有三个地址记录,是否可以生成一个报告: 列出工作簿中每条街道的所有记录街道编号
这个问题已经有答案了: VBA auto hide ribbon in Excel 2013 (7 个回答) 已关闭 4 年前。 我试图在打开工作文件时隐藏我的丝带。 我已点击以下链接,但不断收到运行
我编写了一个 VBA 程序来删除元音。我无法从 excel 调用该函数。我收到 #NAME 错误。下面的代码 Function REMOVEVOWELS(Txt) As String 'Removes
嗨,我正在尝试在 MS excel 中应用一个函数(正确函数) 但是当我编写这个函数并使用填充句柄将其复制到其他单元格时,我在所有复制的单元格中得到相同的输出。 但是当我点击单元格时,引用是好的。但结
假设我有一个格式如下的电子表格: Sheet 1 | Sheet 2 name email | name e
我正在尝试简化财务报告中的数据输入,因此我尝试使用 Excel Visual Basic 制作表格。 到目前为止我做了2个用户表单,以后我会做5个。我做了用户表单,以便数据输入运算符(operator
我需要对单元格公式而不是单元格内容执行 Mid 或 Find。 如果我的单元格公式是: =[功能](Arg1, Arg2, Arg3) 我需要能够将 Arg2 提取到另一个单元格。 如果不使用 VBA
我想用 VBA 管理嵌入在另一个 Excel 文件中的 Excel 文件。我可以使用 .docx 文档找到很多结果,但我坚持使用 .xlsx 文档。 我最后一次尝试是使用 OLE 对象,但停留在“Sa
我最近一直在尝试使用 perl 和一些模块来读取 Excel 文件,尤其是单元格的格式。 例如,我写了一段使用 ParseExcel 模块读取单元格背景颜色的 perl 代码。然而,在测试时我注意到对
我目前正在使用 Maatwebsite 的 Excel 包,并且能够很好地生成一个包含我想要的列和值的表格,但我希望能够生成表格,其他表格位于单个 Excel 工作表的下方。可能吗? 上面附上的屏幕截
我需要以下方面的指导。我有一个包含 150000 条记录的文件 (excel)。收到另一个包含 5000-6000 条记录的 excel 文件,需要根据第二个文件中信息的某些条件删除该行。 我使用字典
我有我认为的标准公式,根据我使用的 Excel 版本、Excel 365 或 Excel 2019 的不同,它的行为会有所不同 =IF(F5=$M$1;IFERROR(IF(AND(IFERROR(F
信息: 我有一个名为 Demo.xlsm 的 Excel 文件 此文件包含一个名为 UserForm1 的用户表单,该用户表单会在打开文件时自动加载。 打开文件时,名为 Demo.xlsm 的工作簿也
我在A Excel工作表中有一个列,其值是1 1 1 2 2 2 3 3 3 4 4 4....,在B Excel工作表中有另一列,其值1 2 4 ....,什么我想要的是从 B 读取值并查看它们是否
所以,我有这个问题,我想通过使用 OR 函数检查调整列的条件来找到列的平均值,我尝试将 OR 放入 AverageIf 函数,失败,还尝试了“Average(IF( OR("再次不是正确的返回。认为这
假设我想要这种类型的formula = SUM(startcell:endcell)的答案,但是startcell和endcell组件发生了变化。 因此,我希望能够使用 和 中的任何值,而不是直接在公
我正在寻找一个简单的 Excel 宏,它可以根据单元格中的特定数字/值将行从一张工作表复制到 Excel 中的另一张工作表。我有两张纸。一个称为“master”,另一个表称为“top10”。 这是数据
我正在尝试调用另一个工作簿中的 Excel 宏。它是一个特定于工作表的宏,但 Microsoft 文档和网上研究给出的语法仅提供了一种仅通过工作簿访问宏的方法。该语法是: Application.Ru
我检查了很多不同的帖子,但似乎找不到我正在寻找的确切代码。另外,我以前从未使用过 VBA,因此我尝试从其他帖子中获取代码并输入我的信息以使其正常工作。还没有运气。在工作中,我们有一个 Excel 薪资
我是一名优秀的程序员,十分优秀!