asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.14k stars 500 forks source link

Error: undefined method get_page_objects #1953

Closed eda1-fiunam closed 3 years ago

eda1-fiunam commented 3 years ago

Hi, I get such error whenever I try the next instruction in Linux:

$ asciidoctor-pdf -n -a pdf-stylesdir=resources/themes some_doc.adoc -osome_output.pdf

I've been using this program for years with the same kind of documents and this is the first time I get it. The Debian maintaner also gets it: https://github.com/prawnpdf/pdf-core/issues/46

If I remove the "-a pdf-stylesdir=resources/themes" option it works, but that's is something I need.

If I use the "--trace" option I get this:

Traceback (most recent call last): 12: from /usr/bin/asciidoctor-pdf:31:in <main>' 11: from /usr/lib/ruby/vendor_ruby/asciidoctor/cli/invoker.rb:111:ininvoke!' 10: from /usr/lib/ruby/vendor_ruby/asciidoctor/cli/invoker.rb:111:in each' 9: from /usr/lib/ruby/vendor_ruby/asciidoctor/cli/invoker.rb:128:inblock in invoke!' 8: from /usr/lib/ruby/vendor_ruby/asciidoctor/convert.rb:183:in convert_file' 7: from /usr/lib/ruby/vendor_ruby/asciidoctor/convert.rb:183:inopen' 6: from /usr/lib/ruby/vendor_ruby/asciidoctor/convert.rb:183:in block in convert_file' 5: from /usr/lib/ruby/vendor_ruby/asciidoctor/convert.rb:118:inconvert' 4: from /usr/lib/ruby/vendor_ruby/asciidoctor/document.rb:951:in convert' 3: from /usr/lib/ruby/vendor_ruby/asciidoctor-pdf/converter.rb:118:inconvert' 2: from /usr/lib/ruby/vendor_ruby/asciidoctor-pdf/converter.rb:211:in convert_document' 1: from /usr/lib/ruby/vendor_ruby/asciidoctor-pdf/prawn_ext/extensions.rb:682:indelete_page' /usr/lib/ruby/vendor_ruby/pdf/core/object_store.rb:96:in object_id_for_page': undefined methodget_page_objects' for # (NoMethodError)

This is the version I'm using under Linux Mint Cinnamon 20:

