3

I have a problem with the pdf-writer gem on a collaborative project I'm trying to run, I'm using RVM, Ruby 1.9.2p180, Rails 3.1.0 on Ubuntu 10.10.

I created a new gemset to install the required gems with Bundler, but when I try to run the app I get the fallowing error;

josethernandezc@DG965WH:~/Desktop/conest31$ rails s
/home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require': /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:712: invalid multibyte char (US-ASCII) (SyntaxError)
/home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:712: invalid multibyte char (US-ASCII)
/home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:712: syntax error, unexpected $end, expecting keyword_end
content = "%PDF-#{@version}\n%âãÏÓ\n"
                                ^
from /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'
from /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency'
from /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /home/josethernandezc/Desktop/conest31/config/application.rb:58:in `<top (required)>'
from /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/railties-3.1.0/lib/rails/commands.rb:52:in `require'
from /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/railties-3.1.0/lib/rails/commands.rb:52:in `block in <top (required)>'
from /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/railties-3.1.0/lib/rails/commands.rb:49:in `tap'
from /home/josethernandezc/.rvm/gems/ruby-1.9.2-p180@conest31/gems/railties-3.1.0/lib/rails/commands.rb:49:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

The problem is in the pdf-writer-1.1.8/lib/pdf/writer.rb:712, especifically; content = "%PDF-#{@version}\n%âãÏÓ\n"

Any suggestions would be great, I tried to Google the error but I have not found anything specific to pdf-writer....

josethernandezc
  • 160
  • 2
  • 12
  • Have a look at http://stackoverflow.com/questions/5359928/make-ruby-1-9-regard-all-source-files-to-be-utf-8-encoded-even-if-recompiling – Markus Jarderot Jan 27 '12 at 15:37
  • I fallowed your advice and it works... partially, I don't know is it is because I'm using RVM but I have to `export RUBYOPT=-Ku` everytime I want to run the app, and what's worst I can't generate any new controllers or models trough the terminal because if the same error no matter if I export either. Any suggestions? – josethernandezc Jan 30 '12 at 16:50
  • I don't know. Try searching for other similar questions. – Markus Jarderot Jan 30 '12 at 19:29
  • I solved this problem a long time ago but forgot to post an answer, there is a folder for each gemset within the RVM file system and in that folder there is a configuration file with all the info of the gemset, add the `export RUBYOPT=-Ku` command and you are good to go, this solves even the `create` and `destroy` commands as well – josethernandezc May 04 '12 at 18:42

3 Answers3

3

pdf-writer is not compatible with Ruby 1.9. There is a fork which is: https://github.com/metaskills/pdf-writer

Change the pdf-writer line in your Gemfile for:

gem 'pdf-writer', :git => 'git://github.com/metaskills/pdf-writer.git'
Alex D
  • 29,755
  • 7
  • 80
  • 126
1

I just ported pdf-writer to Ruby 2.0. Pull request sent to metaskills (referenced in previous answer).

If you need it for Ruby 2.0 in the meantime, please find the forked code here:

gem 'pdf-writer', :git => 'git://github.com/mwlang/pdf-writer.git'
Michael Lang
  • 1,028
  • 12
  • 21
1

The fork of pdf-writer also works on Ruby 2.1, thanks.

gem 'pdf-writer', :git => 'git://github.com/mwlang/pdf-writer.git'
mabahamo
  • 684
  • 10
  • 10