Search code examples
javaspring-bootthymeleafflying-saucer

Saving PDF's generated with flying-saucer directly to /resources or any other folder


I'am pretty new to java and spring MVC. I now can successfully create PDF Files with thymeleaf and flying-saucer like in this example: How to generate pdf Report using thymeleaf as template engine

In this example, files are stored in the local temp folder java.io.tempdir. My question is: How can i save these generated PDF's to my /resources directory or any other directory in my project?


Solution

  • In the example "out" is the path to file to be stored ,

    getClass().getClassLoader().getResource(".").getFile()

    will give resource folder location add your filename ,

    pass

    getClass().getClassLoader().getResource(".").getFile()+"/"+"yourfilename.ext"

    as "out"