-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.go
52 lines (37 loc) · 1.08 KB
/
Main.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
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
"pdfmerge/helpers"
)
func main() {
if helpers.IsPdftkInstalled() == false {
log.Fatal("Error: pdftk is not installed.\nPlease install pdftk to use this tool.")
}
args := helpers.GetMappedArguments()
if args.HasEnoughArguments == false {
log.Fatal("3 arguments are required: front-file, back-file, output-file")
}
if helpers.AreInputFilesExisting(args) == false {
log.Fatal("One or both input files could not be found.")
}
argsArray := helpers.GeneratePagePickArguments(args)
fileA := fmt.Sprintf("A=%s", args.FrontFile)
fileB := fmt.Sprintf("B=%s", args.BackFile)
begin := []string{fileA, fileB, "cat"}
end := []string{"output", args.OutputFile}
params := append(begin, argsArray...)
params = append(params, end...)
cmd := exec.Command("pdftk", params...)
var out bytes.Buffer
var errorbuf bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &errorbuf
err := cmd.Run()
if err != nil {
log.Fatalf("Error parsing pdf-file. %q", errorbuf.String())
}
log.Printf("File %q created successfully!", args.OutputFile)
}