forked from varia/go-sh-manymanuals
35 lines
528 B
Go
35 lines
528 B
Go
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
|
|
}
|