forked from kevin2li/PDF-Guru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
split.go
47 lines (40 loc) · 1.29 KB
/
split.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
package main
import "fmt"
func (a *App) SplitPDFByChunk(inFile string, chunkSize int, outDir string) error {
logger.Printf("inFile: %s, chunkSize: %d, outDir: %s\n", inFile, chunkSize, outDir)
args := []string{"split", "--mode", "chunk"}
args = append(args, "--chunk_size")
args = append(args, fmt.Sprintf("%d", chunkSize))
if outDir != "" {
args = append(args, "--output", outDir)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) SplitPDFByBookmark(inFile string, tocLevel string, outDir string) error {
logger.Printf("inFile: %s, outDir: %s\n", inFile, outDir)
args := []string{"split", "--mode", "toc"}
if tocLevel != "" {
args = append(args, "--toc-level", tocLevel)
}
if outDir != "" {
args = append(args, "--output", outDir)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) SplitPDFByPage(inFile string, pages string, outDir string) error {
logger.Printf("inFile: %s, pages: %s, outDir: %s\n", inFile, pages, outDir)
args := []string{"split", "--mode", "page"}
if pages != "" {
args = append(args, "--page_range", pages)
}
if outDir != "" {
args = append(args, "--output", outDir)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}