Search code examples
javagwtwkhtmltopdfgxt

Previous pdf in response


I have servlet, which create html-file and then convert it to pdf-file:

private void ConvertHTMLtoPDF(String sConvertationProgramm, String sHTML, String sPDF)
{        
    try {
        ProcessBuilder pb = new ProcessBuilder(sConvertationProgramm, sHTML, sPDF);
        Process process = pb.start();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

Everything work perfect, but then I open this new (as I think) generated pdf-file from this code:

ConvertHTMLtoPDF("C:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe",
                "PDFtemplate/requiredPDF.html",
                "PDFtemplate/Report.pdf");
response.sendRedirect("PDFtemplate/Report.pdf");

- that gave me previous pdf-file, which was created before. Furthermore I've tried to open it from Windows explorer, and it's also showed me previous file every first opens.


Does anybody have any suggestion what's happen and how to solve this problem?

Any input would be greatly appreciated,
Thanks


Solution

  • You are doing response.sendRedirect("PDFtemplate/Report.pdf") after starting some process. You should wait finish of that process and only after finishing make other actions.

    Use process.waitFor();