PDF::Writer Switching to Production Trouble (on rails)

Hello, i'm newbie for pdf::writer and also for
  rails.
  I've put PDF::Writer on rails to use rpdf views.
  All ok in development mode (with webrick), ok in
  ./script/console test, in development and also in
  production environment.
  When I switch to production environment in apache
  (fcgi mode) FPFD generate well graphics, but become
  an arror when I wrote text (perhaps for font trouble
  troble?)
ActionView::TemplateError (undefined method `[]' for nil:NilClass) on
line #15
15: pdf.add_text_wrap left_base, top-30, width, "Aula "

  I try copy environmente/development.rb to
  environmente/production.rb but all the same.
  There is some troble in fcgi mode?

  Bests, Tomaso

I'm not sure what would be causing this. Is it possible to get a more
detailed stack trace?

-austin

here the full stack trace.
If I remove all pdf.add_text_wrap commands, and I leave only draw
command (like
pdf.fill_color(Color::RGB.from_html('#E6E6E6;'))
pdf.rectangle(left, cur_y-4, 610, 15).fill
pdf.line(left+70, cur_y-4 ,left+70, cur_y+11).stroke
no error happenz

Thanks, Tomaso

ActionView::TemplateError (undefined method `[]' for nil:NilClass) on line #15 of app/views/facolta/calendario/orario_aule.rpdf:
12: #if a == 8
13: pdf.start_new_page if a>1
14: #table = PDF::SimpleTable.new
15: pdf.add_text_wrap left_base, top-30, width, "Aula #{aula} I Periodo - 2 OTTOBRE - 18 NOVEMBRE 2006", 15, :center
16: cur_y=top-60
17: (1..6).each { |g|
18: pdf.fill_color(Color::RGB.from_html('#E6E6E6;'))

/usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3/lib/pdf/writer.rb:1540:in `char_width'
/usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3/lib/pdf/writer.rb:1702:in `add_text_wrap'
/usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3/lib/pdf/writer.rb:1690:in `loop'
/usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3/lib/pdf/writer.rb:1690:in `add_text_wrap'
     #{RAILS_ROOT}/app/views/facolta/calendario/orario_aule.rpdf:15:in `render'
     #{RAILS_ROOT}/app/views/facolta/calendario/orario_aule.rpdf:9:in `each_index'
     #{RAILS_ROOT}/app/views/facolta/calendario/orario_aule.rpdf:9:in `render'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:406:in `eval'
     #{RAILS_ROOT}/vendor/plugins/pdf_render/lib/pdf_render.rb:25:in `render'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:406:in `delegate_render'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:290:in `render_template'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in `render_file'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:726:in `render_file'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:695:in `render_with_no_layout'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/layout.rb:253:in `render_without_benchmark'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `measure'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render'
#{RAILS_ROOT}/app/controllers/facolta/calendario_controller.rb:305:in `orario_aule'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `perform_action_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `measure'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process'
     /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'
     /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:150:in `process_request'
     /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:54:in `process!'
     /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in `each_cgi'
     /usr/lib/ruby/1.8/fcgi.rb:597:in `each'
     /usr/lib/ruby/1.8/fcgi.rb:597:in `each_cgi'
     /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in `process!'
     /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:23:in `process!'
     /www/http/internos/lisa/dispatch.fcgi:24

Austin Ziegler ha scritto:

What character set are you using? It appears that you have some
characters that don't have default widths defined and you need to put
them in a substitution map (see the manual for details on how the
manual added the copyright symbol, for example).

-austin

I'm using "Times-Roman", and if I wrote on
  ./script/console
  require 'pdf/simpletable'
  pdf=PDF::Writer.new
  pdf.select_font "Times-Roman"
  pdf.add_text_wrap 100, 100, 400, "Aula", 15
  pdf.render

  no error happen...
  only in production mode, on apache fcgi...
  Is possible a misconfiguration on www-user?
  PDF::Writer use some ENV variable?
  root and ww-user have same shell (bash) on /etc/passwd
  something else? Really, I've no idea...
  Trouble only on apache/fcgi... Argh!
  
  Thank you for your kind help

  Tomaso

Austin Ziegler ha scritto:

Does this specific problem test case fail in production? If it does,
it sounds like a Rails problem and I don't know what to say about it
-- PDF::Writer does not use ENV variables.

-austin

No, if I run
./script/console production
no erro happen...
Thank you anyware.

Tomaso

Austin Ziegler ha scritto:

No way!
I've decided to run application in development mode under apache/fcgi,
but using production environment, i.e. whith cahing class:
config.cache_classes = true
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
If I call development mode with other name (for example new_state),
and I correct database.yml and environments/new_state.rb the
error become like production mode....

Than I set DefaultInitEnv RAILS_ENV development and no preoblem found.
If someone know differences between devlopment status and other
status (production or elseware) tell me where I can read about it
(nothing in agile web and rail recipes)

Thank you Austin, right way is the problem in Rails...

Tomaso

minni ha scritto:

PDF::Writer do not work properly in fcgi mode, in linux.
  The trouble is in PDF::Writer::FontMetrics class that try
  to read afm in binary mode and do some operations that is
  prohibited in fcgi.
  The solution is the creation of rfm file who is only
  unmarshaled. This workaround has beautiful side effect to
  increase the performance of pdf generation.
  
  Here the snipplet (whith Times-Roman):
  cd <your application>
  ./script/console development
  >> require 'pdf/writer'
  >> p=PDF::Writer::FontMetrics.open("Times-Roman")
  >> p.save_as_rfm
  >> exit
  mv Times-Roman.afm.rfm \
    /usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3\
    /lib/pdf/writer/fonts/

  To made this for all the fonts, simply execute in console:
Dir.foreach('/usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3/lib/pdf/writer/fonts/') {|d|; if d=~/.afm$/; p=PDF::Writer::FontMetrics.open(d); p.save_as_rfm; end }
  and copy all to destination
  mv *.rfm /usr/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3\
    /lib/pdf/writer/fonts/

  Hope this is useful...

  Minni
  
  Solution to tread
  PDF::Writer Switching to Production Trouble (on rails)