mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 00:22:14 +01:00
30 lines
737 B
Go
30 lines
737 B
Go
package printer
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
|
|
pdfcpuAPI "github.com/hhrutter/pdfcpu/pkg/api"
|
|
pdfcpuConfig "github.com/hhrutter/pdfcpu/pkg/pdfcpu"
|
|
)
|
|
|
|
// Printer is a type that can create a PDF file from a source.
|
|
// The source is defined in the underlying implementation.
|
|
type Printer interface {
|
|
Print(destination string) error
|
|
}
|
|
|
|
// Merge merges PDF files.
|
|
func Merge(fpaths []string, destination string) error {
|
|
cmd := pdfcpuAPI.MergeCommand(fpaths, destination, pdfcpuConfig.NewDefaultConfiguration())
|
|
_, err := pdfcpuAPI.Merge(cmd)
|
|
return err
|
|
}
|
|
|
|
func writeBytesToFile(dst string, b []byte) error {
|
|
if err := ioutil.WriteFile(dst, b, 0644); err != nil {
|
|
return fmt.Errorf("%s: writting file: %v", dst, err)
|
|
}
|
|
return nil
|
|
}
|