2018-03-22 14:03:47 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions defined in
|
|
|
|
* file 'LICENSE.md', which is part of this source code package.
|
|
|
|
*/
|
|
|
|
|
2018-03-22 13:01:04 +00:00
|
|
|
package extractor
|
|
|
|
|
|
|
|
import (
|
2018-03-22 13:53:12 +00:00
|
|
|
"bytes"
|
2018-03-22 13:01:04 +00:00
|
|
|
"errors"
|
2018-03-22 13:53:12 +00:00
|
|
|
"fmt"
|
2018-03-22 13:01:04 +00:00
|
|
|
|
2018-03-22 13:53:12 +00:00
|
|
|
"github.com/unidoc/unidoc/common/license"
|
2018-03-22 13:01:04 +00:00
|
|
|
"github.com/unidoc/unidoc/pdf/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
// getNumberAsFloat can retrieve numeric values from PdfObject (both integer/float).
|
|
|
|
func getNumberAsFloat(obj core.PdfObject) (float64, error) {
|
|
|
|
if fObj, ok := obj.(*core.PdfObjectFloat); ok {
|
|
|
|
return float64(*fObj), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if iObj, ok := obj.(*core.PdfObjectInteger); ok {
|
|
|
|
return float64(*iObj), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0, errors.New("Not a number")
|
|
|
|
}
|
2018-03-22 13:53:12 +00:00
|
|
|
|
|
|
|
func procBuf(buf *bytes.Buffer) {
|
|
|
|
if isTesting {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lk := license.GetLicenseKey()
|
|
|
|
if lk != nil && lk.IsLicensed() {
|
|
|
|
fmt.Printf("Unlicensed copy of unidoc\n")
|
|
|
|
fmt.Printf("To get rid of the watermark and keep entire text - Please get a license on https://unidoc.io\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s := "- [Unlicensed UniDoc - Get a license on https://unidoc.io]"
|
|
|
|
if buf.Len() > 100 {
|
|
|
|
s = "... [Truncated - Unlicensed UniDoc - Get a license on https://unidoc.io]"
|
|
|
|
buf.Truncate(buf.Len() - 100)
|
|
|
|
}
|
|
|
|
buf.WriteString(s)
|
|
|
|
}
|