mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 04:32:15 +01:00
fix(libreoffice): accept PDF/A-1b instead of PDF/A-1a (#751)
This commit is contained in:
@@ -734,7 +734,7 @@ func TestConvertUrl(t *testing.T) {
|
|||||||
engine: &gotenberg.PdfEngineMock{ConvertMock: func(ctx context.Context, logger *zap.Logger, formats gotenberg.PdfFormats, inputPath, outputPath string) error {
|
engine: &gotenberg.PdfEngineMock{ConvertMock: func(ctx context.Context, logger *zap.Logger, formats gotenberg.PdfFormats, inputPath, outputPath string) error {
|
||||||
return nil
|
return nil
|
||||||
}},
|
}},
|
||||||
pdfFormats: gotenberg.PdfFormats{PdfA: gotenberg.PdfA1a},
|
pdfFormats: gotenberg.PdfFormats{PdfA: gotenberg.PdfA1b},
|
||||||
options: DefaultOptions(),
|
options: DefaultOptions(),
|
||||||
expectError: false,
|
expectError: false,
|
||||||
expectHttpError: false,
|
expectHttpError: false,
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ type Options struct {
|
|||||||
// Optional.
|
// Optional.
|
||||||
PageRanges string
|
PageRanges string
|
||||||
|
|
||||||
// PdfFormats allows to convert the resulting PDF to PDF/A-1a, PDF/A-2b,
|
// PdfFormats allows to convert the resulting PDF to PDF/A-1b, PDF/A-2b,
|
||||||
// PDF/A-3b and PDF/UA.
|
// PDF/A-3b and PDF/UA.
|
||||||
// Optional.
|
// Optional.
|
||||||
PdfFormats gotenberg.PdfFormats
|
PdfFormats gotenberg.PdfFormats
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ func (p *libreOfficeProcess) pdf(ctx context.Context, logger *zap.Logger, inputP
|
|||||||
|
|
||||||
switch options.PdfFormats.PdfA {
|
switch options.PdfFormats.PdfA {
|
||||||
case "":
|
case "":
|
||||||
case gotenberg.PdfA1a:
|
case gotenberg.PdfA1b:
|
||||||
args = append(args, "--export", "SelectPdfVersion=1")
|
args = append(args, "--export", "SelectPdfVersion=1")
|
||||||
case gotenberg.PdfA2b:
|
case gotenberg.PdfA2b:
|
||||||
args = append(args, "--export", "SelectPdfVersion=2")
|
args = append(args, "--export", "SelectPdfVersion=2")
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ func TestLibreOfficeProcess_pdf(t *testing.T) {
|
|||||||
expectError: false,
|
expectError: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
scenario: "success (PDF/A-1a)",
|
scenario: "success (PDF/A-1b)",
|
||||||
libreOffice: newLibreOfficeProcess(
|
libreOffice: newLibreOfficeProcess(
|
||||||
libreOfficeArguments{
|
libreOfficeArguments{
|
||||||
binPath: os.Getenv("LIBREOFFICE_BIN_PATH"),
|
binPath: os.Getenv("LIBREOFFICE_BIN_PATH"),
|
||||||
@@ -417,7 +417,7 @@ func TestLibreOfficeProcess_pdf(t *testing.T) {
|
|||||||
|
|
||||||
return fs
|
return fs
|
||||||
}(),
|
}(),
|
||||||
options: Options{PdfFormats: gotenberg.PdfFormats{PdfA: gotenberg.PdfA1a}},
|
options: Options{PdfFormats: gotenberg.PdfFormats{PdfA: gotenberg.PdfA1b}},
|
||||||
cancelledCtx: false,
|
cancelledCtx: false,
|
||||||
start: true,
|
start: true,
|
||||||
expectError: false,
|
expectError: false,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func (engine *LibreOfficePdfEngine) Merge(ctx context.Context, logger *zap.Logge
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert converts the given PDF to a specific PDF format. Currently, only the
|
// Convert converts the given PDF to a specific PDF format. Currently, only the
|
||||||
// PDF/A-1a, PDF/A-2b, PDF/A-3b and PDF/UA formats are available. If another
|
// PDF/A-1b, PDF/A-2b, PDF/A-3b and PDF/UA formats are available. If another
|
||||||
// PDF format is requested, it returns a [gotenberg.ErrPdfFormatNotSupported]
|
// PDF format is requested, it returns a [gotenberg.ErrPdfFormatNotSupported]
|
||||||
// error.
|
// error.
|
||||||
func (engine *LibreOfficePdfEngine) Convert(ctx context.Context, logger *zap.Logger, formats gotenberg.PdfFormats, inputPath, outputPath string) error {
|
func (engine *LibreOfficePdfEngine) Convert(ctx context.Context, logger *zap.Logger, formats gotenberg.PdfFormats, inputPath, outputPath string) error {
|
||||||
|
|||||||
@@ -88,9 +88,12 @@ func TestConvertRoute(t *testing.T) {
|
|||||||
"document.docx": "/document.docx",
|
"document.docx": "/document.docx",
|
||||||
})
|
})
|
||||||
ctx.SetValues(map[string][]string{
|
ctx.SetValues(map[string][]string{
|
||||||
"pdfFormat": {
|
"pdfa": {
|
||||||
"foo",
|
"foo",
|
||||||
},
|
},
|
||||||
|
"nativePdfFormats": {
|
||||||
|
"false",
|
||||||
|
},
|
||||||
})
|
})
|
||||||
return ctx
|
return ctx
|
||||||
}(),
|
}(),
|
||||||
@@ -120,8 +123,11 @@ func TestConvertRoute(t *testing.T) {
|
|||||||
"document.docx": "/document.docx",
|
"document.docx": "/document.docx",
|
||||||
})
|
})
|
||||||
ctx.SetValues(map[string][]string{
|
ctx.SetValues(map[string][]string{
|
||||||
"pdfFormat": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
|
},
|
||||||
|
"nativePdfFormats": {
|
||||||
|
"false",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return ctx
|
return ctx
|
||||||
@@ -209,7 +215,7 @@ func TestConvertRoute(t *testing.T) {
|
|||||||
expectOutputPathsCount: 2,
|
expectOutputPathsCount: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
scenario: "success with non-native PDF/A (single file)",
|
scenario: "success with non-native PDF/A & PDF/UA (single file)",
|
||||||
ctx: func() *api.ContextMock {
|
ctx: func() *api.ContextMock {
|
||||||
ctx := &api.ContextMock{Context: new(api.Context)}
|
ctx := &api.ContextMock{Context: new(api.Context)}
|
||||||
ctx.SetFiles(map[string]string{
|
ctx.SetFiles(map[string]string{
|
||||||
@@ -217,7 +223,10 @@ func TestConvertRoute(t *testing.T) {
|
|||||||
})
|
})
|
||||||
ctx.SetValues(map[string][]string{
|
ctx.SetValues(map[string][]string{
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
|
},
|
||||||
|
"pdfua": {
|
||||||
|
"true",
|
||||||
},
|
},
|
||||||
"nativePdfFormats": {
|
"nativePdfFormats": {
|
||||||
"false",
|
"false",
|
||||||
@@ -254,13 +263,13 @@ func TestConvertRoute(t *testing.T) {
|
|||||||
"true",
|
"true",
|
||||||
},
|
},
|
||||||
"pdfFormat": {
|
"pdfFormat": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
"nativePdfFormat": {
|
"nativePdfFormat": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
"pdfua": {
|
"pdfua": {
|
||||||
"true",
|
"true",
|
||||||
@@ -375,7 +384,7 @@ func TestConvertRoute(t *testing.T) {
|
|||||||
"true",
|
"true",
|
||||||
},
|
},
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
"nativePdfFormats": {
|
"nativePdfFormats": {
|
||||||
"false",
|
"false",
|
||||||
@@ -469,7 +478,7 @@ func TestConvertRoute(t *testing.T) {
|
|||||||
expectOutputPathsCount: 1,
|
expectOutputPathsCount: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
scenario: "success with non-native PDF/A (merge)",
|
scenario: "success with non-native PDF/A & PDF/UA (merge)",
|
||||||
ctx: func() *api.ContextMock {
|
ctx: func() *api.ContextMock {
|
||||||
ctx := &api.ContextMock{Context: new(api.Context)}
|
ctx := &api.ContextMock{Context: new(api.Context)}
|
||||||
ctx.SetFiles(map[string]string{
|
ctx.SetFiles(map[string]string{
|
||||||
@@ -481,7 +490,54 @@ func TestConvertRoute(t *testing.T) {
|
|||||||
"true",
|
"true",
|
||||||
},
|
},
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
|
},
|
||||||
|
"pdfua": {
|
||||||
|
"true",
|
||||||
|
},
|
||||||
|
"nativePdfFormats": {
|
||||||
|
"false",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return ctx
|
||||||
|
}(),
|
||||||
|
libreOffice: &libreofficeapi.ApiMock{
|
||||||
|
PdfMock: func(ctx context.Context, logger *zap.Logger, inputPath, outputPath string, options libreofficeapi.Options) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
ExtensionsMock: func() []string {
|
||||||
|
return []string{".docx"}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
engine: &gotenberg.PdfEngineMock{
|
||||||
|
MergeMock: func(ctx context.Context, logger *zap.Logger, inputPaths []string, outputPath string) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
ConvertMock: func(ctx context.Context, logger *zap.Logger, formats gotenberg.PdfFormats, inputPath, outputPath string) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectError: false,
|
||||||
|
expectHttpError: false,
|
||||||
|
expectOutputPathsCount: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scenario: "success with non-native PDF/A & PDF/UA (merge)",
|
||||||
|
ctx: func() *api.ContextMock {
|
||||||
|
ctx := &api.ContextMock{Context: new(api.Context)}
|
||||||
|
ctx.SetFiles(map[string]string{
|
||||||
|
"document.docx": "/document.docx",
|
||||||
|
"document2.docx": "/document2.docx",
|
||||||
|
})
|
||||||
|
ctx.SetValues(map[string][]string{
|
||||||
|
"merge": {
|
||||||
|
"true",
|
||||||
|
},
|
||||||
|
"pdfa": {
|
||||||
|
gotenberg.PdfA1b,
|
||||||
|
},
|
||||||
|
"pdfua": {
|
||||||
|
"true",
|
||||||
},
|
},
|
||||||
"nativePdfFormats": {
|
"nativePdfFormats": {
|
||||||
"false",
|
"false",
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ func TestMergeHandler(t *testing.T) {
|
|||||||
})
|
})
|
||||||
ctx.SetValues(map[string][]string{
|
ctx.SetValues(map[string][]string{
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return ctx
|
return ctx
|
||||||
@@ -127,7 +127,7 @@ func TestMergeHandler(t *testing.T) {
|
|||||||
})
|
})
|
||||||
ctx.SetValues(map[string][]string{
|
ctx.SetValues(map[string][]string{
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return ctx
|
return ctx
|
||||||
@@ -157,7 +157,7 @@ func TestMergeHandler(t *testing.T) {
|
|||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1a,
|
||||||
},
|
},
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
"pdfua": {
|
"pdfua": {
|
||||||
"true",
|
"true",
|
||||||
@@ -259,7 +259,7 @@ func TestConvertHandler(t *testing.T) {
|
|||||||
})
|
})
|
||||||
ctx.SetValues(map[string][]string{
|
ctx.SetValues(map[string][]string{
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return ctx
|
return ctx
|
||||||
@@ -283,7 +283,7 @@ func TestConvertHandler(t *testing.T) {
|
|||||||
})
|
})
|
||||||
ctx.SetValues(map[string][]string{
|
ctx.SetValues(map[string][]string{
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return ctx
|
return ctx
|
||||||
@@ -306,7 +306,7 @@ func TestConvertHandler(t *testing.T) {
|
|||||||
})
|
})
|
||||||
ctx.SetValues(map[string][]string{
|
ctx.SetValues(map[string][]string{
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
ctx.SetCancelled(true)
|
ctx.SetCancelled(true)
|
||||||
@@ -333,7 +333,7 @@ func TestConvertHandler(t *testing.T) {
|
|||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1a,
|
||||||
},
|
},
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
"pdfua": {
|
"pdfua": {
|
||||||
"true",
|
"true",
|
||||||
@@ -363,7 +363,7 @@ func TestConvertHandler(t *testing.T) {
|
|||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1a,
|
||||||
},
|
},
|
||||||
"pdfa": {
|
"pdfa": {
|
||||||
gotenberg.PdfA1a,
|
gotenberg.PdfA1b,
|
||||||
},
|
},
|
||||||
"pdfua": {
|
"pdfua": {
|
||||||
"true",
|
"true",
|
||||||
|
|||||||
Reference in New Issue
Block a user