mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 04:32:15 +01:00
fix(qpdf): allow warnings (#1135)
* Optionally allow warnings in QPDF operations * warnings are not errors by default * Apply suggestions from code review Co-authored-by: Julien Neuhart <neuhart.julien@gmail.com> * fix some merge artifacts * follow the args convention --------- Co-authored-by: Julien Neuhart <neuhart.julien@gmail.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user