...
|
...
|
@@ -7,6 +7,7 @@ import ( |
|
|
"github.com/pdfcpu/pdfcpu/pkg/api"
|
|
|
"io/fs"
|
|
|
"io/ioutil"
|
|
|
"math/rand"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
"os/exec"
|
...
|
...
|
@@ -14,6 +15,7 @@ import ( |
|
|
"runtime"
|
|
|
"sort"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
const (
|
...
|
...
|
@@ -113,8 +115,10 @@ func ImageBlur(filePath string) (string, error) { |
|
|
|
|
|
// PDFBlur PDF 模糊处理
|
|
|
func PDFBlur(pdfPath string) (string, error) {
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
filename := filepath.Base(pdfPath)
|
|
|
blurFilename := filepath.Join(outPath, BlurPrefix+filename)
|
|
|
tmpblurFilename := filepath.Join(outPath, BlurPrefix+fmt.Sprintf("%v-", rand.Int())+filename)
|
|
|
tmpImagePath, err := ioutil.TempDir("", "image-")
|
|
|
tmpImagePathBlur, err := ioutil.TempDir("", "image-"+BlurPrefix)
|
|
|
cmd := exec.Command(cmdPath, pdfPath, tmpImagePath+"/")
|
...
|
...
|
@@ -132,10 +136,13 @@ func PDFBlur(pdfPath string) (string, error) { |
|
|
_ = imaging.Save(dst, filepath.Join(tmpImagePathBlur, f.Name()))
|
|
|
}
|
|
|
sort.Strings(blurFiles)
|
|
|
err = api.ImportImagesFile(blurFiles, blurFilename, nil, nil)
|
|
|
err = api.ImportImagesFile(blurFiles, tmpblurFilename, nil, nil)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
if err = os.Rename(tmpblurFilename, blurFilename); err != nil {
|
|
|
return "", nil
|
|
|
}
|
|
|
//clear
|
|
|
os.RemoveAll(tmpImagePath)
|
|
|
os.RemoveAll(tmpImagePathBlur)
|
...
|
...
|
|