class Kramdown::Converter::Pdf

def create_outline(root)

Create the PDF outline from the header elements in the TOC.
def create_outline(root)
  toc = ::Kramdown::Converter::Toc.convert(root).first
  text_of_header = lambda do |el|
    if el.type == :text
      el.value
    else
      el.children.map {|c| text_of_header.call(c)}.join('')
    end
  end
  add_section = lambda do |item, parent|
    text = text_of_header.call(item.value)
    destination = @dests[item.attr[:id]]
    if !parent
      @pdf.outline.page(:title => text, :destination => destination)
    else
      @pdf.outline.add_subsection_to(parent) do
        @pdf.outline.page(:title => text, :destination => destination)
      end
    end
    item.children.each {|c| add_section.call(c, text)}
  end
  toc.children.each do |item|
    add_section.call(item, nil)
  end
end