大虾:带页码的目录 [英] Prawn: Table of content with page numbers

查看:48
本文介绍了大虾:带页码的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用 Prawn 创建一个目录.我的代码中有 add_dest 函数调用,并且目录中的正确链接:

I need to create a table of contents with Prawn. I have add_dest function calls in my code and the right links in the table of content:

add_dest('Komplett', dest_fit(page_count - 1))

text "* <link anchor='Komplett'> Vollstaendiges Mitgliederverzeichnis </link>", :inline_format = true

这有效,我得到了可点击的链接,这些链接将我转发到正确的页面.但是,我需要在目录中有页码.如何打印出来?

This works and I get clickable links which forward me to the right pages. However, I need to have page numbers in the table of content. How do I get it printed out?

推荐答案

您应该阅读本文档中关于 Outline 的章节 http://prawn.majesticseacreature.com/manual.pdf,第 96 页.它通过示例说明如何创建 TOC.

you should read the chapter on Outline in this document http://prawn.majesticseacreature.com/manual.pdf, p.96. It explains with examples on how to create TOC.

destinations, page_references = {}, {}

page_count.downto(1).each {|num| page_references[num] = state.store.object_id_for_page(num)}

dests.data.to_hash.each_value do |values|
    values.each do |value|
        value_array             = value.to_s.split(":")
        dest_name               = value_array[0]
        dest_id                 = value_array[1].split[0]
        destinations[dest_name] = Integer(dest_id)
    end 
end 

state.store.each do |reference| 
    if !(dest_name = destinations.key(reference.identifier)).nil?
        puts "Destination - #{dest_name} is on Page #{page_references.key(Integer(reference.data[0].to_s.split[0]))}"
    end 
end   

这篇关于大虾:带页码的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