Is Greyscale function of Wicked_PDF functional? - ruby-on-rails-3

In my project I am trying to print a PDF in Greyscale with a couple of images and text from HTML using the wicked_PDF. The Gem provides a function for the same, but it doesn't seem to be working.
Here is my code:
render :pdf => "MyObject",
:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
:template => '/widgets/pdf/show_myObject.erb',
:page_size => 'A4',
:header => { :html => { :template => "/widgets/pdf/myObject_header.erb" }},
:footer => { :html => { :template => "/widgets/pdf/myObject_footer.erb" }, :line => true },
:margin => { :top => 0, :left => 3, :right => 3 },
:greyscale => true
I am passing the images as background. But it renders in color. Am I missing something? Why is wicked_PDF gem unable to process greyscale function as expected?
Their documentation did not have any help regarding this.

Turns out the wkhtmltopdf --grayscale option was incorrectly coded in wicked_pdf as --greyscale
(swap the 'e' for an 'a').
I've pushed a fix, and cut a new version of the gem (0.7.9) for this. Thanks for pointing it out!
:grayscale => true
Now works as intended.

Related

Paperclip-av-transcoder not generating thumbnails in rails app

I am using paperclip-ac-transcoder gem for uploading videos in my rails app. Now, the videos are being successfully saved at the application path, but it's not generating the thumbnails for it. Moreover, the video_tag is not working to display the video also.
Below is my code :-
has_attached_file :movie,
:url => ":assets_host/system/:class/:attachment/:id/:style/:filename",
:path => ":rails_root/public/system/:class/:attachment/:id/:style/:filename",
:medium => { :geometry => "640x480", :format => 'mov', :streaming => true },
:thumb => { :geometry => "100x100#", :format => 'png', :time => 10 },
:processors => [:transcoder], :swallow_stderr => false
For video tag I am using the following:-
<%= video_tag "#{:rails_root}/public/system/sources/uploaded_movies/movies/10/original/MyMov.mov", :size => "320x240", :controls => true %>
Please guide.
Thanks in advance.
That was a known issue with the gem that has been fixed. Try upgrading to the latest version.

Redcarpet anchors to headers

