1 Star 0 Fork 354

honiswang/PDF-Guru

forked from Kevin2li/PDF-Guru 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cut_and_combine.go 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
Kevin2li 提交于 2023-07-18 15:06 . refactor
package main
import "fmt"
func (a *App) CutPDFByGrid(inFile string, outFile string, row int, col int, pages string) error {
logger.Printf("inFile: %s, outFile: %s, row: %d, col: %d, pages: %s\n", inFile, outFile, row, col, pages)
args := []string{"cut", "--method", "grid"}
args = append(args, "--nrow", fmt.Sprintf("%d", row))
args = append(args, "--ncol", fmt.Sprintf("%d", col))
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) CutPDFByBreakpoints(inFile string, outFile string, HBreakpoints []float32, VBreakpoints []float32, pages string) error {
logger.Printf("inFile: %s, outFile: %s, HBreakpoints: %v, VBreakpoints: %v, pages: %s\n", inFile, outFile, HBreakpoints, VBreakpoints, pages)
args := []string{"cut", "--method", "breakpoints"}
args = append(args, inFile)
if len(HBreakpoints) > 0 {
args = append(args, "--h_breakpoints")
for _, v := range HBreakpoints {
args = append(args, fmt.Sprintf("%f", v))
}
}
if len(VBreakpoints) > 0 {
args = append(args, "--v_breakpoints")
for _, v := range VBreakpoints {
args = append(args, fmt.Sprintf("%f", v))
}
}
if pages != "" {
args = append(args, "--page_range", pages)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) CombinePDFByGrid(inFile string, outFile string, row int, col int, pages string, paperSize string, orientation string) error {
logger.Printf("inFile: %s, outFile: %s, row: %d, col: %d, pages: %s, paperSize: %s, orientation: %s\n", inFile, outFile, row, col, pages, paperSize, orientation)
args := []string{"combine"}
args = append(args, "--nrow", fmt.Sprintf("%d", row))
args = append(args, "--ncol", fmt.Sprintf("%d", col))
if paperSize != "" {
args = append(args, "--paper_size", paperSize)
}
if orientation != "" {
args = append(args, "--orientation", orientation)
}
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 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/whyfree/PDF-Guru.git
git@gitee.com:whyfree/PDF-Guru.git
whyfree
PDF-Guru
PDF-Guru
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385