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"
|
|
|
|
"fmt"
|
2018-03-22 13:01:04 +00:00
|
|
|
|
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:01:04 +00:00
|
|
|
)
|
|
|
|
|
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)
|
|
|
|
}
|
2018-06-27 16:31:28 +10:00
|
|
|
|
|
|
|
// 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) {
|
2018-06-27 16:31:28 +10:00
|
|
|
if len(objs) != 2 {
|
2018-07-25 12:00:49 +10:00
|
|
|
return 0, 0, fmt.Errorf("Invalid number of params: %d", len(objs))
|
2018-06-27 16:31:28 +10:00
|
|
|
}
|
2018-07-25 12:00:49 +10:00
|
|
|
floats, err := core.GetNumbersAsFloat(objs)
|
2018-06-27 16:31:28 +10:00
|
|
|
if err != nil {
|
2018-07-25 12:00:49 +10:00
|
|
|
return 0, 0, err
|
2018-06-27 16:31:28 +10:00
|
|
|
}
|
2018-07-25 12:00:49 +10:00
|
|
|
return floats[0], floats[1], nil
|
2018-06-27 16:31:28 +10:00
|
|
|
}
|
|
|
|
|
2018-07-25 12:00:49 +10:00
|
|
|
// truncate returns the first `n` characters in string `s`.
|
2018-06-27 16:31:28 +10:00
|
|
|
func truncate(s string, n int) string {
|
|
|
|
if len(s) < n {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
return s[:n]
|
|
|
|
}
|