
LuaTeX の最近のバージョンでは、PDF アウトライン階層は TeX 側から次のように設定できます\pdfextension outline
。例:
\pdfextension outline goto page \the\c@page {} count 1 {Chapter 1}
\pdfextension outline attr{/F 1} goto name{label} {Section 1.1}
これを Lua から実行したいと思います。次のようになります:
pdf.setoutlines( whatever )
…しかし、そのようなインターフェースはありません。
を使用して生の PDF オブジェクトを使用することを考えましたpdf.immediateobj
が、やり方がわかりません。その方法でこれを実現できる場合は、階層の例を示していただけますか?
答え1
はい、生の PDF オブジェクトを書き出す必要があります。以下は、ブックマークされた 2 つのページで構成される最小限の例です。
ファイルoutlines-example.tex
(プレーンでコンパイルluatex
):
This is the first page.
\vfil\break
This is the second page.
\directlua{require('outline-examples')}
\bye
ファイルoutlines-example.lua
:
-- Reserve all object numbers beforehand
local first, second, outlines =
pdf.reserveobj(), pdf.reserveobj(), pdf.reserveobj()
-- Write out the bookmarks
pdf.immediateobj(first, string.format(
'<< /Title (First page) /Parent %d 0 R /Next %d 0 R /Dest [0 /XYZ] >>',
outlines, second))
pdf.immediateobj(second, string.format(
'<< /Title (Second page) /Parent %d 0 R /Prev %d 0 R /Dest [1 /XYZ] >>',
outlines, first))
-- Write out the outline dictionary
pdf.immediateobj(outlines, string.format(
'<< /Type/Outlines /First %d 0 R /Last %d 0 R /Count 2 >>',
first, second))
-- Add the outline dictionary to the document catalog
pdf.setcatalog(string.format(
'%s /Outlines %d 0 R',
pdf.getcatalog() or '', outlines))