From 27bf973a252e822bcc921065e70d22a99f6de00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwena=C3=ABl=20MITTOUX?= <162977413+Gwenael-Mittoux@users.noreply.github.com> Date: Wed, 15 Jan 2025 09:40:40 +0100 Subject: [PATCH] fix: Fix pdf generation when no bookmark --- pkg/modules/chromium/routes.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/modules/chromium/routes.go b/pkg/modules/chromium/routes.go index eb3ee541..ad21395e 100644 --- a/pkg/modules/chromium/routes.go +++ b/pkg/modules/chromium/routes.go @@ -647,16 +647,18 @@ func convertUrl(ctx *api.Context, chromium Api, engine gotenberg.PdfEngine, url } if options.GenerateDocumentOutline { - bookmarks, errMarshal := json.Marshal(options.Bookmarks) - outputBMPath := ctx.GeneratePath(".pdf") + if len(options.Bookmarks.Bookmarks) > 0 { + bookmarks, errMarshal := json.Marshal(options.Bookmarks) + outputBMPath := ctx.GeneratePath(".pdf") - if errMarshal == nil { - outputPath, err = pdfengines.ImportBookmarksStub(ctx, engine, outputPath, bookmarks, outputBMPath) - if err != nil { - return fmt.Errorf("import bookmarks into PDF err: %w", err) + if errMarshal == nil { + outputPath, err = pdfengines.ImportBookmarksStub(ctx, engine, outputPath, bookmarks, outputBMPath) + if err != nil { + return fmt.Errorf("import bookmarks into PDF err: %w", err) + } + } else { + return fmt.Errorf("import bookmarks into PDF errMarshal : %w", errMarshal) } - } else { - return fmt.Errorf("import bookmarks into PDF errMarshal : %w", errMarshal) } }