ayush rai
ayush rai

Reputation: 31

Issue with wkhtmltopdf

So in my project i when i am submitting a form i get the html to a action class and then clean it up as per my requirement and load the view form page in the backend for wkhtmltopdf to be able to convert that page into a pdf the issue i am facing is that this image is the view fomr page and the checkboxes or some other basic styling is different here expected output where as actual outputthis image here you see the differences in the pdf being generated

command used for the conversion is -

ProcessBuilder pb = new ProcessBuilder(
                "wkhtmltopdf",
                "--enable-local-file-access",
                "--disable-javascript", 
                "--cookie", "JSESSIONID", sessionId,  // Dynamically set session ID
                "--javascript-delay", "5000",
                "--page-size", "A4",
                "--zoom", "1.3",
                "--run-script", "document.getElementById('BottomButtons').style.display='none';",  // Hide buttons before rendering
                eformHtmlUrl, pdfFilePath
            );

if anyone could help me out with this it would mean alot

i tried wkhtmltoimage and chrome headless but didn't work maybe i didn't know exactly how to implement these

Upvotes: 1

Views: 33

Answers (1)

Marco Frag Delle Monache
Marco Frag Delle Monache

Reputation: 1538

Probably, it's only a matter of CSS.

Try creating a .css file with table-layout: fixed to the table class and white-space: nowrap; to the td class, like so:

table {
    table-layout: fixed;
    width: 100%;
}
td {
    white-space: nowrap;
}

and then, to your wkhtmltopdf command, add --user-style-sheet", "styles.css", like so:

ProcessBuilder pb = new ProcessBuilder(
            "wkhtmltopdf",
            "--enable-local-file-access",
            "--disable-javascript", 
            "--cookie", "JSESSIONID", sessionId,  // Dynamically set session ID
            "--javascript-delay", "5000",
            "--page-size", "A4",
            "--zoom", "1.3",
            "--user-style-sheet", "/path/to/styles.css"
            "--run-script", "document.getElementById('BottomButtons').style.display='none';",  // Hide buttons before rendering
            eformHtmlUrl, pdfFilePath
        );

Upvotes: 3

Related Questions