PDF generation with princely under Ruby 1.9
Under Ruby 1.9, princely fails to generate a pdf with the following error:
ArgumentError (invalid byte sequence in UTF-8)
The solution seems to be forcing binary encoding of the data you pass into the send_data method used by princely:
def make_and_send_pdf(pdf_name, options = {})
send_data(
make_pdf(options).force_encoding('BINARY'),
:filename => pdf_name + ".pdf",
:type => 'application/pdf'
)
end
I’m not sure whether this is the best solution but it worked. Another solution used ASCII-8BIT instead of BINARY.
Specific versions: Ruby 1.9.2, Rails 2.3.10, Prince 6, Princely 1.2.5