mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-18 05:02:15 +01:00
Merge pull request #31 from thecodingmachine/merge-alt
adding PDFtk for merging PDF files < 1.7
This commit is contained in:
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2018 TheCodingMachine
|
Copyright (c) 2019 TheCodingMachine
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM debian:stretch-slim
|
FROM debian:9.5-slim
|
||||||
|
|
||||||
# |--------------------------------------------------------------------------
|
# |--------------------------------------------------------------------------
|
||||||
# | Common libraries
|
# | Common libraries
|
||||||
@@ -43,4 +43,14 @@ RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add
|
|||||||
RUN pip3 install unoconv &&\
|
RUN pip3 install unoconv &&\
|
||||||
# https://github.com/nextcloud/docker/issues/380
|
# https://github.com/nextcloud/docker/issues/380
|
||||||
mkdir -p /usr/share/man/man1mkdir -p /usr/share/man/man1 &&\
|
mkdir -p /usr/share/man/man1mkdir -p /usr/share/man/man1 &&\
|
||||||
apt-get -y install libreoffice
|
apt-get -y install libreoffice
|
||||||
|
|
||||||
|
# |--------------------------------------------------------------------------
|
||||||
|
# | PDFtk
|
||||||
|
# |--------------------------------------------------------------------------
|
||||||
|
# |
|
||||||
|
# | Installs PDFtk as an alternative to pdfcpu for merging PDFs.
|
||||||
|
# | https://github.com/thecodingmachine/gotenberg/issues/29
|
||||||
|
# |
|
||||||
|
|
||||||
|
RUN apt-get -y install pdftk
|
||||||
@@ -3,6 +3,7 @@ package printer
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
pdfcpuAPI "github.com/hhrutter/pdfcpu/pkg/api"
|
pdfcpuAPI "github.com/hhrutter/pdfcpu/pkg/api"
|
||||||
pdfcpuLog "github.com/hhrutter/pdfcpu/pkg/log"
|
pdfcpuLog "github.com/hhrutter/pdfcpu/pkg/log"
|
||||||
@@ -23,9 +24,18 @@ type Printer interface {
|
|||||||
|
|
||||||
// Merge merges PDF files.
|
// Merge merges PDF files.
|
||||||
func Merge(fpaths []string, destination string) error {
|
func Merge(fpaths []string, destination string) error {
|
||||||
cmd := pdfcpuAPI.MergeCommand(fpaths, destination, pdfcpuConfig.NewDefaultConfiguration())
|
cmdcpu := pdfcpuAPI.MergeCommand(fpaths, destination, pdfcpuConfig.NewDefaultConfiguration())
|
||||||
_, err := pdfcpuAPI.Merge(cmd)
|
_, err := pdfcpuAPI.Merge(cmdcpu)
|
||||||
return err
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// if pdfcpu failed to merge PDF files...
|
||||||
|
// https://github.com/thecodingmachine/gotenberg/issues/29
|
||||||
|
var cmdArgs []string
|
||||||
|
cmdArgs = append(cmdArgs, fpaths...)
|
||||||
|
cmdArgs = append(cmdArgs, "cat", "output", destination)
|
||||||
|
cmd := exec.Command("pdftk", cmdArgs...)
|
||||||
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeBytesToFile(dst string, b []byte) error {
|
func writeBytesToFile(dst string, b []byte) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user