【问题标题】:how to convert multiple file into PDF [duplicate]如何将多个文件转换为PDF [重复]
【发布时间】:2019-09-02 18:23:39
【问题描述】:

我正在尝试将文件夹中的 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。然后重复下一个文件。

【问题讨论】:

    标签: java itext pdf-generation


    【解决方案1】:
    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)的方法中。

    【讨论】:

    • 方法getAllFilesFromFolder()从何而来?
    • @ErwinBolwidt 我编辑了我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 2016-08-16
    • 2015-02-14
    • 1970-01-01
    • 2012-08-05
    相关资源
    最近更新 更多