Hi. I'm rather confused. I looked at the code and what I'm reporting here makes absolutely no sense to me, but I'm doing it anyway, as I believe I have no other option.
So, it seems to be impossible to reach any node within the document outline, below the toplevel nodes. This is the code I'm using to test it:
<pre>
require 'rubygems'
require 'poppler'
doc = Poppler::Document.new("example.pdf")
def print_tree(iter)
puts iter.action.title
if child = iter.child
puts "desc"
print_tree(iter)
end
if iter.next
puts "next"
print_tree(iter)
end
end
print_tree(doc.index_iter)
</pre>
My test document (actually mirror.ctan.org/biblio/bibtex/utils/alphabib/example.pdf) has one toplevel node, with several children. The code above though, prints the toplevel node until SystemStackError occurs. The child nodes are never accessed.
To verify that my understanding of the Poppler API is correct, I tried the same in python:
<pre>
import poppler
doc = poppler.document_new_from_file("file:///home/nilclass/poppler-bug/example.pdf", "")
def print_tree(iter):
print iter.get_action().title
child = iter.get_child()
if(child):
print "desc"
print_tree(child)
if(iter.next()):
print "next"
print_tree(iter)
print_tree(poppler.IndexIter(doc))
</pre>
This works as expected, so I believe the error is somewhere within the ruby bindings.
Versions:
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
poppler 0.16.4 (ubuntu packages libpoppler13 and libpoppler-glib6)
poppler gem 0.90.9
Anyway, thank's a lot for all the rest of ruby-gnome that works wonderfully :)
this is bullshit. I had an obvious error in my code, so here's the new version:
require 'rubygems'
require 'poppler'
doc = Poppler::Document.new("example.pdf")
def print_tree(iter)
puts iter.action.title if iter.action
if child = iter.child
puts "desc"
print_tree(child)
end
if iter.next
puts "next"
print_tree(iter)
end
end
print_tree(doc.index_iter)
The error described above was obviously an error in my code, but what I'm experiencing now is, that within all second-level nodes the "action" method returns nil (hence the added check). All nodes are visited ("desc"/"next" printed as expected), though the action is empty. Needless to say - I'm even more confused than before.
Sorry for the mess.
Could you give us an example PDF?
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
I am having this problem as well. Is this a confirmed bug ? Tried different iterations of the code below, but was only able to get the main chapters
http://stackoverflow.com/questions/8484426/ruby-poppler-pdf-table-of-contents-index
It's not a confirmed bug yet. Could you also give us an example PDF?