mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-15 03:42:15 +01:00
feat(pdfengines): add PDF/UA (#714)
This commit is contained in:
@@ -10,30 +10,24 @@ import (
|
||||
"github.com/gotenberg/gotenberg/v7/pkg/gotenberg"
|
||||
)
|
||||
|
||||
// multiPDFEngines implements the gotenberg.PDFEngine interface and gathers one
|
||||
// or more gotenberg.PDFEngine. It provides a sort of fallback mechanism: if an
|
||||
// engine's method returns an error, it calls the same method from another
|
||||
// engine.
|
||||
type multiPDFEngines struct {
|
||||
engines []gotenberg.PDFEngine
|
||||
type multiPdfEngines struct {
|
||||
engines []gotenberg.PdfEngine
|
||||
}
|
||||
|
||||
// newMultiPDFEngines returns a multiPDFEngines. Arguments' order determines the
|
||||
// order of the engines called.
|
||||
func newMultiPDFEngines(engines ...gotenberg.PDFEngine) *multiPDFEngines {
|
||||
return &multiPDFEngines{
|
||||
func newMultiPdfEngines(engines ...gotenberg.PdfEngine) *multiPdfEngines {
|
||||
return &multiPdfEngines{
|
||||
engines: engines,
|
||||
}
|
||||
}
|
||||
|
||||
// Merge tries to merge the given PDFs into a unique PDF thanks to its
|
||||
// children. If the context is done, it stops and returns an error.
|
||||
func (multi multiPDFEngines) Merge(ctx context.Context, logger *zap.Logger, inputPaths []string, outputPath string) error {
|
||||
func (multi *multiPdfEngines) Merge(ctx context.Context, logger *zap.Logger, inputPaths []string, outputPath string) error {
|
||||
var err error
|
||||
errChan := make(chan error, 1)
|
||||
|
||||
for _, engine := range multi.engines {
|
||||
go func(engine gotenberg.PDFEngine) {
|
||||
go func(engine gotenberg.PdfEngine) {
|
||||
errChan <- engine.Merge(ctx, logger, inputPaths, outputPath)
|
||||
}(engine)
|
||||
|
||||
@@ -53,13 +47,13 @@ func (multi multiPDFEngines) Merge(ctx context.Context, logger *zap.Logger, inpu
|
||||
|
||||
// Convert converts the given PDF to a specific PDF format. thanks to its
|
||||
// children. If the context is done, it stops and returns an error.
|
||||
func (multi multiPDFEngines) Convert(ctx context.Context, logger *zap.Logger, format, inputPath, outputPath string) error {
|
||||
func (multi *multiPdfEngines) Convert(ctx context.Context, logger *zap.Logger, formats gotenberg.PdfFormats, inputPath, outputPath string) error {
|
||||
var err error
|
||||
errChan := make(chan error, 1)
|
||||
|
||||
for _, engine := range multi.engines {
|
||||
go func(engine gotenberg.PDFEngine) {
|
||||
errChan <- engine.Convert(ctx, logger, format, inputPath, outputPath)
|
||||
go func(engine gotenberg.PdfEngine) {
|
||||
errChan <- engine.Convert(ctx, logger, formats, inputPath, outputPath)
|
||||
}(engine)
|
||||
|
||||
select {
|
||||
@@ -73,10 +67,10 @@ func (multi multiPDFEngines) Convert(ctx context.Context, logger *zap.Logger, fo
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("convert PDF to '%s' with multi PDF engines: %w", format, err)
|
||||
return fmt.Errorf("convert PDF to '%+v' with multi PDF engines: %w", formats, err)
|
||||
}
|
||||
|
||||
// Interface guards.
|
||||
var (
|
||||
_ gotenberg.PDFEngine = (*multiPDFEngines)(nil)
|
||||
_ gotenberg.PdfEngine = (*multiPdfEngines)(nil)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user