prawnpdf / prawn

Fast, Nimble PDF Writer for Ruby
https://prawnpdf.org
Other
4.67k stars 688 forks source link

Rails 5.2.1 and Ruby 2.5.3: undefined method `mm' for 2:Integer #1089

Closed rusllonrails closed 6 years ago

rusllonrails commented 6 years ago

Hey team :wave:

Tried to use prawnpdf in new Rails 5.2.1 / Ruby 2.5.3 application. It works, but when I'm trying to use millimeters for Integer, for example:

bounding_box [60.mm, 271.mm], :width => 125.mm, :height => 15.mm do
  text "Test", :size => 12, :align => :right
end

or

move_down 2.mm

or

stroke_line 0.mm, 265.mm, 185.mm, 265.mm

I'm getting following issue:

NoMethodError: undefined method `mm' for [N]:Integer

In my Gemfile:

ruby '2.5.3'

gem 'rails', '~> 5.2.1'
gem 'prawn'
gem 'prawn-table'

In Gemfile.lock I see versions for prawn:

prawn (2.2.2)
      pdf-core (~> 0.7.0)
      ttfunk (~> 1.5)
prawn-table (0.2.2)
      prawn (>= 1.3.0, < 3.0.0)

I also tried to use another versions of Prawn and Prawn table gems.

I tested with:

gem 'prawn', '1.3.0'
gem 'prawn-table', '0.2.1'

and with:

gem 'prawn', '2.0.2'
gem 'prawn-table', '0.2.2'

Same issue.

I prepared small testing snippet which allows to test issue quicker:

require "prawn"

class Tester
  def this_works
    Prawn::Document.generate("hello.pdf") do
      text "Hello World!"
      text "What's up", :style => :bold, :size => 14
    end
  end

  def this_doesn_work
    Prawn::Document.generate("hello.pdf") do
      text "Hello World!"

      move_down 2.mm # Problem Line - causing NoMethodError: undefined method `mm' for 2:Integer

      text "What's up", :style => :bold, :size => 14
    end
  end
end

My testing output:

1) PDF generated - all good.

Tester.new.this_works
=> nil

2) Trying to add 'move_down 2.mm' and getting issue.

Tester.new.this_doesn_work
NoMethodError: undefined method `mm' for 2:Integer

Thanks in advance, appreciate any help :beer:

pointlessone commented 6 years ago

Prawn doesn't patch built-in classes by default. You need to require prawn/peasurement_extensiosn.


I will close the issue now. Feel free to reopen if you feel like you issue has not been resolved.

rusllonrails commented 6 years ago

Thanks man :+1:

You are right. :beer: Tested :heavy_check_mark: , works if I add:

require "prawn/measurement_extensions"