github.com/unidoc/unidoc@v2.2.0+incompatible/pdf/extractor/utils.go (about)

     1  /*
     2   * This file is subject to the terms and conditions defined in
     3   * file 'LICENSE.md', which is part of this source code package.
     4   */
     5  
     6  package extractor
     7  
     8  import (
     9  	"bytes"
    10  	"errors"
    11  	"fmt"
    12  
    13  	"github.com/unidoc/unidoc/common/license"
    14  	"github.com/unidoc/unidoc/pdf/core"
    15  )
    16  
    17  // getNumberAsFloat can retrieve numeric values from PdfObject (both integer/float).
    18  func getNumberAsFloat(obj core.PdfObject) (float64, error) {
    19  	if fObj, ok := obj.(*core.PdfObjectFloat); ok {
    20  		return float64(*fObj), nil
    21  	}
    22  
    23  	if iObj, ok := obj.(*core.PdfObjectInteger); ok {
    24  		return float64(*iObj), nil
    25  	}
    26  
    27  	return 0, errors.New("Not a number")
    28  }
    29  
    30  func procBuf(buf *bytes.Buffer) {
    31  	if isTesting {
    32  		return
    33  	}
    34  
    35  	lk := license.GetLicenseKey()
    36  	if lk != nil && lk.IsLicensed() {
    37  		return
    38  	}
    39  	fmt.Printf("Unlicensed copy of unidoc\n")
    40  	fmt.Printf("To get rid of the watermark and keep entire text - Please get a license on https://unidoc.io\n")
    41  
    42  	s := "- [Unlicensed UniDoc - Get a license on https://unidoc.io]"
    43  	if buf.Len() > 100 {
    44  		s = "... [Truncated - Unlicensed UniDoc - Get a license on https://unidoc.io]"
    45  		buf.Truncate(buf.Len() - 100)
    46  	}
    47  	buf.WriteString(s)
    48  }