forked from timsat/go-poppler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpage.go
51 lines (42 loc) · 1017 Bytes
/
page.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
47
48
49
50
51
package poppler
// #cgo pkg-config: poppler-glib
// #include <poppler.h>
// #include <glib.h>
import "C"
import (
"runtime"
"unsafe"
)
type Page struct {
p *C.struct__PopplerPage
}
func (p *Page) Text() string {
cCharPtr := C.poppler_page_get_text(p.p)
pageText := C.GoString(cCharPtr)
C.free(unsafe.Pointer(cCharPtr))
return pageText
}
func (p *Page) Size() (width, height float64) {
var w, h C.double
C.poppler_page_get_size(p.p, &w, &h)
return float64(w), float64(h)
}
func (p *Page) Index() int {
return int(C.poppler_page_get_index(p.p))
}
func (p *Page) Label() string {
return toString(C.poppler_page_get_label(p.p))
}
func (p *Page) Duration() float64 {
return float64(C.poppler_page_get_duration(p.p))
}
// Close frees memory allocated when Poppler opened the page
func (p *Page) Close() {
// GC/finalizer shouldn't try to free C memory that has been freed already
runtime.SetFinalizer(p, nil)
closePage(p)
p.p = nil
}
func closePage(p *Page) {
C.g_object_unref(C.gpointer(p.p))
}