1

JBoss with Java で wkhtml2pdf を使用して PDF ファイルを作成しようとしています。私は成功しましたが、jsp ファイルからではなく、ログイン ページからのみ PDF ファイルを作成します。

ユーザー名やパスワードなどのパラメーターを追加できることを読みましたが、これが私がしたことです:

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を作成する方法はありますか? どうもありがとう。

4

0 に答える 0