mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-18 21:22:15 +01:00
feat(chromium): split filenames can be controlled with the Gotenberg-Output-Filename header - closes #1130
This commit is contained in:
@@ -409,6 +409,13 @@ func (ctx *Context) GeneratePath(extension string) string {
|
|||||||
return fmt.Sprintf("%s/%s%s", ctx.dirPath, uuid.New().String(), extension)
|
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
|
// CreateSubDirectory creates a subdirectory within the context's working
|
||||||
// directory.
|
// directory.
|
||||||
func (ctx *Context) CreateSubDirectory(dirName string) (string, error) {
|
func (ctx *Context) CreateSubDirectory(dirName string) (string, error) {
|
||||||
|
|||||||
@@ -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 {
|
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")
|
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 := chromium.Pdf(ctx, ctx.Log(), url, outputPath, options)
|
||||||
err = handleChromiumError(err, options.Options)
|
err = handleChromiumError(err, options.Options)
|
||||||
|
|||||||
@@ -582,6 +582,36 @@ Feature: /forms/chromium/convert/html
|
|||||||
Page 3
|
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)
|
Scenario: POST /forms/chromium/convert/html (Split Pages)
|
||||||
Given I have a default Gotenberg container
|
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):
|
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/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)
|
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)
|
Scenario: POST /forms/chromium/convert/html (Metadata)
|
||||||
Given I have a default Gotenberg container
|
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):
|
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s):
|
||||||
|
|||||||
@@ -676,6 +676,39 @@ Feature: /forms/chromium/convert/markdown
|
|||||||
Page 3
|
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)
|
Scenario: POST /forms/chromium/convert/markdown (Split Pages)
|
||||||
Given I have a default Gotenberg container
|
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):
|
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/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)
|
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)
|
Scenario: POST /forms/chromium/convert/markdown (Metadata)
|
||||||
Given I have a default Gotenberg container
|
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):
|
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/markdown" endpoint with the following form data and header(s):
|
||||||
|
|||||||
@@ -656,6 +656,37 @@ Feature: /forms/chromium/convert/url
|
|||||||
Page 3
|
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)
|
Scenario: POST /forms/chromium/convert/url (Split Pages)
|
||||||
Given I have a default Gotenberg container
|
Given I have a default Gotenberg container
|
||||||
Given I have a static server
|
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/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)
|
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)
|
Scenario: POST /forms/chromium/convert/url (Metadata)
|
||||||
Given I have a default Gotenberg container
|
Given I have a default Gotenberg container
|
||||||
Given I have a static server
|
Given I have a static server
|
||||||
|
|||||||
Reference in New Issue
Block a user