Настройка PDF-контуров из Lua

Настройка PDF-контуров из Lua

В последних версиях 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 raw с помощью pdf.immediateobj, но не знаю, как это сделать. Если это возможно сделать таким образом, не могли бы вы показать пример иерархии?

решение1

Да, вам придется выписывать объекты raw 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))

Связанный контент