Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `downcase' for nil:NilClass #2

Closed
olegsobchuk opened this issue Oct 28, 2016 · 10 comments
Closed

NoMethodError: undefined method `downcase' for nil:NilClass #2

olegsobchuk opened this issue Oct 28, 2016 · 10 comments
Assignees

Comments

@olegsobchuk
Copy link

Hi, I've tried merge document with next steps

target = HexaPDF::Document.new
['/path/to/my/file.pdf')].each do |file|
   pdf = HexaPDF::Document.open(file)
   pdf.pages.each_page {|page| target.pages.add_page(target.import(page))}
end

target.write("merging.pdf", optimize: true)

but it raise:

NoMethodError: undefined method `downcase' for nil:NilClass
from /my/path/gems/hexapdf-0.1.0/lib/hexapdf/serializer.rb:91:in `block (2 levels) in initialize'
@gettalong gettalong self-assigned this Oct 28, 2016
@gettalong
Copy link
Owner

This should definitely not happen. However, without the source PDF I can't really do much - can you provide it?

@olegsobchuk
Copy link
Author

I've tried with different documents, all raise same error. For example I took this https://wwwimages2.adobe.com/www.adobe.com/content/dam/Adobe/ru/legal/licenses-terms/pdf/PlatformClients_PC_WWEULA-ru_RU-20150407_1357.pdf file

@gettalong
Copy link
Owner

I have tried with your provided document and it works fine. Which Ruby version are you using? Try Ruby 2.3 if you are not using it.

@olegsobchuk
Copy link
Author

olegsobchuk commented Oct 28, 2016

I'm using

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
$ rails -v
Rails 5.0.0.1

@gettalong
Copy link
Owner

Rails version should be irrelevant since the code you presented didn't have anything to do with Rails. However, if this was not the case, try using the code without Rails and see if it works then.

@gaga5lala
Copy link

I've test merge method with the file provided by @olegsobchuk at both ruby and rails environment, it's work fine.

  • ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
  • Rails 4.2.5.2

@gettalong
Copy link
Owner

@gaga5lala Thanks!

@olegsobchuk
Copy link
Author

olegsobchuk commented Oct 29, 2016

I don't know why but in HexaPDF::Serializer in initializer when I run klass.ancestors it shows me

 => [#<Module:0x00000006e79d10>,
 ActiveSupport::NumericWithFormat,
 Fixnum,
 JSON::Ext::Generator::GeneratorMethods::Fixnum,
 ActiveSupport::ToJsonWithActiveSupportEncoder,
 Integer,
 Numeric,
 Comparable,
 ActiveSupport::ToJsonWithActiveSupportEncoder,
 Object,
 PP::ObjectMixin,
 ActiveSupport::Dependencies::Loadable,
 JSON::Ext::Generator::GeneratorMethods::Object,
 ActiveSupport::Tryable,
 Kernel,
 BasicObject]

as you can see there is Module and that makes error

BTW

it works in pure ruby (in irb)

@gettalong
Copy link
Owner

Okay, so it seems we found the culprit, namely ActiveSupport prepending modules to built-in classes which shouldn't be done globally - that's what refinements are for.

@gettalong
Copy link
Owner

@olegsobchuk @gaga5lala I have updated the serialization implementation to work around this problem. Please try the code from Github and see if it works with your setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants