forked from cheggaaa/go-poppler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document.go
68 lines (58 loc) · 2.15 KB
/
document.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package poppler
// #cgo pkg-config: poppler-glib
// #include <poppler.h>
// #include <stdlib.h>
// #include <glib.h>
// #include <unistd.h>
import "C"
type Document struct {
doc poppDoc
openedPopplerPages []*C.struct__PopplerPage
}
type DocumentInfo struct {
PdfVersion, Title, Author, Subject, KeyWords, Creator, Producer, Metadata string
CreationDate, ModificationDate, Pages int
IsLinearized bool
}
func (d *Document) Info() DocumentInfo {
return DocumentInfo{
PdfVersion: toString(C.poppler_document_get_pdf_version_string(d.doc)),
Title: toString(C.poppler_document_get_title(d.doc)),
Author: toString(C.poppler_document_get_author(d.doc)),
Subject: toString(C.poppler_document_get_subject(d.doc)),
KeyWords: toString(C.poppler_document_get_keywords(d.doc)),
Creator: toString(C.poppler_document_get_creator(d.doc)),
Producer: toString(C.poppler_document_get_producer(d.doc)),
Metadata: toString(C.poppler_document_get_metadata(d.doc)),
CreationDate: int(C.poppler_document_get_creation_date(d.doc)),
ModificationDate: int(C.poppler_document_get_modification_date(d.doc)),
Pages: int(C.poppler_document_get_n_pages(d.doc)),
IsLinearized: toBool(C.poppler_document_is_linearized(d.doc)),
}
}
func (d *Document) GetNPages() int {
return int(C.poppler_document_get_n_pages(d.doc))
}
func (d *Document) GetPage(i int) (page *Page) {
p := C.poppler_document_get_page(d.doc, C.int(i))
d.openedPopplerPages = append(d.openedPopplerPages, p)
return &Page{p: p}
}
func (d *Document) HasAttachments() bool {
return toBool(C.poppler_document_has_attachments(d.doc))
}
func (d *Document) GetNAttachments() int {
return int(C.poppler_document_get_n_attachments(d.doc))
}
func (d *Document) Close() {
for i := 0; i < len(d.openedPopplerPages); i++ {
C.g_object_unref(C.gpointer(d.openedPopplerPages[i]))
}
d.openedPopplerPages = []*C.struct__PopplerPage{}
C.g_object_unref(C.gpointer(d.doc))
}
/*
func (d *Document) GetAttachments() []Attachment {
return
}
*/