
在 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 物件。這是一個最小的範例,由兩個帶有書籤的頁面組成。
文件outlines-example.tex
(用 plain 編譯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))