Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8103729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:38:09+00:00 2026-06-05T23:38:09+00:00

I know more or less how to do this, but I think I’m getting

  • 0

I know more or less how to do this, but I think I’m getting burned by the complexity of this command due to inexperience.

I’m trying to feed some raw html into wkhtmltopdf. I can do this from the command line like this:

echo "<p>Hello</p>" | wkhtmltopdf - ~/somePdf.pdf

That works fine, but how do I do this from a Java app? Here’s a couple things I’ve tried:

String[] cmd = { "echo", html.body(), "|", "wkhtmltopdf", "-", "/home/sam/yourPdf.pdf" };
Runtime.getRuntime().exec(cmd);

OR

Runtime.getRuntime().exec("echo " + html.body() + " | wkhtmltopdf - /home/sam/yourPdf.pdf");

Neither one of these produces a file in my home folder.

I’ve read that wkhtmltopdf will output to STDERR, but I’m not sure how to view that from Eclipse. I was told it should be available in my Console view, but I don’t see anything there.

Any help is appreciated, thanks!

Edit

The accepted answer will work for wkhtmltopdf, but for anyone else using the Play! framework who finds this post, there is a Play! module that generates a PDF based on a scala template. It works really well, but don’t forget to set media="print" in your stylesheet 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:38:11+00:00Added an answer on June 5, 2026 at 11:38 pm

    You cannot do this directly, because you are running two commands and you create a pipe. Neither the Runtime.exec() nor the ProcessBuilder.command() methods are made for this. The easiest way to still achieve something akin to this from Java is to put all that stuff into a shell script and call that script with Runtime.exec() .

    EDIT:
    You can also skip the shell script and call

    Runtime.getRuntime().exec( new String[] { "bash", "-c", "\"echo \"<p>Hello</p>\ | wkhtmltopdf - ~/somePdf.pdf\""} );
    

    That save you writing the shell script, but you may have to fiddle with the quotes a little to get it right.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there is this post , but I still want to know more
Alright I know this is more than likely a amateur question but I have
I know that being open source does not necessarily makes a program more/less secure
I am very novice in directx and want to know more, I was trying
I want to know this more in detail. Is it a realtime scheduler? An
I know that there are more practical ways of going about what I'm trying
I am trying to (more or less) uniquely identify a system for licensing purposes.
I have asked aqbout timezones and date/time before but this is a more specific
This question is more or less programming language agnostic. However as I'm mostly into
I think I already know the answer, but I'm going to ask the question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.