unipdf/pdf/extractor/utils.go

55 lines
1.3 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"
"fmt"
2018-03-22 13:53:12 +00:00
"github.com/unidoc/unidoc/common/license"
2018-07-15 17:29:27 +10:00
"github.com/unidoc/unidoc/pdf/core"
)
2018-03-22 13:53:12 +00:00
func procBuf(buf *bytes.Buffer) {
if isTesting {
return
}
lk := license.GetLicenseKey()
if lk != nil && lk.IsLicensed() {
return
}
2018-03-22 14:16:59 +00:00
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")
2018-03-22 13:53:12 +00:00
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)
}
// toFloatList returns `objs` as 2 floats, if that's what it is, or an error if it isn't
2018-07-15 17:29:27 +10:00
func toFloatXY(objs []core.PdfObject) (x, y float64, err error) {
if len(objs) != 2 {
return 0, 0, fmt.Errorf("Invalid number of params: %d", len(objs))
}
floats, err := core.GetNumbersAsFloat(objs)
if err != nil {
return 0, 0, err
}
return floats[0], floats[1], nil
}
// truncate returns the first `n` characters in string `s`.
func truncate(s string, n int) string {
if len(s) < n {
return s
}
return s[:n]
}