mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-01 22:17:29 +08:00
Fixes
This commit is contained in:
parent
6941899c74
commit
1593b0ebd4
@ -88,7 +88,7 @@ func newPdfOutlineFromDict(dict *PdfObjectDictionary) (*PdfOutline, error) {
|
||||
}
|
||||
|
||||
// Does not traverse the tree.
|
||||
func newPdfOutlineItemFromDict(dict *PdfObjectDictionary) (*PdfOutlineItem, error) {
|
||||
func (this *PdfReader) newPdfOutlineItemFromDict(dict *PdfObjectDictionary) (*PdfOutlineItem, error) {
|
||||
item := PdfOutlineItem{}
|
||||
item.context = &item
|
||||
|
||||
@ -97,6 +97,10 @@ func newPdfOutlineItemFromDict(dict *PdfObjectDictionary) (*PdfOutlineItem, erro
|
||||
if !hasTitle {
|
||||
return nil, fmt.Errorf("Missing Title from Outline Item (required)")
|
||||
}
|
||||
obj, err := this.traceToObject(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
title, ok := TraceToDirectObject(obj).(*PdfObjectString)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Title not a string (%T)", obj)
|
||||
@ -115,19 +119,42 @@ func newPdfOutlineItemFromDict(dict *PdfObjectDictionary) (*PdfOutlineItem, erro
|
||||
|
||||
// Other keys.
|
||||
if obj, hasKey := (*dict)["Dest"]; hasKey {
|
||||
item.Dest = obj
|
||||
item.Dest, err = this.traceToObject(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err := this.traverseObjectData(item.Dest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if obj, hasKey := (*dict)["A"]; hasKey {
|
||||
item.A = obj
|
||||
item.A, err = this.traceToObject(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err := this.traverseObjectData(item.A)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if obj, hasKey := (*dict)["SE"]; hasKey {
|
||||
item.SE = obj
|
||||
item.SE, err = this.traceToObject(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if obj, hasKey := (*dict)["C"]; hasKey {
|
||||
item.C = obj
|
||||
item.C, err = this.traceToObject(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if obj, hasKey := (*dict)["F"]; hasKey {
|
||||
item.F = obj
|
||||
item.F, err = this.traceToObject(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &item, nil
|
||||
|
@ -205,13 +205,11 @@ func (this *PdfReader) loadOutlines() (*PdfOutlineTreeNode, error) {
|
||||
return nil, fmt.Errorf("File need to be decrypted first")
|
||||
}
|
||||
|
||||
outlines := &PdfOutline{}
|
||||
|
||||
// Has outlines? Otherwise return an empty outlines structure.
|
||||
catalog := this.catalog
|
||||
outlinesObj, hasOutlines := (*catalog)["Outlines"]
|
||||
if !hasOutlines {
|
||||
return &outlines.PdfOutlineTreeNode, nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
common.Log.Debug("-Has outlines")
|
||||
@ -225,12 +223,12 @@ func (this *PdfReader) loadOutlines() (*PdfOutlineTreeNode, error) {
|
||||
|
||||
outlineRoot, ok := outlineRootObj.(*PdfIndirectObject)
|
||||
if !ok {
|
||||
return &outlines.PdfOutlineTreeNode, errors.New("Outline root should be an indirect object")
|
||||
return nil, errors.New("Outline root should be an indirect object")
|
||||
}
|
||||
|
||||
dict, ok := outlineRoot.PdfObject.(*PdfObjectDictionary)
|
||||
if !ok {
|
||||
return &outlines.PdfOutlineTreeNode, errors.New("Outline indirect object should contain a dictionary")
|
||||
return nil, errors.New("Outline indirect object should contain a dictionary")
|
||||
}
|
||||
|
||||
common.Log.Debug("Outline root dict: %v", dict)
|
||||
@ -254,7 +252,7 @@ func (this *PdfReader) buildOutlineTree(obj PdfObject) (*PdfOutlineTreeNode, err
|
||||
|
||||
if _, hasTitle := (*dict)["Title"]; hasTitle {
|
||||
// Outline item has a title.
|
||||
outlineItem, err := newPdfOutlineItemFromDict(dict)
|
||||
outlineItem, err := this.newPdfOutlineItemFromDict(dict)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -547,6 +547,7 @@ func (this *PdfWriter) Write(ws io.WriteSeeker) error {
|
||||
common.Log.Debug("Write()")
|
||||
// Outlines.
|
||||
if this.outlineTree != nil {
|
||||
common.Log.Debug("OutlineTree: %v", this.outlineTree)
|
||||
outlines := this.outlineTree.ToPdfObject(true)
|
||||
(*this.catalog)["Outlines"] = outlines
|
||||
err := this.addObjects(outlines)
|
||||
|
Loading…
x
Reference in New Issue
Block a user