使用wkhtmltopdf和基于JBoss表单的身份验证

时间:2012-07-10 08:19:42

标签: java jsp pdf-generation wkhtmltopdf

我试图在JBoss和Java中使用wkhtml2pdf来创建PDF文件。我成功了,但它只从我的登录页面创建了一个PDF文件,而不是从jsp文件创建。

我读到可以添加用户名或密码等参数,这就是我所做的:

String command = applicationLocation + "wkhtmltopdf.exe " + "--post j_username=" + username +" --post j_password=" + password + " " + reqURL + "?" + reqQuery + " c:/PDF/" + folderName + "/" + id + "/" + folderName + ".pdf";

但这不会创建PDF文件,甚至不会产生错误输出。这就是我班级的样子:

public class GeneratePDF {

    String logUserId = "0";
    public String path = "c:/PDF";
    String applicationLocation = "C:\\Program Files\\wkhtmltopdf\\";

    /**
     * This method creates a command which calls wkhtmltopdf from Google in order to create a PDF file.
     * 
     * @param reqURL
     * @param reqQuery
     * @param folderName
     * @param id
     */
    public void genrateCmd(String reqURL, String username, String password, String reqQuery, String folderName, String id) {

        try {
            // make sure c:/eGP exists
            File destFoldereGP = new File("c:/eGP");
            if (destFoldereGP.exists() == false) {
                destFoldereGP.mkdirs();
                System.out.println("successfully created c:/eGP");
            }

            // make sure c:/PDF exists
            File destFolderPDF = new File("c:/PDF/");
            if (destFolderPDF.exists() == false) {
                destFolderPDF.mkdirs();
                System.out.println("successfully created c:/PDF");
            }

            // make sure c:/PDF/foldername exists
            File destFolder = new File("c:/PDF/" + folderName);
            if (destFolder.exists() == false) {
                destFolder.mkdirs();
                System.out.println("successfully created c:/PDF/foldername");
            }

            // make sure c:/PDF/foldername/id exists
            File destFolder2 = new File("c:/PDF/" + folderName + "/" + id);
            if (destFolder2.exists() == false) {
                destFolder2.mkdirs();
                System.out.println("successfully created c:/PDF/foldername/id");
            }

            //For Image change 'wkhtmltopdf.exe' to 'wkhtmltoimage.exe' and '.pdf' to '.jpeg'
            String command = applicationLocation + "wkhtmltopdf.exe " + "--post j_username=" + username +" --post j_password=" + password + " " + reqURL + "?" + reqQuery + " c:/PDF/" + folderName + "/" + id + "/" + folderName + ".pdf";
            System.out.println("Command to create PDF: " + command);
            Runtime.getRuntime().exec(command);

            System.out.println("Successfully created a new PDF file.");
        } catch (IOException e1) {
            System.out.println("Exception: " + e1);
        } catch (Exception e) {
            System.out.println("Exception: " + e);
        }
    }
}

知道如何在JBoss中使用wkhtml2pdf和基于表单的身份验证创建PDF吗? 非常感谢。

0 个答案:

没有答案