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 501 forks source link

How to get the page number in PDF #2233

Closed jasminesoap2222 closed 2 years ago

jasminesoap2222 commented 2 years ago

Asciidoctor enables to get the cross reference with ID and anchor https://docs.asciidoctor.org/asciidoc/latest/macros/xref/. Could you tell me the way to get the page numbers of the reference sections and appendices in the generated pdf file ?

mojavelinux commented 2 years ago

It's not possible to include the page number in the text of the xref since that information is not known at the time the xref is rendered. The converter only knows the page numbers of the sections after the title of the section has been rendered, which could be ahead of where the xref is located.

Even if we could somehow go back and insert the page numbers, doing so could affect the flow of the text and end up changing the pages those sections are on. So there's a circular dependency in the logic.

You can query the page numbers after the document is rendered for informational purposes just like the TOC does. See https://github.com/asciidoctor/asciidoctor-pdf/blob/d37f565dc2e67b15c6f0404f77eab239a69c3d4e/lib/asciidoctor/pdf/converter.rb#L3826-L3837

In the future, please direct open ended questions like this one to the project chat at https://chat.asciidoctor.org/. We are being much more strict about how the issue tracker is used so that we can better manage the project.