Asciidoctor PDF 1.5.0.alpha.17.dev using Asciidoctor 2.0.10 [https://asciidoctor.org] Runtime Environment (ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8)

Greetings!

mojavelinux commented 3 years ago

Asciidoctor PDF 1.5.0.alpha.17.dev

This is an unsupported version of Asciidoctor PDF. (It was released 2019). Please use one of the stable releases, ideally 1.6.0.

It's likely that a function that the alpha used is no longer available in the version of prawn/pdf-core that gets installed. But given this happens in an alpha release, and an outdated one at that, it will not be addressed.

pgeorgi commented 3 years ago

Still happens in

Asciidoctor PDF 1.6.0 using Asciidoctor 2.0.12 [https://asciidoctor.org] Runtime Environment (ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8)

Traceback (most recent call last): 14: from /usr/bin/asciidoctor:15:in <main>' 13: from /usr/lib/ruby/vendor_ruby/asciidoctor/cli/invoker.rb:113:ininvoke!' 12: from /usr/lib/ruby/vendor_ruby/asciidoctor/cli/invoker.rb:113:in each' 11: from /usr/lib/ruby/vendor_ruby/asciidoctor/cli/invoker.rb:130:inblock in invoke!' 10: from /usr/lib/ruby/vendor_ruby/asciidoctor/convert.rb:189:in convert_file' 9: from /usr/lib/ruby/vendor_ruby/asciidoctor/convert.rb:189:inopen' 8: from /usr/lib/ruby/vendor_ruby/asciidoctor/convert.rb:189:in block in convert_file' 7: from /usr/lib/ruby/vendor_ruby/asciidoctor/convert.rb:117:inconvert' 6: from /usr/lib/ruby/vendor_ruby/asciidoctor/document.rb:936:in convert' 5: from /usr/lib/ruby/vendor_ruby/asciidoctor/pdf/converter.rb:139:inconvert' 4: from /usr/lib/ruby/vendor_ruby/asciidoctor/pdf/converter.rb:215:in convert_document' 3: from /usr/lib/ruby/vendor_ruby/asciidoctor/pdf/converter.rb:598:inindent_section' 2: from /usr/lib/ruby/vendor_ruby/asciidoctor/pdf/converter.rb:277:in block in convert_document' 1: from /usr/lib/ruby/vendor_ruby/asciidoctor/pdf/ext/prawn/extensions.rb:738:indelete_page' /var/lib/gems/2.7.0/gems/pdf-core-0.9.0/lib/pdf/core/object_store.rb:96:in object_id_for_page': undefined methodget_page_objects' for # (NoMethodError)

mojavelinux commented 2 years ago

If you can provide a reproducible test case (which can either be an actual test case or instructions for how to reproduce), then please file a new issue. Otherwise, I cannot act on the report.

PeterAshfordPEL commented 2 years ago

I have a simple test case which produces this error.

make a file test.adoc with these contents:

=== TEST

<<<

Then use asciidoctor-pdf: asciidoctor-pdf test.adoc

Produces the error: undefined method `get_page_objects' for #

mojavelinux commented 2 years ago

Can you please test using the main branch? See https://github.com/asciidoctor/asciidoctor-pdf/blob/main/CONTRIBUTING-CODE.adoc#development

mojavelinux commented 2 years ago

I tried the test case and I cannot reproduce it. I still need more information, including which version of Asciidoctor PDF you are using and how you installed it.

PeterAshfordPEL commented 2 years ago

I can confirm that it works with the main branch. Thanks =)

mojavelinux commented 2 years ago

Thanks for verifying!

vboehm commented 2 years ago

This error reappeared in the current Debian version of asciidoctor-pdf.

Asciidoctor 2.0.12 [https://asciidoctor.org]
Runtime Environment (ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8)

The test file mentioned above leads to the error.

undefined method `get_page_objects' for #<PDF::Core::ObjectStore:0x000056396e664998>
  Use --trace for backtrace
mojavelinux commented 2 years ago

If you look above, you'll see that the fix is only confirmed in the main branch. So the error is not reappearing, the fix has not yet been available in a released version. If someone wants to backport the fix to 1.6.x, then I will accept it and make a new version of 1.6 available.

mojavelinux commented 2 years ago

The method get_page_objects is only provided by prawn-templates, even though it is called by pdf-core. It appears that either Debian is not packaging prawn-templates as a dependency of asciidoctor-pdf, or the version that is packaged does not provide this method. asciidoctor-pdf depends on prawn-templates ~> 0.1.0, so that must be available to use asciidoctor-pdf. Our test suite verifies this.

mojavelinux commented 2 years ago

This circular dependency entanglement was reported through the following issue in pdf-core: https://github.com/prawnpdf/pdf-core/issues/46 It is not included in a release. Which is why prawn-templates must be available as it provides this method.

mojavelinux commented 2 years ago

I can confirm from this page that the asciidoctor-pdf deb is missing the prawn-templates dependency.

https://packages.debian.org/bookworm/ruby-asciidoctor-pdf

That also means that it is not possible to import PDF pages using the block image macro. This problem is outside the scope of this project.

vboehm commented 2 years ago

After manually installing the prawn-templates

$ sudo gem install prawn-templates
Fetching prawn-templates-0.1.2.gem
Fetching ttfunk-1.7.0.gem
Successfully installed ttfunk-1.7.0
Successfully installed prawn-templates-0.1.2
Parsing documentation for ttfunk-1.7.0
Installing ri documentation for ttfunk-1.7.0
Parsing documentation for prawn-templates-0.1.2
Installing ri documentation for prawn-templates-0.1.2
Done installing documentation for ttfunk, prawn-templates after 0 seconds
2 gems installed

trying to convert the test file still exits with the error

$ asciidoctor-pdf ~/tmp/test.adoc 
undefined method `get_page_objects' for #<PDF::Core::ObjectStore:0x0000556ec02fc9a0>
  Use --trace for backtrace

Since I have no clue how to work with Ruby: Do I have to provide additional actions to fix this error?

mojavelinux commented 2 years ago

I don't recommend using sudo to install gems on top of a Linux package. That never ends well. If you can't use the Debian package, then the best approach is to install Asciidoctor PDF in user space following to advice on https://docs.asciidoctor.org/asciidoctor/latest/install/ruby-packaging/.

There's nothing I can do about the Debian package. But it would appear that the patch in the linked issue is no longer being applied. If you want to try to fix the Debian package, I would start by looking there.

Please direct follow-up questions to the project chat at https://chat.asciidoctor.org where you will be able to get support from fellow community members.

matthijskooijman commented 2 years ago

For anyone coming across this, I think this is fixed in upstream prawn pdfcore by implementing a fallback for this method when prawn-templates is not installed: https://github.com/prawnpdf/pdf-core/issues/46

That was merged last February, but it seems it is not included in the current release (ruby-pdf-core 0.9.0 from 2020) yet.

mojavelinux commented 2 years ago

You're correct. prawn-templates is a required dependency of asciidoctor-pdf, in part because it provides this method. (It also allows PDF pages to be imported using the block image macro). If the dependency is missing, then the method needs to be provided by pdf-core. The method used to be provided by pdf-core, then it was removed, then it was restored. However, as you pointed out, pdf-core hasn't been released since it was added back in.

For distributions packaging Asciidoctor PDF, they will need to apply this patch until pdf-core is released or package prawn-templates as a dependency of Asciidoctor PDF.

If there's any change you still require in Asciidoctor PDF after that, please open a new issue and we'll address it. Thanks!

keith-packard commented 2 years ago

It still seems broken -- prawn-templates replaces a file from prawn (prawn/document/internals.rb). That doesn't seem right to me.

mojavelinux commented 2 years ago

It is right. prawn-templates extends Prawn, adding additional functionality in whatever way is has to. Many prawn extensions override internals. That's just how this ecosystem is structured. These are not strict boundaries. And without prawn-templates, users will get an error when trying to convert a document that uses a PDF as the target of a block image. So prawn-templates is a hard dependency of Asciidoctor PDF as it currently stands.

keith-packard commented 2 years ago

I'd expect this overriding to be supported by some language mechanism that didn't require you to replace files delivered by one package with files delivered by another -- to make this work in Debian, I'd need to do significant work on the prawn package so that this file could be overridden -- I must support being able to install and then de-install prawn-templates without affecting any other packages.

mojavelinux commented 2 years ago

Monkeypatching (which is what it's called) is used all over Ruby. This is well within the normal mechanism of packages. We even do it in Asciidoctor PDF, a lot. It's not replacing the file itself, just the definition of the class. I don't see why any rework would be necessary...unless you're changing the package rules for hundreds of other gems.

If you want to discuss this further, please raise a question in the #asciidoctor-pdf stream of the project chat at https://chat.asciidoctor.org.

keith-packard commented 2 years ago

Thanks, I've moved the discussion over there. Would love help getting this sorted out.

Aurora12 commented 9 months ago

1.5 years after this discussion, I'm hitting the same problem. 🤷‍♂️ What is the current solution, please?

This is what I'm using:

Ubuntu 22.04.3 LTS
Asciidoctor PDF 1.6.2 using Asciidoctor 2.0.16
Runtime Environment (ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu])

I install the tools like this:

sudo apt-get update
sudo apt-get install -y imagemagick graphicsmagick asciidoctor ruby pandoc ruby-rouge ruby-asciidoctor-pdf

Should I install the tools differently? This is happening in a Github action so I can potentially change the OS image if that helps...

wmat commented 9 months ago

You'll get help quicker asking on the community Chat.

Similarly, see this thread.

mojavelinux commented 9 months ago

1.5 years after this discussion

And 1.5 years since the problem was solved. The problem is that you're using an outdated packaged version of Asciidoctor PDF that's no longer compatible with other installed gems on the version of Ubuntu you're using.

The recommended way to install Asciidoctor PDF is to get it from rubygems.org directly. That means either using gem install or bundle with a Gemfile.

Here are the workflow steps you can use in GitHub Actions to install it using gem install:

    - name: Install Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: '3.2'
        bundler-cache: false
    - name: Install Gems
      run: gem install asciidoctor-pdf
    - name: Run Application
      run: asciidoctor-pdf -v

To use Bundler instead, first create and commit a Gemfile:

source 'https://rubygems.org'

gem 'asciidoctor-pdf'

Then you can use these workflow steps:

    - name: Install Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: '3.2'
        bundler-cache: true # setup-ruby will install the gems listed in Gemfile
    - name: Run Application
      run: bundle exec asciidoctor-pdf -v

Notice when using Bundler, you usually have to prefix the command with bundle exec.

As wmat mentioned, please direct questions to the chat in the future. Since this is solved and there is no reason to keep discussing it here, I'm locking this issue to remind people.