-2

I'm trying to convert a list a file Informix4gl report file in a folder into PDF file.

I'm using java with iText to convert the file. I've only succeeded converting one file at the moment. This is how I get the file from a folder.

    //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";

Problem with this is, I have to define the input file name and output file name in the code. What i wanted to do is add loop so that the program automatically get file one from the folder and convert to PDF. Then repeat for the next file.

1 Answers1

0
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());
}

We will loop all files in the folder, then put it to your method that need two params (sourceFile, destinationFile).

KyHuynh
  • 23
  • 5