加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
scale.go 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
Kevin2li 提交于 2023-07-18 15:06 . refactor
package main
import "fmt"
func (a *App) ScalePDFByScale(inFile string, outFile string, scale float32, pages string) error {
logger.Printf("inFile: %s, outFile: %s, scale: %f, pages: %s\n", inFile, outFile, scale, pages)
args := []string{"resize", "--method", "scale"}
args = append(args, "--scale", fmt.Sprintf("%f", scale))
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) ScalePDFByDim(inFile string, outFile string, width float32, height float32, unit string, pages string) error {
logger.Printf("inFile: %s, outFile: %s, width: %f, height: %f, unit: %s, pages: %s\n", inFile, outFile, width, height, unit, pages)
args := []string{"resize", "--method", "dim"}
args = append(args, "--width", fmt.Sprintf("%f", width))
args = append(args, "--height", fmt.Sprintf("%f", height))
if pages != "" {
args = append(args, "--page_range", pages)
}
if unit != "" {
args = append(args, "--unit", unit)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) ScalePDFByPaperSize(inFile string, outFile string, paperSize string, pages string) error {
logger.Printf("inFile: %s, outFile: %s, paperSize: %s, pages: %s\n", inFile, outFile, paperSize, pages)
args := []string{"resize", "--method", "paper_size"}
if paperSize != "" {
args = append(args, "--paper_size", paperSize)
}
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")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化