加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
crop.go 1.98 KB
一键复制 编辑 原始数据 按行查看 历史
Kevin2li 提交于 2023-07-21 08:43 . fix: 类型水印文件变大
package main
import "fmt"
func (a *App) CropPDFByBBOX(inFile string, outFile string, bbox []float32, unit string, keepSize bool, pages string) error {
logger.Printf("inFile: %s, outFile: %s, bbox: %v, unit: %s, keepSize: %v, pages: %s\n", inFile, outFile, bbox, unit, keepSize, pages)
args := []string{"crop", "--method", "bbox"}
args = append(args, "--bbox")
for _, v := range bbox {
args = append(args, fmt.Sprintf("%f", v))
}
if unit != "" {
args = append(args, "--unit", unit)
}
if keepSize {
args = append(args, "--keep_size")
}
if pages != "" {
args = append(args, "--page_range", pages)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) CropPDFByMargin(inFile string, outFile string, margin []float32, unit string, keepSize bool, pages string) error {
logger.Printf("inFile: %s, outFile: %s, margin: %v, unit: %s, keepSize: %v, pages: %s\n", inFile, outFile, margin, unit, keepSize, pages)
args := []string{"crop", "--method", "margin"}
args = append(args, "--margin")
for _, v := range margin {
args = append(args, fmt.Sprintf("%f", v))
}
if unit != "" {
args = append(args, "--unit", unit)
}
if keepSize {
args = append(args, "--keep_size")
}
if pages != "" {
args = append(args, "--page_range", pages)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) CropPDFByRectAnnots(inFile string, outFile string, keepSize bool, pages string) error {
logger.Printf("inFile: %s, outFile: %s, keepSize: %v, pages: %s\n", inFile, outFile, keepSize, pages)
args := []string{"crop", "--method", "annot"}
if keepSize {
args = append(args, "--keep_size")
}
if pages != "" {
args = append(args, "--page_range", pages)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化