There was a small issue here that made me post my first SO question. I use wkhtmltopdf to convert an HTML document to PDF as part of a Rails application. To do this, I transfer the Rails webpage to a static HTML file in the temp directory, copying the static header, footer and images to the same temp directory and then executing wkhtmltopdf using "system".
This works great in development and testing environments. In my Staging env this is not the case. At first I suspected permissions, but the first two parts of this process work (creating static HTML files and copying them to a directory). I can run wkhtmltopdf from the command line in this temporary directory and get the expected result. Finally, I ran wkhtmltopdf through the "system" and backticks through the Rails console in the middleware, and here is what I get as output:
> `wkhtmltopdf --footer-html tmp/invoices/footer.html --header-html tmp/invoices/header.html -s Letter -L 0in -R 0in -T 0.5in -B 1in tmp/invoices/test.html tmp/invoices/this.pdf` Loading pages (1/6) QPainter::begin(): Returned false ] 10% Error: Unable to write to destination Error: Failed loading page http:
Note the last bit. I point to local files, but they look for them through http. Well, I think, maybe I need to be explicit and pass the file: // protocol so that it doesn't look for http. So I try this:
> system("wkhtmltopdf --footer-html file://Library/Server/Web/Data/Sites/intranet-staging/current/tmp/invoices/footer.html --header-html file://Library/Server/Web/Data/Sites/intranet-staging/current/tmp/invoices/header.html -s Letter -L 0in -R 0in -T 0.5in -B 1in file://Library/Server/Web/Data/Sites/intranet-staging/current/tmp/invoices/test.html file://Library/Server/Web/Data/Sites/intranet-staging/current/tmp/invoices/this.pdf") Loading pages (1/6) Error: Failed loading page file:
Note that this failure occurs with the lowercase "l" in the Library. What the heck? (And no, it's best not to ignore the error with this switch.)
Any ideas? Is there a Rails or Ruby parameter that will cause system commands to be overwritten? Is there an option that I can add to wkhtmltopdf to make sure it is loaded from a local file? I'm pretty puzzled. Thanks!
source share