diff --git a/pkg/modules/qpdf/qpdf.go b/pkg/modules/qpdf/qpdf.go index 95294002..45123bbb 100644 --- a/pkg/modules/qpdf/qpdf.go +++ b/pkg/modules/qpdf/qpdf.go @@ -22,7 +22,8 @@ func init() { // QPdf abstracts the CLI tool QPDF and implements the [gotenberg.PdfEngine] // interface. type QPdf struct { - binPath string + binPath string + globalArgs []string } // Descriptor returns a [QPdf]'s module descriptor. @@ -41,6 +42,8 @@ func (engine *QPdf) Provision(ctx *gotenberg.Context) error { } engine.binPath = binPath + // Warnings should not cause errors. + engine.globalArgs = []string{"--warning-exit-0"} return nil } @@ -88,7 +91,10 @@ func (engine *QPdf) Split(ctx context.Context, logger *zap.Logger, mode gotenber if !mode.Unify { return nil, fmt.Errorf("split PDFs using mode '%s' without unify with QPDF: %w", mode.Mode, gotenberg.ErrPdfSplitModeNotSupported) } - args = append(args, inputPath, "--pages", ".", mode.Span, "--", outputPath) + args = append(args, inputPath) + args = append(args, engine.globalArgs...) + args = append(args, "--pages", ".", mode.Span) + args = append(args, "--", outputPath) default: return nil, fmt.Errorf("split PDFs using mode '%s' with QPDF: %w", mode.Mode, gotenberg.ErrPdfSplitModeNotSupported) } @@ -110,6 +116,7 @@ func (engine *QPdf) Split(ctx context.Context, logger *zap.Logger, mode gotenber func (engine *QPdf) Merge(ctx context.Context, logger *zap.Logger, inputPaths []string, outputPath string) error { var args []string args = append(args, "--empty") + args = append(args, engine.globalArgs...) args = append(args, "--pages") args = append(args, inputPaths...) args = append(args, "--", outputPath) @@ -131,10 +138,11 @@ func (engine *QPdf) Merge(ctx context.Context, logger *zap.Logger, inputPaths [] // original annotations. func (engine *QPdf) Flatten(ctx context.Context, logger *zap.Logger, inputPath string) error { var args []string + args = append(args, inputPath) args = append(args, "--generate-appearances") args = append(args, "--flatten-annotations=all") args = append(args, "--replace-input") - args = append(args, inputPath) + args = append(args, engine.globalArgs...) cmd, err := gotenberg.CommandContext(ctx, logger, engine.binPath, args...) if err != nil { diff --git a/pkg/modules/qpdf/qpdf_test.go b/pkg/modules/qpdf/qpdf_test.go index 53972429..212a2cc4 100644 --- a/pkg/modules/qpdf/qpdf_test.go +++ b/pkg/modules/qpdf/qpdf_test.go @@ -154,6 +154,15 @@ func TestQPdf_Merge(t *testing.T) { }, expectError: false, }, + { + scenario: "success even with warnings", + ctx: context.TODO(), + inputPaths: []string{ + "/tests/test/testdata/pdfengines/sample1.pdf", + "/tests/test/testdata/pdfengines/sample5.pdf", + }, + expectError: false, + }, } { t.Run(tc.scenario, func(t *testing.T) { engine := new(QPdf) @@ -236,6 +245,14 @@ func TestQPdf_Split(t *testing.T) { expectError: false, expectOutputPathsCount: 1, }, + { + scenario: "success even with warnings", + ctx: context.TODO(), + mode: gotenberg.SplitMode{Mode: gotenberg.SplitModePages, Span: "1-2", Unify: true}, + inputPath: "/tests/test/testdata/pdfengines/sample5.pdf", + expectError: false, + expectOutputPathsCount: 1, + }, } { t.Run(tc.scenario, func(t *testing.T) { engine := new(QPdf) @@ -304,6 +321,13 @@ func TestQPdf_Flatten(t *testing.T) { createCopy: true, expectError: false, }, + { + scenario: "success even with warnings", + ctx: context.TODO(), + inputPath: "/tests/test/testdata/pdfengines/sample5.pdf", + createCopy: true, + expectError: false, + }, } { t.Run(tc.scenario, func(t *testing.T) { engine := new(QPdf) diff --git a/test/testdata/pdfengines/sample5.pdf b/test/testdata/pdfengines/sample5.pdf new file mode 100644 index 00000000..a6185f71 Binary files /dev/null and b/test/testdata/pdfengines/sample5.pdf differ