Initial commit
This commit is contained in:
commit
f1b648247e
4 changed files with 54 additions and 0 deletions
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module t0xa/pdf_to_txt
|
||||
|
||||
go 1.22.5
|
||||
|
||||
require github.com/rudolfoborges/pdf2go v0.1.1 // indirect
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
github.com/rudolfoborges/pdf2go v0.1.1 h1:cAEi53YeticMNnuts30UD11W6AAcB+Xe3odLVrI9XIE=
|
||||
github.com/rudolfoborges/pdf2go v0.1.1/go.mod h1:l+ur9AjixJEV8ZEapV1ggOLAkSiBj+jSSXcWKRJp3TY=
|
47
main.go
Normal file
47
main.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/rudolfoborges/pdf2go"
|
||||
)
|
||||
|
||||
type CheckEntry struct {
|
||||
Product string
|
||||
Price string
|
||||
}
|
||||
|
||||
func main() {
|
||||
pdf, err := pdf2go.New("./test.pdf", pdf2go.Config{
|
||||
LogLevel: pdf2go.LogLevelError,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
text, err := pdf.Text()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
split := strings.Split(text, "\n")
|
||||
for index, element := range split{
|
||||
if element == "Цена*Кол" {
|
||||
fmt.Println("----")
|
||||
fmt.Println(split[index-4])
|
||||
fmt.Println(split[index-3])
|
||||
fmt.Println(split[index-2])
|
||||
fmt.Println(split[index-1])
|
||||
fmt.Println(split[index])
|
||||
fmt.Println(split[index+1])
|
||||
fmt.Println(split[index+2])
|
||||
fmt.Println(split[index+3])
|
||||
fmt.Println(split[index+4])
|
||||
|
||||
fmt.Println("Товар: ", split[index-2])
|
||||
fmt.Println("Цена: ", split[index+2])
|
||||
fmt.Println("------")
|
||||
}
|
||||
}
|
||||
}
|
BIN
test.pdf
Normal file
BIN
test.pdf
Normal file
Binary file not shown.
Loading…
Reference in a new issue