I'm trying to display a PDF as basically as possible in my Rails env. Following their docs, my Gemfile has these lines:
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
I have a wicked_pdf.rb initializer (but it's an empty hash, with a comment to the effect that I shouldn't need to specify the exe_path).
In config/initializers/mime_types.rb
, I have this:
Mime::Type.register "application/pdf", :pdf
In my Profiles controller, since all I want to do is have a page display a static PDF, I have this action:
def pdf_sample
respond_to do |format|
format.html
format.pdf do
render pdf: "pdf_sample" #, encoding: "ASCII-8BIT"
end
end
end
And my routes.rb includes this:
get 'pdf_sample', to: 'profiles#pdf_sample', as: :pdf
When I now visit /pdf_sample
it renders a blank screen, but visiting /pdf_sample.pdf
generates a ActionView::WrongEncodingError, with the following message:
Your template was not saved as valid UTF-8. Please either specify UTF-8 as the encoding for your template in your text editor, or mark the template with its encoding by inserting the following as the first line of the template:
# encoding:
<name of correct encoding\>
.
I'm not sure how to follow these instructions though - what 'template' should I put the correct encoding in? I'm trying to render the PDF directly, not wrapped in a template.
I tried adding the commented option to the render call above (opening the sample pdf in ruby and calling #encoding.to_s on its contents returned that string), but that hasn't changed the message from saying it's 'not valid UTF-8'.