diff --git a/pkg/modules/api/context.go b/pkg/modules/api/context.go index 37c3a370..576c3176 100644 --- a/pkg/modules/api/context.go +++ b/pkg/modules/api/context.go @@ -409,6 +409,13 @@ func (ctx *Context) GeneratePath(extension string) string { return fmt.Sprintf("%s/%s%s", ctx.dirPath, uuid.New().String(), extension) } +// GeneratePathFromFilename generates a path within the context's working +// directory, using the given filename (with extension). It does not create +// a file. +func (ctx *Context) GeneratePathFromFilename(filename string) string { + return fmt.Sprintf("%s/%s", ctx.dirPath, filename) +} + // CreateSubDirectory creates a subdirectory within the context's working // directory. func (ctx *Context) CreateSubDirectory(dirName string) (string, error) { diff --git a/pkg/modules/chromium/routes.go b/pkg/modules/chromium/routes.go index 633c90a7..ee9c2ca1 100644 --- a/pkg/modules/chromium/routes.go +++ b/pkg/modules/chromium/routes.go @@ -601,6 +601,9 @@ func markdownToHtml(ctx *api.Context, inputPath string, markdownPaths []string) func convertUrl(ctx *api.Context, chromium Api, engine gotenberg.PdfEngine, url string, options PdfOptions, mode gotenberg.SplitMode, pdfFormats gotenberg.PdfFormats, metadata map[string]interface{}) error { outputPath := ctx.GeneratePath(".pdf") + // See https://github.com/gotenberg/gotenberg/issues/1130. + filename := ctx.OutputFilename(outputPath) + outputPath = ctx.GeneratePathFromFilename(filename) err := chromium.Pdf(ctx, ctx.Log(), url, outputPath, options) err = handleChromiumError(err, options.Options) diff --git a/test/integration/features/chromium_convert_html.feature b/test/integration/features/chromium_convert_html.feature index d136b75f..ab93e348 100644 --- a/test/integration/features/chromium_convert_html.feature +++ b/test/integration/features/chromium_convert_html.feature @@ -582,6 +582,36 @@ Feature: /forms/chromium/convert/html Page 3 """ + # See https://github.com/gotenberg/gotenberg/issues/1130. + Scenario: POST /forms/chromium/convert/html (Split Output Filename) + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s): + | files | testdata/pages-3-html/index.html | file | + | splitMode | intervals | field | + | splitSpan | 2 | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the response header "Content-Type" should be "application/zip" + Then there should be 2 PDF(s) in the response + Then there should be the following file(s) in the response: + | foo.zip | + | foo_0.pdf | + | foo_1.pdf | + Then the "foo_0.pdf" PDF should have 2 page(s) + Then the "foo_1.pdf" PDF should have 1 page(s) + Then the "foo_0.pdf" PDF should have the following content at page 1: + """ + Page 1 + """ + Then the "foo_0.pdf" PDF should have the following content at page 2: + """ + Page 2 + """ + Then the "foo_1.pdf" PDF should have the following content at page 1: + """ + Page 3 + """ + Scenario: POST /forms/chromium/convert/html (Split Pages) Given I have a default Gotenberg container When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s): @@ -704,6 +734,40 @@ Feature: /forms/chromium/convert/html Then the response PDF(s) should be valid "PDF/A-1b" with a tolerance of 1 failed rule(s) Then the response PDF(s) should be valid "PDF/UA-1" with a tolerance of 2 failed rule(s) + # See https://github.com/gotenberg/gotenberg/issues/1130. + Scenario: POST /forms/chromium/convert/html (Split & PDF/A-1b & PDF/UA-1 & Output Filename) + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s): + | files | testdata/pages-3-html/index.html | file | + | splitMode | intervals | field | + | splitSpan | 2 | field | + | pdfa | PDF/A-1b | field | + | pdfua | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the response header "Content-Type" should be "application/zip" + Then there should be 2 PDF(s) in the response + Then there should be the following file(s) in the response: + | foo.zip | + | foo_0.pdf | + | foo_1.pdf | + Then the "foo_0.pdf" PDF should have 2 page(s) + Then the "foo_1.pdf" PDF should have 1 page(s) + Then the "foo_0.pdf" PDF should have the following content at page 1: + """ + Page 1 + """ + Then the "foo_0.pdf" PDF should have the following content at page 2: + """ + Page 2 + """ + Then the "foo_1.pdf" PDF should have the following content at page 1: + """ + Page 3 + """ + Then the response PDF(s) should be valid "PDF/A-1b" with a tolerance of 1 failed rule(s) + Then the response PDF(s) should be valid "PDF/UA-1" with a tolerance of 2 failed rule(s) + Scenario: POST /forms/chromium/convert/html (Metadata) Given I have a default Gotenberg container When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s): diff --git a/test/integration/features/chromium_convert_markdown.feature b/test/integration/features/chromium_convert_markdown.feature index b6efe4a4..b8d84c28 100644 --- a/test/integration/features/chromium_convert_markdown.feature +++ b/test/integration/features/chromium_convert_markdown.feature @@ -676,6 +676,39 @@ Feature: /forms/chromium/convert/markdown Page 3 """ + # See https://github.com/gotenberg/gotenberg/issues/1130. + Scenario: POST /forms/chromium/convert/markdown (Split Output Filename) + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/markdown" endpoint with the following form data and header(s): + | files | testdata/pages-3-markdown/index.html | file | + | files | testdata/pages-3-markdown/page_1.md | file | + | files | testdata/pages-3-markdown/page_2.md | file | + | files | testdata/pages-3-markdown/page_3.md | file | + | splitMode | intervals | field | + | splitSpan | 2 | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the response header "Content-Type" should be "application/zip" + Then there should be 2 PDF(s) in the response + Then there should be the following file(s) in the response: + | foo.zip | + | foo_0.pdf | + | foo_1.pdf | + Then the "foo_0.pdf" PDF should have 2 page(s) + Then the "foo_1.pdf" PDF should have 1 page(s) + Then the "foo_0.pdf" PDF should have the following content at page 1: + """ + Page 1 + """ + Then the "foo_0.pdf" PDF should have the following content at page 2: + """ + Page 2 + """ + Then the "foo_1.pdf" PDF should have the following content at page 1: + """ + Page 3 + """ + Scenario: POST /forms/chromium/convert/markdown (Split Pages) Given I have a default Gotenberg container When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/markdown" endpoint with the following form data and header(s): @@ -820,6 +853,43 @@ Feature: /forms/chromium/convert/markdown Then the response PDF(s) should be valid "PDF/A-1b" with a tolerance of 1 failed rule(s) Then the response PDF(s) should be valid "PDF/UA-1" with a tolerance of 2 failed rule(s) + # See https://github.com/gotenberg/gotenberg/issues/1130. + Scenario: POST /forms/chromium/convert/markdown (Split & PDF/A-1b & PDF/UA-1 & Output Filename) + Given I have a default Gotenberg container + When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/markdown" endpoint with the following form data and header(s): + | files | testdata/pages-3-markdown/index.html | file | + | files | testdata/pages-3-markdown/page_1.md | file | + | files | testdata/pages-3-markdown/page_2.md | file | + | files | testdata/pages-3-markdown/page_3.md | file | + | splitMode | intervals | field | + | splitSpan | 2 | field | + | pdfa | PDF/A-1b | field | + | pdfua | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the response header "Content-Type" should be "application/zip" + Then there should be 2 PDF(s) in the response + Then there should be the following file(s) in the response: + | foo.zip | + | foo_0.pdf | + | foo_1.pdf | + Then the "foo_0.pdf" PDF should have 2 page(s) + Then the "foo_1.pdf" PDF should have 1 page(s) + Then the "foo_0.pdf" PDF should have the following content at page 1: + """ + Page 1 + """ + Then the "foo_0.pdf" PDF should have the following content at page 2: + """ + Page 2 + """ + Then the "foo_1.pdf" PDF should have the following content at page 1: + """ + Page 3 + """ + Then the response PDF(s) should be valid "PDF/A-1b" with a tolerance of 1 failed rule(s) + Then the response PDF(s) should be valid "PDF/UA-1" with a tolerance of 2 failed rule(s) + Scenario: POST /forms/chromium/convert/markdown (Metadata) Given I have a default Gotenberg container When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/markdown" endpoint with the following form data and header(s): diff --git a/test/integration/features/chromium_convert_url.feature b/test/integration/features/chromium_convert_url.feature index 7847d9d0..4c16dc25 100644 --- a/test/integration/features/chromium_convert_url.feature +++ b/test/integration/features/chromium_convert_url.feature @@ -656,6 +656,37 @@ Feature: /forms/chromium/convert/url Page 3 """ + # See https://github.com/gotenberg/gotenberg/issues/1130. + Scenario: POST /forms/chromium/convert/url (Split Output Filename) + Given I have a default Gotenberg container + Given I have a static server + When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/url" endpoint with the following form data and header(s): + | url | http://host.docker.internal:%d/html/testdata/pages-3-html/index.html | field | + | splitMode | intervals | field | + | splitSpan | 2 | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the response header "Content-Type" should be "application/zip" + Then there should be 2 PDF(s) in the response + Then there should be the following file(s) in the response: + | foo.zip | + | foo_0.pdf | + | foo_1.pdf | + Then the "foo_0.pdf" PDF should have 2 page(s) + Then the "foo_1.pdf" PDF should have 1 page(s) + Then the "foo_0.pdf" PDF should have the following content at page 1: + """ + Page 1 + """ + Then the "foo_0.pdf" PDF should have the following content at page 2: + """ + Page 2 + """ + Then the "foo_1.pdf" PDF should have the following content at page 1: + """ + Page 3 + """ + Scenario: POST /forms/chromium/convert/url (Split Pages) Given I have a default Gotenberg container Given I have a static server @@ -783,6 +814,41 @@ Feature: /forms/chromium/convert/url Then the response PDF(s) should be valid "PDF/A-1b" with a tolerance of 1 failed rule(s) Then the response PDF(s) should be valid "PDF/UA-1" with a tolerance of 2 failed rule(s) + # See https://github.com/gotenberg/gotenberg/issues/1130. + Scenario: POST /forms/chromium/convert/url (Split & PDF/A-1b & PDF/UA-1 & Output Filename) + Given I have a default Gotenberg container + Given I have a static server + When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/url" endpoint with the following form data and header(s): + | url | http://host.docker.internal:%d/html/testdata/pages-3-html/index.html | field | + | splitMode | intervals | field | + | splitSpan | 2 | field | + | pdfa | PDF/A-1b | field | + | pdfua | true | field | + | Gotenberg-Output-Filename | foo | header | + Then the response status code should be 200 + Then the response header "Content-Type" should be "application/zip" + Then there should be 2 PDF(s) in the response + Then there should be the following file(s) in the response: + | foo.zip | + | foo_0.pdf | + | foo_1.pdf | + Then the "foo_0.pdf" PDF should have 2 page(s) + Then the "foo_1.pdf" PDF should have 1 page(s) + Then the "foo_0.pdf" PDF should have the following content at page 1: + """ + Page 1 + """ + Then the "foo_0.pdf" PDF should have the following content at page 2: + """ + Page 2 + """ + Then the "foo_1.pdf" PDF should have the following content at page 1: + """ + Page 3 + """ + Then the response PDF(s) should be valid "PDF/A-1b" with a tolerance of 1 failed rule(s) + Then the response PDF(s) should be valid "PDF/UA-1" with a tolerance of 2 failed rule(s) + Scenario: POST /forms/chromium/convert/url (Metadata) Given I have a default Gotenberg container Given I have a static server