Allow adding an external outline tree to the creator (#106)

This commit is contained in:
Adrian-George Bostan 2019-07-04 21:57:34 +03:00 committed by Gunnsteinn Hall
parent 3de3705eb2
commit 2189002435

View File

@ -54,6 +54,9 @@ type Creator struct {
// Outline.
outline *model.Outline
// External outlines.
externalOutline *model.PdfOutlineTreeNode
// Forms.
acroForm *model.PdfAcroForm
@ -70,6 +73,13 @@ func (c *Creator) SetForms(form *model.PdfAcroForm) error {
return nil
}
// SetOutlineTree adds the specified outline tree to the PDF file generated
// by the creator. Adding an external outline tree disables the automatic
// generation of outlines done by the creator for the relevant components.
func (c *Creator) SetOutlineTree(outlineTree *model.PdfOutlineTreeNode) {
c.externalOutline = outlineTree
}
// FrontpageFunctionArgs holds the input arguments to a front page drawing function.
// It is designed as a struct, so additional parameters can be added in the future with backwards
// compatibility.
@ -588,7 +598,9 @@ func (c *Creator) Write(ws io.Writer) error {
}
// Outlines.
if c.outline != nil && c.AddOutlines {
if c.externalOutline != nil {
pdfWriter.AddOutlineTree(c.externalOutline)
} else if c.outline != nil && c.AddOutlines {
pdfWriter.AddOutlineTree(&c.outline.ToPdfOutline().PdfOutlineTreeNode)
}