forked from kevin2li/PDF-Guru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract.go
46 lines (43 loc) · 1.36 KB
/
extract.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
package main
func (a *App) ExtractTextFromPDF(inFile string, outFile string, pages string) error {
logger.Printf("inFile: %s, outFile: %s, pages: %s\n", inFile, outFile, pages)
args := []string{"extract", "--type", "text"}
if pages != "" {
args = append(args, "--page_range", pages)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) ExtractImageFromPDF(inFile string, outFile string, pages string) error {
logger.Printf("inFile: %s, outFile: %s, pages: %s\n", inFile, outFile, pages)
args := []string{"extract", "--type", "image"}
if pages != "" {
args = append(args, "--page_range", pages)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}
func (a *App) OCRExtract(inFile string, outFile string, pages string, extractType string) error {
logger.Printf("inFile: %s, outFile: %s, pages: %s, extractType: %s\n", inFile, outFile, pages, extractType)
args := []string{"ocr", "extract"}
if extractType != "" {
args = append(args, "--type", extractType)
}
if pages != "" {
args = append(args, "--range", pages)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "python")
}