crunk
2 years ago
4 changed files with 37 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,34 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"bytes" |
||||
|
"fmt" |
||||
|
|
||||
|
"github.com/ledongthuc/pdf" |
||||
|
) |
||||
|
|
||||
|
func main() { |
||||
|
pdf.DebugOn = true |
||||
|
content, err := readPdf("../files/74ahc138.pdf") // Read local pdf file
|
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
fmt.Println(content) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
func readPdf(path string) (string, error) { |
||||
|
f, r, err := pdf.Open(path) |
||||
|
// remember close file
|
||||
|
defer f.Close() |
||||
|
if err != nil { |
||||
|
return "", err |
||||
|
} |
||||
|
var buf bytes.Buffer |
||||
|
b, err := r.GetPlainText() |
||||
|
if err != nil { |
||||
|
return "", err |
||||
|
} |
||||
|
buf.ReadFrom(b) |
||||
|
return buf.String(), nil |
||||
|
} |
Loading…
Reference in new issue