java - 如何将多个文件转换为PDF
问题描述
我正在尝试将文件夹中的 Informix4gl 报告文件列表转换为 PDF 文件。
我正在使用 java 和 iText 来转换文件。我目前只成功转换了一个文件。这就是我从文件夹中获取文件的方式。
//File directory
public static final String TEXT
= "O:\\CONVERT\\FOLDER ORI\\BL2054.801";
//Where file will be stored after conversion
public static final String DEST
= "O:\\CONVERT\\FOLDER PDF\\BL2054.801.pdf";
问题是,我必须在代码中定义输入文件名和输出文件名。我想要做的是添加循环,以便程序自动从文件夹中获取文件一并转换为 PDF。然后重复下一个文件。
解决方案
getPathFilesFromFolder().stream().forEach({
file -> convertToPdf(file, generateDestinationPathFile(file))
//convertToPdf is a method from your lib
})
generateDestinationPathFile(File file) {
// rename file
}
List<Path> getPathFilesFromFolder() throws IOException {
return Files.list(Paths.get("D:\\Example"))
.collect(Collectors.toList());
}
我们将循环文件夹中的所有文件,然后将其放入需要两个参数(sourceFile、destinationFile)的方法中。
推荐阅读
- ios - 关闭应用程序时不处理深度链接 React Native iOS 应用程序
- php - PHP中的“无效代码单元序列”实际上是什么意思?htmlspecialchars() 中的“无效代码单元序列”如何工作?需要它的例子
- java - KeycloakSecurityContext 在 SpringBoot 中返回 null
- r - 缩小绘图宽度,为 ggrepel 标签腾出更多空间
- python - 检查字符串在Python中是否为某种格式
- ansible - Ansible 没有在清单/主机文件中进行更改
- python - 使用 Quine-McCluskey 算法后如何使用 XOR 进行简化?
- selenium - 如何为 img src 编写动态 xpath
- asp.net-mvc-4 - Host\Servername$ 登录失败
- google-earth-engine - 在谷歌地球引擎的 imageCollection 中对 2 个连续图像应用函数