72 Star 907 Fork 300

Kevin2li / PDF-Guru

加入 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")
}
Go
1
https://gitee.com/Kevin234/PDF-Guru.git
git@gitee.com:Kevin234/PDF-Guru.git
Kevin234
PDF-Guru
PDF-Guru
main

搜索帮助