WIP - respond with document info
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"bitbucket.org/digitorus/pdf"
|
"bitbucket.org/digitorus/pdf"
|
||||||
@@ -23,7 +24,7 @@ import (
|
|||||||
type Response struct {
|
type Response struct {
|
||||||
Error string
|
Error string
|
||||||
|
|
||||||
DocumentInfo string
|
DocumentInfo DocumentInfo
|
||||||
Signers []Signer
|
Signers []Signer
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +57,8 @@ func File(file *os.File) (apiResp *Response, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Reader(file io.ReaderAt, size int64) (apiResp *Response, err error) {
|
func Reader(file io.ReaderAt, size int64) (apiResp *Response, err error) {
|
||||||
|
var documentInfo DocumentInfo
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
apiResp = nil
|
apiResp = nil
|
||||||
@@ -80,6 +83,9 @@ func Reader(file io.ReaderAt, size int64) (apiResp *Response, err error) {
|
|||||||
// Get the xref object Value
|
// Get the xref object Value
|
||||||
v := rdr.Resolve(x.Ptr(), x.Ptr())
|
v := rdr.Resolve(x.Ptr(), x.Ptr())
|
||||||
|
|
||||||
|
// get document info
|
||||||
|
getDocumentInfo(v, &documentInfo)
|
||||||
|
|
||||||
// We must have a Filter Adobe.PPKLite
|
// We must have a Filter Adobe.PPKLite
|
||||||
if v.Key("Filter").Name() != "Adobe.PPKLite" {
|
if v.Key("Filter").Name() != "Adobe.PPKLite" {
|
||||||
continue
|
continue
|
||||||
@@ -301,9 +307,41 @@ func Reader(file io.ReaderAt, size int64) (apiResp *Response, err error) {
|
|||||||
err = fmt.Errorf("Document looks to have a signature but got no results")
|
err = fmt.Errorf("Document looks to have a signature but got no results")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apiResp.DocumentInfo = documentInfo
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DocumentInfo struct {
|
||||||
|
Author,
|
||||||
|
CreationDate,
|
||||||
|
Creator,
|
||||||
|
Hash,
|
||||||
|
Keywords,
|
||||||
|
ModDate,
|
||||||
|
Name,
|
||||||
|
Pages,
|
||||||
|
Permission,
|
||||||
|
Producer,
|
||||||
|
Subject,
|
||||||
|
Title string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDocumentInfo(v pdf.Value, documentInfo *DocumentInfo) {
|
||||||
|
keys := []string{"Author", "CreationDate", "Creator", "Hash", "Keywords", "ModDate",
|
||||||
|
"Name", "Pages", "Permission", "Producer", "Subject", "Title"}
|
||||||
|
|
||||||
|
for _, key := range keys {
|
||||||
|
value := v.Key(key)
|
||||||
|
if !value.IsNull() {
|
||||||
|
valueStr := value.Text()
|
||||||
|
t := reflect.ValueOf(documentInfo).Elem()
|
||||||
|
val := t.FieldByName(key)
|
||||||
|
val.Set(reflect.ValueOf(valueStr))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func walk(t pdf.Value, pad int) {
|
func walk(t pdf.Value, pad int) {
|
||||||
for _, k := range t.Keys() {
|
for _, k := range t.Keys() {
|
||||||
v := t.Key(k)
|
v := t.Key(k)
|
||||||
|
Reference in New Issue
Block a user