-
Notifications
You must be signed in to change notification settings - Fork 208
/
crop.go
68 lines (64 loc) · 1.98 KB
/
crop.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
68
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")
}