unipdf/pdf/extractor/utils.go
2018-12-15 18:49:15 +05:00

55 lines
1.3 KiB
Go

/*
* 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 (
"bytes"
"fmt"
"github.com/unidoc/unidoc/common/license"
"github.com/unidoc/unidoc/pdf/core"
)
func procBuf(buf *bytes.Buffer) {
if isTesting {
return
}
lk := license.GetLicenseKey()
if lk != nil && lk.IsLicensed() {
return
}
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")
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
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]
}