You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
528 B
34 lines
528 B
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
|
|
}
|
|
|