forked from kevin2li/PDF-Guru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cut_and_combine.go
67 lines (63 loc) · 2.21 KB
/
cut_and_combine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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")
}