-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (42 loc) · 808 Bytes
/
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
package main
import (
"log"
"os"
"github.com/speedata/fixxref/scanner"
)
func writePDFFile(filename string, contents string) error {
f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0644)
if err != nil {
return err
}
if err = f.Truncate(0); err != nil {
return err
}
if _, err = f.WriteString(contents); err != nil {
return err
}
return f.Close()
}
func fixXRefForFile(fn string) error {
pdffile, err := os.Open(fn)
if err != nil {
return err
}
out, err := scanner.Scan(pdffile)
if err != nil {
return err
}
pdffile.Close()
if err = writePDFFile(fn, out); err != nil {
return err
}
return nil
}
func main() {
if len(os.Args) < 2 {
log.Fatalf("fixxref: expect file name of PDF file")
}
if err := fixXRefForFile(os.Args[1]); err != nil {
log.Fatal(err)
}
}