I'm having this error when I try to use wicked_pdf:
irb: No such file or directory - which wkhtmltopdf
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.chomp
from C:/Ruby187/lib/ruby/gems/1.8/gems/wicked_pdf-0.7.2/lib/wicked_pdf.r
b:19:in `initialize'
from (irb):2:in `new'
from (irb):2
from :0
I think the path to wkhtmltopdf should be configured. But how?
Provide sth like
:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf', # path to binary
with your render call and make sure, that a wkhtmltopdf binary resides at that path.
(You can get wkhtmltopdf from google code in case you have not installed it yet)
According to the sources, simply add it to your $PATH (the folder containing the binary).
Wkhtmltopdf project can't be found on Google Code any longer. It was moved to http://wkhtmltopdf.org/downloads.html
In my case, I just had to download the OSX binary and it was automatically added to my PATH variable.
Create an initializer: config/initializers/wicked_pdf.rb:
WickedPdf.config = {
:exe_path => "#{ENV['GEM_HOME']}/bin/wkhtmltopdf"
}
:exe_path should hold the path to the wkhtmltopdf binary. For my instance, I used the gem:
gem "wkhtmltopdf-binary"
Which stored the binary in my GEM_HOME, so I could reference a path that wasnt hard coded.
Related
The command run the following :
C:\V4\framework\scripts > ruby SCM.rb
The error I get is the following :
C:/Rubby/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in require: 126: The specified module could not be found. - C:/Rubby/lib/ruby/gems/2.4.0/gems/win32-api-1.4.8-x86-mingw32/lib/win32/ruby19/win32/api.so (LoadError)
from C:/Rubby/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Rubby/lib/ruby/gems/2.4.0/gems/win32-api-1.4.8-x86-mingw32/lib/win32/api.rb:2:in
The first few lines of the calling script looks like following :
require 'watir/win32ole'
require 'windows/com'
require 'windows/window/message'
The second line is giving the Load Error. I googled and am not able to find a solution.
I have faced the same issue , I got resolved this by download the zip file of api.dll from https://www.dll-files.com/api.dll.html and extract the zip file and then paste the 'api.dll' inside my ruby bin folder : "C:\Ruby22\bin
I am trying to use pdf generator in my rails 2.3app. It is working fine
in my local machine and pdf is generating. In my production server (nginix) it is not working and shows the error:
"wkhtmltopdf RuntimeError (Location of wkhtmltopdf unknown)"
In the config/initializers/wicked_pdf.rb.example file I have mentioned the path to the binary exe file as:
WickedPdf.config = {
:wkhtmltopdf => '/opt/wkhtmltopdf-amd64',
:layout => 'pdf.html'
:header => {:html => {:template=> 'layouts/pdf_header.html'}}
}
And in the opt folder there is wkhtmltopdf-amd64 binary exe file.
:wkhtmltopdf => '/opt/wkhtmltopdf-amd64',
This is your system opt folder, check whether this folder has permission to execute the binary.
Alternatively change the location of wkhtmltopdf into your rails application by extracting it to /path/to/rails_app/bin
and then change your initializer to :wkhtmltopdf => Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
can we replace the path with installed gem at gemset?
At terminal just check 'which wkhtmltopdf' is installed in our app gemset path.Then replace the path your wkhtmltopdf initializer with that.
I just switched from a paperclip rails plugin to a paperclip gem. The project is a rails 2.3 application and I am using paperclip 2.7.2 gem.
I am getting the following odd error:
identify: unable to open image `file': No such file or directory # error/blob.c/OpenBlob/2617.
identify: no decode delegate for this image format `file' # error/constitute.c/ReadImage/544.
Seems like paperclip is looking for a file called 'file' but I am not sure why. I didn't change any of the code we had before. It used to work, all I did was upgrade to a newer version and use a gem over a plugin.
Any ideas?
Update
It to be a bug in paper clip where it does not parse the content of the command properly. I dug deep into the paperclip source to find:
def run(cmd, arguments = "", local_options = {})
if options[:image_magick_path]
Paperclip.log("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead")
end
command_path = options[:command_path] || options[:image_magick_path]
Cocaine::CommandLine.path = [Cocaine::CommandLine.path, command_path].flatten.compact.uniq
local_options = local_options.merge(:logger => logger) if logging? && (options[:log_command] || local_options[:log_command])
Cocaine::CommandLine.new(cmd, arguments, local_options).run
end
and
# Uses ImageMagick to determing the dimensions of a file, passed in as either a
# File or path.
# NOTE: (race cond) Do not reassign the 'file' variable inside this method as it is likely to be
# a Tempfile object, which would be eligible for file deletion when no longer referenced.
def self.from_file file
file_path = file.respond_to?(:path) ? file.path : file
raise(Paperclip::NotIdentifiedByImageMagickError.new("Cannot find the geometry of a file with a blank name")) if file_path.blank?
geometry = begin
Paperclip.run("identify", "-format %wx%h :file", :file => "#{file_path}[0]")
rescue Cocaine::ExitStatusError
""
rescue Cocaine::CommandNotFoundError => e
raise Paperclip::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
parse(geometry) ||
raise(NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command."))
end
The Paperclip.run command fails to replace the :file placeholder for some reason. I verified this by running the following on the commandline:
identify :file
Monkey patching the replacement by hand yields other errors where a similar thing happens.
Ok I managed to solve it.
It was a problem with Cocaine. Seems paperclip has a dependency on cocaine that only says it must be Cociane > 0.02. The latest version of Cocaine 0.4.2 (at the time of this writing) has a new API which is not backward compatible. You need to downgrade to Cocaine 0.3.2.
Simply put this in your Gemfile before paperclip:
gem "cocaine", "0.3.2"
I'm running Rails on Windows and installed wkhtmltopdf(path - C:\Users\User\local\bin). I'm trying to configure it using documentation - https://github.com/pdfkit/pdfkit#configuration. But it gives me errors about path.
I create pdfkit.rb file in initializers folder and wrote this:
PDFKit.configure do |config|
config.wkhtmltopdf = "C:Users/User/local/bin"
config.default_options = {
:page_size => 'Legal',
:print_media_type => true
}
end
but it gives me error
No wkhtmltopdf executable found at C:Users/User/local/bin
>> Please install wkhtmltopdf - https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF
You need to specify the whole executable path and put a slash after C:
The path should look like: C:/Users/User/local/bin/wkhtmltopdf.exe consider also that you may use backslash \ instead of slash / in Windows
I'm working with Ruby on rails 2.3.8, NetBeans IDE.
I've installed paperclip and I could show/save images successfully. Now, I've installed ImageMagick-6.6.2-4-Q16(for windows 7, 64bits).
Until that moment, my model looked like this(and worked fine):
has_attached_file :photo
Now, after installing ImageMagick, when I add the :style line it fails:
has_attached_file :photo,
:styles => {:thumb => "100x100#", :small => "150x150>", :large => "400x400>" }
and it throws the following error message when I try to upload an image:
TypeError in ProfilesController#update
backtrace must be Array of String
The only thing I'm doing in the update action of that controller is the following:
#profile.update_attributes(params[:profile])
#profile.update_attribute(:photo, params[:profile][:photo])
I've also installed miniMagick gem(because I read somewhere I had to do it).
What am I missing?
I'll show you what it worked for us:
There is a name conflict with "convert" command. Paperclips tries to run "convert" as is, but this command is already included in the Windows installations as a filesystem converter (FAT to NTFS or something).
If you try to run "convert" from command line, probably will run the mentioned converter instead of imagemagick's "convert"
It depends on the PATH environment variable.
If we set imagemagick's path FIRST in the PATH variable it will resolve this path first, so the windows' command won't be executed.
In order to fix it on our rails application, we added
...
if Sys::Uname.sysname == "Linux"
...
else
....
ENV['PATH'] = Paperclip.options[:command_path] + ";" + ENV['PATH']
end
...
on production.rb
Try to download the paperclip version 2.3.1.1, higher versions failed to me.