Skip to content

Commit a633c23

Browse files
Merge pull request #5 from fulll/shouze/feat/add_bookmarks
fix: Fix pdf generation when no bookmark
2 parents 6b0e880 + 27bf973 commit a633c23

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pkg/modules/chromium/routes.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,18 @@ func convertUrl(ctx *api.Context, chromium Api, engine gotenberg.PdfEngine, url
647647
}
648648

649649
if options.GenerateDocumentOutline {
650-
bookmarks, errMarshal := json.Marshal(options.Bookmarks)
651-
outputBMPath := ctx.GeneratePath(".pdf")
650+
if len(options.Bookmarks.Bookmarks) > 0 {
651+
bookmarks, errMarshal := json.Marshal(options.Bookmarks)
652+
outputBMPath := ctx.GeneratePath(".pdf")
652653

653-
if errMarshal == nil {
654-
outputPath, err = pdfengines.ImportBookmarksStub(ctx, engine, outputPath, bookmarks, outputBMPath)
655-
if err != nil {
656-
return fmt.Errorf("import bookmarks into PDF err: %w", err)
654+
if errMarshal == nil {
655+
outputPath, err = pdfengines.ImportBookmarksStub(ctx, engine, outputPath, bookmarks, outputBMPath)
656+
if err != nil {
657+
return fmt.Errorf("import bookmarks into PDF err: %w", err)
658+
}
659+
} else {
660+
return fmt.Errorf("import bookmarks into PDF errMarshal : %w", errMarshal)
657661
}
658-
} else {
659-
return fmt.Errorf("import bookmarks into PDF errMarshal : %w", errMarshal)
660662
}
661663
}
662664

0 commit comments

Comments
 (0)