Nothing Special   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
Fix #448
Browse files Browse the repository at this point in the history
  • Loading branch information
hhrutter committed Apr 21, 2023
1 parent e560c3e commit 73c50d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/api/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
// AddBookmarks adds a single bookmark outline layer to the PDF context read from rs and writes the result to w.
func AddBookmarks(rs io.ReadSeeker, w io.Writer, bms []pdf.Bookmark, conf *model.Configuration) error {

// Note: Existing bookmarks will be replaced.

if conf == nil {
conf = model.NewDefaultConfiguration()
} else {
Expand Down Expand Up @@ -69,6 +71,9 @@ func AddBookmarks(rs io.ReadSeeker, w io.Writer, bms []pdf.Bookmark, conf *model

// AddBookmarksFile adds a single bookmark outline layer to the PDF context read from inFile and writes the result to outFile.
func AddBookmarksFile(inFile, outFile string, bms []pdf.Bookmark, conf *model.Configuration) (err error) {

// Note: Existing bookmarks will be replaced.

var f1, f2 *os.File

if f1, err = os.Open(inFile); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/test/bookmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
// Mac Preview limitations: does not render color, style, outline tree collapsed by default.

func TestAddSimpleBookmarks(t *testing.T) {
// Note: Existing bookmarks will be overwritten.
msg := "TestAddSimpleBookmarks"
inFile := filepath.Join(inDir, "CenterOfWhy.pdf")
outFile := filepath.Join("..", "..", "samples", "bookmarks", "bookmarkSimple.pdf")
Expand Down
6 changes: 2 additions & 4 deletions pkg/pdfcpu/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,13 @@ func createOutlineItemDict(ctx *model.Context, bms []Bookmark, parent *types.Ind
// AddBookmarks adds bms to ctx.
func AddBookmarks(ctx *model.Context, bms []Bookmark) error {

// Note: Existing bookmarks will be replaced.

rootDict, err := ctx.Catalog()
if err != nil {
return err
}

if _, ok := rootDict.Find("Outlines"); ok {
return errExistingBookmarks
}

outlinesDict := types.Dict(map[string]types.Object{"Type": types.Name("Outlines")})
outlinesir, err := ctx.IndRefForNewObject(outlinesDict)
if err != nil {
Expand Down

0 comments on commit 73c50d3

Please sign in to comment.