4

I manged to get my spring boot website online on Heroku. But I also use wkhtmltopdf to create a pdf. This works locally but now I have some problems.

Offline it works as follow :

        ProcessBuilder pb = new ProcessBuilder
                ("cmd.exe",
                        "/c",
                        " cd C:\\Program Files\\wkhtmltopdf\\bin && wkhtmltopdf.exe "
                + "http://google.com C:\\MainWebApps\\TestApp\\src\\main\\resources\\userstorage\\Google2.pdf");

But how do I install this on Heroku?

Where do I store the temporarily html page so I can create a pdf from it ?

And where is wkhtmltopdf installed on Heroku ?

Can I call the wkhtmltopdf with a processbuilder on heroku?

EDIT

So after the comment of ceejayoz I googled a bit more and did find some interesting stuff.

So for Compile the binaries on Heroku I used this:

heroku run /bin/bash

Then I did a curl of wkhtmltopdf like this:

curl -O http://download.gna.org/wkhtmltopdf/0.12/0.12.0/wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz 

Then I tried to extract it on the server but without success:

 $ tar -xjvf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz
tar (child): wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2

tar: Error is not recoverable: exiting now

EDIT2

I also found this https://github.com/dscout/wkhtmltopdf-buildpack on github.

So I did following :

 heroku buildpacks:set 'https://github.com/heroku/heroku-buildpack-multi.git'
 echo 'https://github.com/dscout/wkhtmltopdf-buildpack.git' >> .buildpacks

This created a file named .buildpacks but how do I proceed from there on ?

I also found this post but vulcan is deprecated and uses ruby Using Wkhtmltopdf with Nodejs on Heroku

Can somebody provide me with good information because I am completely stuck with this?

Community
  • 1
  • 1
Greg
  • 1,690
  • 4
  • 26
  • 52
  • Googling "wkhtmltopdf heroku" shows some options. You can also just get a Linux version of the binary and commit it into your repository. – ceejayoz Nov 24 '15 at 13:54
  • @ceejayoz And how could i commit the binary into my repository and use it from there? Sorry i'm very new to this. – Greg Nov 24 '15 at 13:58
  • Just like any other file. – ceejayoz Nov 24 '15 at 14:01
  • @ceejayoz I do not understand what i'm suppose todo. So i download the binary from wkhtmltopdf. But what do i need to do from there where do i place the file ? And once i commit the file how can i use this binary online ? Do i not need to know the path like C:\\Program Files\\wkhtmltopdf\\bin && wkhtmltopdf.exe ? I also could not much information on wkhtmltopdf on heroku using java. – Greg Nov 24 '15 at 14:14

2 Answers2

0

You actually have two problems that you need to solve -

  • How to install/invoke the executable
  • How to handle the generated .pdf

Assuming you have the basics of Heroku deployment (push to the Heroku git remote), for #1, @ceejayoz is right - check the binary into your git repository. For example, under a ./bin directory. The root of your project (where the Procfile is) will be your working directory, and you should be able to invoke the program with ProcessBuilder using relative paths.

Caveat - since it looks like you are developing on Windows, you will need to pay attention to ensuring both platform-specific binaries are available, and add some logic to know which one to invoke (for example, by setting/checking a specific environment variable).

I recommend against trying to build with a custom build pack - you will spend a lot of energy for little to no benefit. Aside from the platform issue, you don't need to rebuild a third party tool when your code changes...

The second problem is that you can't leave the generated PDF in place. It will go away when the dyno is restarted (see https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem). Thus, the first thing you should do when the process completes is move the generated file to an external storage service (Amazon S3 is a good starting point).

Hope this helps.

bimsapi
  • 4,985
  • 2
  • 19
  • 27
0

You might want to use wkhtmltopdf-binary. With that solution, you do not need to put wkhtmltopdf executable into your VCS. You can use it for example with Maven or Gradle.

uwolfer
  • 4,356
  • 1
  • 25
  • 40