-
Notifications
You must be signed in to change notification settings - Fork 206
/
scale.go
54 lines (50 loc) · 1.75 KB
/
scale.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
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")
}