-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
61 lines (54 loc) · 1.56 KB
/
cli.go
File metadata and controls
61 lines (54 loc) · 1.56 KB
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
package main
import (
"flag"
"fmt"
"io"
"os"
"github.com/mdmcconnell/pdfcomp/pdfcomp"
)
func main() {
iP := flag.Bool("images", false, "generate comparison images of pages that are different")
pP := flag.Bool("pdf", false, "generate comparison images of pages that are different")
rP := flag.Int("resolution", 300, "dpi resolution for comparison bitmaps")
ratP := flag.Int("ratio", 30, "divide resolution by this to determine the radius for difference outline circles")
dP := flag.Bool("debug", false, "write verbose debug output to stderr")
flag.Parse()
fileArgs := flag.Args()
images := *iP
resolution := *rP
ratio := *ratP
pdf := *pP
pdfcomp.GlobDebug = *dP
if len(fileArgs) != 2 {
fmt.Fprintf(os.Stderr, "Wrong number of files give, need 2, received %d\n", len(fileArgs))
printUse()
os.Exit(2)
}
file1 := fileArgs[0]
file2 := fileArgs[1]
if pdfcomp.GlobDebug {
fmt.Printf("arguments received were images=%t, pdf=%t, radius=%d, resolution=%d, file1=%s, file2=%s\n", images, pdf, ratio, resolution, file1, file2)
}
var w io.Writer
if pdf {
f, err := os.OpenFile(file1+"-diff.pdf", os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Fprintf(os.Stderr, "%s", err.Error())
os.Exit(2)
}
w = f
defer f.Close()
}
same, err := pdfcomp.EqualPDFs(file1, file2, images, w, resolution, ratio)
if err != nil {
fmt.Fprintf(os.Stderr, "%s", err.Error())
os.Exit(2)
}
if same {
os.Exit(0)
}
os.Exit(1)
}
func printUse() {
fmt.Fprintf(os.Stderr, "usage: pdf-comp [-images -overwrite -radius=n -resolution=n] file1.pdf file2.pdf")
}