-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (36 loc) · 910 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
package main
import (
"fmt"
"os"
"path"
"strings"
"github.com/unidoc/unioffice"
"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/document"
)
func main() {
if unidocLicense != "" {
if err := license.SetLegacyLicenseKey(unidocLicense); err != nil {
fmt.Println("error installing unioffice license:", err)
os.Exit(1)
}
}
unioffice.DisableLogging()
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "Usage: unprotect <file1,[file2],...>")
os.Exit(1)
}
for _, file := range os.Args[1:] {
doc, err := document.Open(file)
if err != nil {
fmt.Fprintf(os.Stderr, "error opening %s: %v\n", file, err)
continue
}
doc.Settings.X().DocumentProtection = nil
filename := path.Base(file)
ext := path.Ext(filename)
trunk := strings.TrimSuffix(filename, ext)
doc.SaveToFile(trunk + "-unprotected" + ext)
fmt.Println(trunk + "-unprotected" + ext)
}
}