-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
58 lines (55 loc) · 1.09 KB
/
test.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
55
56
57
package main
import(
"os"
"fmt"
"pdfstrip/decode"
"pdfstrip/deformat"
"encoding/xml"
)
func main() {
if len(os.Args) != 3 {
fmt.Println("Please provide two file names...")
return
}
fileIn, fileErr := os.Open(os.Args[1])
if fileErr != nil {
fmt.Println(fileErr.Error())
return
}
fileOut, fileErr := os.Create(os.Args[2])
if fileErr != nil {
fmt.Println(fileErr.Error())
return
}
fileData, fileErr := decode.Decode(fileIn)
if fileErr != nil {
fmt.Println(fileErr.Error())
return
}
byteBuffer, err := xml.Marshal(fileData)
if err != nil {
fmt.Println(err.Error())
return
}
_, fileErr = fileOut.Write(byteBuffer)
fileIn.Close()
fileOut.Close()
fileOut, fileErr = os.Create("new_" + os.Args[2])
if fileErr != nil {
fmt.Println(fileErr.Error())
return
}
for index, val := range fileData.Blocks {
fileData.Blocks[index].Text, _ = deformat.Deformat([]byte(val.Text))
}
byteBuffer, err = xml.Marshal(fileData)
if err != nil {
fmt.Println(err.Error())
return
}
_, fileErr = fileOut.Write(byteBuffer)
if fileErr != nil {
fmt.Println(fileErr.Error())
return
}
}