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

**URL:** <https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045>\
**Category:** Rails\
**Created:** [September 26, 2006, 3:32pm UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045 "2006-09-26T15:32:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![minni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@minni](https://www.ruby-forum.com/u/minni)\
**Post date:** [September 26, 2006, 3:32pm UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045/1 "2006-09-26T15:32:52Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![minni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@minni](https://www.ruby-forum.com/u/minni)\
**Post date:** [September 26, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045/2 "2006-09-26T16:37:13Z")

</div>

On 9/26/06, minni [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 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?
> 
> ```

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

## -austin

Austin Z. \* removed\_email\_address@domain.invalid \* [http://www.halostatue.ca/](http://www.halostatue.ca/)  
\* removed\_email\_address@domain.invalid \* [You are in a maze of twisty little passages, all alike. // halo • statue](http://www.halostatue.ca/feed/)  
\* removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![minni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@minni](https://www.ruby-forum.com/u/minni)\
**Post date:** [September 26, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045/3 "2006-09-26T17:07:17Z")

</div>

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 Z. ha scritto:

---

<div class="post-metadata">

**Author:** ![minni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@minni](https://www.ruby-forum.com/u/minni)\
**Post date:** [September 26, 2006, 6:55pm UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045/4 "2006-09-26T18:55:34Z")

</div>

On 9/26/06, minni [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

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

Austin Z. \* removed\_email\_address@domain.invalid \* [http://www.halostatue.ca/](http://www.halostatue.ca/)  
\* removed\_email\_address@domain.invalid \* [You are in a maze of twisty little passages, all alike. // halo • statue](http://www.halostatue.ca/feed/)  
\* removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![minni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@minni](https://www.ruby-forum.com/u/minni)\
**Post date:** [September 26, 2006, 10:28pm UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045/5 "2006-09-26T22:28:01Z")

</div>

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 Z. ha scritto:

---

<div class="post-metadata">

**Author:** ![minni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@minni](https://www.ruby-forum.com/u/minni)\
**Post date:** [September 27, 2006, 2:14am UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045/6 "2006-09-27T02:14:19Z")

</div>

On 9/26/06, Tomaso M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 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
> 
> ```

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

Austin Z. \* removed\_email\_address@domain.invalid \* [http://www.halostatue.ca/](http://www.halostatue.ca/)  
\* removed\_email\_address@domain.invalid \* [You are in a maze of twisty little passages, all alike. // halo • statue](http://www.halostatue.ca/feed/)  
\* removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![minni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@minni](https://www.ruby-forum.com/u/minni)\
**Post date:** [September 27, 2006, 8:50am UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045/7 "2006-09-27T08:50:17Z")

</div>

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

Tomaso

Austin Z. ha scritto:

---

<div class="post-metadata">

**Author:** ![minni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@minni](https://www.ruby-forum.com/u/minni)\
**Post date:** [September 27, 2006, 1:12pm UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045/8 "2006-09-27T13:12:37Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![minni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@minni](https://www.ruby-forum.com/u/minni)\
**Post date:** [September 29, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/pdf-writer-switching-to-production-trouble-on-rails/70045/9 "2006-09-29T14:30:12Z")

</div>

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)
```