I'm using Redcarpet gem for markdown and i wanna to generate automatic anchors for h2 titles to allow linking to each section.
show.html.erb
<div class = "content"><%= markdown(#post.body) %></div>
application_helper.rb
class HTMLwithPygments < Redcarpet::Render::HTML
def block_code(code, language)
Pygments.highlight(code, :lexer => language)
end
end
def markdown(text)
renderer = HTMLwithPygments.new(:hard_wrap => true, :with_toc_data => true)
options = {
:fenced_code_blocks => true,
:no_intra_emphasis => true,
:autolink => true,
:strikethrough => true,
:lax_html_blocks => true,
:superscript => true,
}
Redcarpet::Markdown.new(renderer, options).render(text).html_safe
end
I read about :with_toc_data => true but it doesn't works for me. I added it in options area.
I do the same thing as you describe which basically is
Redcarpet::Markdown.new(
Redcarpet::Render::HTML.new(with_toc_data: true), {}
).render(text)
My view contains the following code
- #article.description.scan(/(#+)(.*)/).each do |menu_item|
= content_tag(:a, menu_item[1], :href => "##{menu_item[1].downcase.strip.gsub(" ","-")}")
Maybe this helps.

Uploading to Rackspace Cloud Files with paperclip and fog

Can't figure out how to do this? and couldn't find much help from anywhere else!
I have set up the paperclip and fog like this;
config/initializers/fog.rb
connection = Fog::Storage.new({
:provider => 'Rackspace',
:rackspace_username => '',
:rackspace_api_key => ''
})
environment.rb;
Paperclip::Attachment.default_options.update({
:path => ":attachment/:id/:timestamp_:style.:extension",
:storage => :fog,
:fog_credentials => {
:provider => 'Rackspace',
:rackspace_username => '',
:rackspace_api_key => '',
:persistent => false
},
:fog_directory => '',
:fog_public => true
})
I am using file_field to get an image and then posting it to my controller. This gets me something like this in;
"pic"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007f90ac06a6c8 #original_filename="3245-1920x1200.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"cloth[pic][image]\"; filename=\"3245-1920x1200.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/tmp/RackMultipart20130104-5386-103laem>>}
What I can't understand is that how do I go about actually saving this file to cloud files using something like this;
file = directory.files.create(
:key => 'resume.html',
:body => File.open("/path/to/my/resume.html"),
:public => true
)
EDIT
Relevant Models;
class Cloth
include Mongoid::Document
has_many :pics
class Pic
include Mongoid::Document
include Mongoid::Paperclip
belongs_to :cloth
has_mongoid_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
And in the controller this is how I am currently creating pic based on above params;
#cloth = Cloth.new
#cloth.pics.create!(params[:cloth][:pic])
Let's step back and look at the problem from different perspective. Can you see if the following script will upload an image to your container:
require 'fog'
service = Fog::Storage.new({
:provider => 'Rackspace',
:rackspace_username => YOUR_USERNAME,
:rackspace_api_key => YOUR_API_KEY
})
container = service.directories.new(:key => YOUR_CONTAINER_NAME)
container.files.create :key => 'my-pix.jpg', :body => File.open PATH_TO_FILE
Update the uppercase parameters with the appropriate variables and let me know what happens. Hopefully this will help narrow down the problem.
Paperclip and ActiveRecord should automatically handle the file upload for you. Here is a good quick start explaining the process:
https://github.com/thoughtbot/paperclip#quick-start
If you are still having issues, can you provide me with the relevant controller and model code?

Rails 3: How can I make Paperclip-FFMPEG work?

I have Rails 3.0.3 with these gems:
delayed_job 2.1.4
delayed_paperclip 0.7.1
paperclip 2.3.16
paperclip-ffmpeg 0.7.0
(This combination is very specific. Some newer gems will not work with others.)
Here's my Video model:
class Video < Upload
has_attached_file :file, :default_style => :view, :processors => [:ffmpeg],
:url => '/system/:class/:attachment/:id/:style/:basename.:extension',
:path => ':rails_root/public/system/:class/:attachment/:id/:style' \
+ '/:basename.:extension',
:default_url => '/images/en/processing.png',
:styles => {
:mp4video => { :geometry => '520x390', :format => 'mp4',
:convert_options => { :output => { :vcodec => 'libx264',
:vpre => 'ipod640', :b => '250k', :bt => '50k',
:acodec => 'libfaac', :ab => '56k', :ac => 2 } } },
:oggvideo => { :geometry => '520x390', :format => 'ogg',
:convert_options => { :output => { :vcodec => 'libtheora',
:b => '250k', :bt => '50k', :acodec => 'libvorbis',
:ab => '56k', :ac => 2 } } },
:view => { :geometry => '520x390', :format => 'jpg', :time => 1 },
:preview => { :geometry => '160x120', :format => 'jpg', :time => 1 }
}
validates_attachment_content_type :file, :content_type => VIDEOTYPES,
:if => Proc.new { |upload| upload.file.file? }
process_in_background :file
end
When creating a new Video object with attachment, the original is saved, but no conversion will be done. Even calling Video.last.file.reprocess! won't to a thing except returning true. (Not sure what "true" means in this case as it didn't work.)
I tried hardcoding the path to ffmpeg in Paperclip::options[:command_path]. I even tried deleting the paperclip-ffmpeg.rb file and replacing it with a blank file. Really thinking I'd get an exception by doing the later, instead, I simply got "true" again.
It feels like the paperclip-ffmpeg.rb is being loaded, because it is required by config/application.rb, but nothing is called in it when trying to generate a thumbnail or convert a video.
Can anyone help me with this? Thanks in advance!
Looks like I solved this problem myself, and it was caused by something I did.
I wrote my own script to import files and the database from an older app to Rails. The files were in place, but someone I updated the database with the wrong file extensions (in this case, ".jpg" instead of ".MOV").
Paperclip will verify first to see if the original file exists before calling any processor, based on the file name stored in the database. As it didn't, Paperclip just didn't do anything. Once I had the data corrected, everything ran as expected. (I had problems with FFMPEG, but that's a different issue.)
My apologies if I wasted anyone's time. Hope this can be helpful for someone.
I use a similar configuration for one of my project (but Rails 3.1.1) and everything works fine. I added paperclip-ffmpeg to my Gemfile not with config/application.rb. Maybe this helps!?

Problem using :default => {:format => 'pdf'} in Rails 3

I want to route requests something like this: reports/bloodtypes is routed to controller reports, action bloodtypes, with format = pdf, and the route named as bloodtype_report. The Guides gives an example
match 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' }
When I do this:
match 'reports/bloodtypes' => 'reports#bloodtypes', :defaults => {:format => 'pdf'}, :as => 'bloodtype_report'
or this
match 'reports/bloodtypes' => 'reports#bloodtypes', :format => 'pdf', :as => 'bloodtype_report'
the controller still does not receive the :format => 'pdf' in params, and tries to render the report as HTML. The funny thing is that the route is shown by Rake as
bloodtype_report : /reports/bloodtypes(.:format) : {:format=>"pdf", :controller=>"reports", :action=>"bloodtypes"}
whether I use the first form (with :default) or second (just setting the format to pdf). It seems the route is correct, so why is the format parameter not being passed to the controller?
have you tried adding this to your controller:
respond_to do |format|
format.html
format.pdf { render :pdf => "show" }
end