Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdf_from_string works on deployed version on heroku, but fails on local, giving empty error #605

Open
Nitsorn opened this issue Jan 5, 2017 · 6 comments

Comments

@Nitsorn
Copy link

Nitsorn commented Jan 5, 2017

Hi,
I am using the WickedPdf.new.pdf_from_string(), which works great in the deployed version, but on my local rails server, I get this error:

RuntimeError - Error: Failed to execute:
["/Users/me/.rvm/gems/ruby-2.2.1/bin/wkhtmltopdf", "-q", "--page-size", "Letter", "--margin-top", "0.1", "--margin-bottom", "0.1", "--margin-left", "0.1", "--margin-right", "0.1", "file:////var/folders/64/ltwmlbrs3tvc8kqvzrdfjvz80000gn/T/wicked_pdf20170105-82335-jgna58.html", "/var/folders/64/ltwmlbrs3tvc8kqvzrdfjvz80000gn/T/wicked_pdf_generated_file20170105-82335-3l0enx.pdf"]
Error: PDF could not be generated!
 Command Error: :
  wicked_pdf (1.0.6) lib/wicked_pdf.rb:63:in `rescue in pdf_from_string'
  wicked_pdf (1.0.6) lib/wicked_pdf.rb:66:in `pdf_from_string'

I'm using version 1.0.6, with the following in my gemfile:

gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'

Here is my controller:

pdf = WickedPdf.new.pdf_from_string(
      content,
      page_size: 'Letter',
      margin: {
        top: 0.1, left: 0.1, right: 0.1, bottom: 0.1
      }
    )

Please help. Thank you

@Nitsorn Nitsorn changed the title pdf_from_string fails on local but works on deployed version on heroku, giving empty error pdf_from_string works on deployed version on heroku, but fails on local, giving empty error Jan 5, 2017
@unixmonkey
Copy link
Collaborator

Does /Users/me/.rvm/gems/ruby-2.2.1/bin/wkhtmltopdf exist?

Does /Users/me/.rvm/gems/ruby-2.2.1/bin/wkhtmltopdf --version output anything meaningful.

The gem tries to guess where the wkhtmltopdf executable is, and should be set in the initializer like so:

WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf'
}

@Nitsorn
Copy link
Author

Nitsorn commented Jan 6, 2017

Hi,
yes, I believe it does exist. When I run which wkhtmltopdf I get /Users/me/.rvm/gems/ruby-2.2.1/bin/wkhtmltopdf. Alternatively, running atom /Users/oat/.rvm/gems/ruby-2.2.1/bin/wkhtmltopdf opens the following file:

#!/usr/bin/env ruby_executable_hooks
#
# This file was generated by RubyGems.
#
# The application 'wkhtmltopdf-binary' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
    version = $1
    ARGV.shift
  end
end

gem 'wkhtmltopdf-binary', version
load Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf', version)

However, running /Users/me/.rvm/gems/ruby-2.2.1/bin/wkhtmltopdf --version does not return anything at all.

When I run gem list, I get the following versions:

wicked_pdf (1.1.0, 1.0.6)
wkhtmltopdf-binary (0.12.3.1, 0.9.9.3)

@mbirman
Copy link

mbirman commented Jan 24, 2019

Stumbled upon this thread trying to fix a similar issue. The gem worked perfectly on local machine, but failed on production with no output at all.

I run a Rails app inside of a docker container based on alpine image. Long story short, some of the libs were missing. I figured that by executing wkhtmltopdf directly (/usr/local/bin/wkhtmltopdf in my case) and looking at the exception backtrace.

Important here is that which wkhtmltopdf will give you a different path, but it's just a wrapper and not the actual binary. Try something like wkhtmltopdf http://google.com google.pdf when you find the binary and see what happens.

@unixmonkey
Copy link
Collaborator

Thanks. There was some improvement to finding the binary in #728 that has been merged, but not yet released that might be helpful. If you could check against master and report back if that improves things in your situation, that would be helpful.

@CoolDrinELiu
Copy link

CoolDrinELiu commented May 15, 2019

@mbirman Hi, I have the same issue and can't find the solution. My case is that wkhtmltopdf located in my '/usr/local/bundle/bin/wkhtmltopdf', and when I run it '/usr/local/bundle/bin/wkhtmltopdf www.google.com google.pdf' , it will show no outputs at all.

Then I have run 'apk add wkhtmltopdf', and it's installed in /usr/bin/wkhtmltopdf

And when I use it to generate pdf, it says

Error relocating /usr/lib/libQt5Core.so.5: getentropy: symbol not found
Error relocating /usr/lib/libxshmfence.so.1: memfd_create: symbol not found

Im totally out of clue for this.

Could you tell me how did you fix that?

@gabrielrolfsen
Copy link

gabrielrolfsen commented Jun 6, 2019

I am also facing the same issue (it just works locally, does not work on Docker container).
I am running my application on an Alpine container, and the outputs of the binary files are different on my local machine and on my Docker Container:

I get this error while running on a docker container:

[wicked_pdf]: ["/usr/local/bundle/bin/wkhtmltopdf", "file:////tmp/wicked_pdf20190606-33-1hywmr7.html", "/tmp/wicked_pdf_generated_file20190606-33-1v3qhpi.pdf"]
RuntimeError: Failed to execute:
["/usr/local/bundle/bin/wkhtmltopdf", "file:////tmp/wicked_pdf20190606-33-1hywmr7.html", "/tmp/wicked_pdf_generated_file20190606-33-1v3qhpi.pdf"]
Error: PDF could not be generated!
 Command Error:
	from (irb):1

Outputs on docker:

/app # which wkhtmltopdf

/usr/local/bundle/bin/wkhtmltopdf

/app # cat $(which wkhtmltopdf)

#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'wkhtmltopdf' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../app/Gemfile",
  Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("wkhtmltopdf-binary", "wkhtmltopdf")

On my localhost:

➜  ~ which wkhtmltopdf

/Users/gabriel/.rvm/gems/ruby-2.4.0/bin/wkhtmltopdf
➜  ~ cat $(which wkhtmltopdf)

#!/usr/bin/env ruby_executable_hooks
#
# This file was generated by RubyGems.
#
# The application 'wkhtmltopdf-binary' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0.a"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
    version = $1
    ARGV.shift
  end
end

if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('wkhtmltopdf-binary', 'wkhtmltopdf', version)
else
gem "wkhtmltopdf-binary", version
load Gem.bin_path("wkhtmltopdf-binary", "wkhtmltopdf", version)
end

EDIT: just found out that it was an Alpine issue. There's an Alpine compiled binary that works well...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants