unipdf/pdf/extractor/utils.go

49 lines
1.1 KiB
Go
Raw Normal View History

/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
package extractor
import (
2018-03-22 13:53:12 +00:00
"bytes"
"errors"
2018-03-22 13:53:12 +00:00
"fmt"
2018-03-22 13:53:12 +00:00
"github.com/unidoc/unidoc/common/license"
"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)
}