1 Star 0 Fork 357

zplogo/PDF-Guru

forked from Kevin2li/PDF-Guru 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
encrypt.go 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import "os"
func (a *App) EncryptPDF(inFile string, outFile string, upw string, opw string, perm []string) error {
logger.Printf("inFile: %s, outFile: %s, upw: %s, opw: %s, perm: %v\n", inFile, outFile, upw, opw, perm)
if _, err := os.Stat(inFile); os.IsNotExist(err) {
logger.Errorln(err)
return err
}
args := []string{"encrypt"}
if len(perm) > 0 {
args = append(args, "--perm")
args = append(args, perm...)
}
if upw != "" {
args = append(args, "--user_password", upw)
}
if opw != "" {
args = append(args, "--owner_password", opw)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) DecryptPDF(inFile string, outFile string, passwd string) error {
logger.Printf("inFile: %s, outFile: %s, passwd: %s\n", inFile, outFile, passwd)
if _, err := os.Stat(inFile); os.IsNotExist(err) {
logger.Errorln(err)
return err
}
args := []string{"decrypt"}
if passwd != "" {
args = append(args, "--password", passwd)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) ChangePasswordPDF(inFile string, outFile string, oldUpw string, upw string, oldOpw string, opw string) error {
logger.Printf("inFile: %s, outFile: %s, oldUpw: %s, upw: %s, oldOpw: %s, opw: %s\n", inFile, outFile, oldUpw, upw, oldOpw, opw)
args := []string{"change_password"}
if oldUpw != "" {
args = append(args, "--old_user_password", oldUpw)
}
if upw != "" {
args = append(args, "--user_password", upw)
}
if oldOpw != "" {
args = append(args, "--old_owner_password", oldOpw)
}
if opw != "" {
args = append(args, "--owner_password", opw)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/zplogo/PDF-Guru.git
git@gitee.com:zplogo/PDF-Guru.git
zplogo
PDF-Guru
PDF-Guru
main

搜索帮助