init
This commit is contained in:
32
utils/utils.go
Normal file
32
utils/utils.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/pdfcpu/pdfcpu/pkg/api"
|
||||
)
|
||||
|
||||
func GenerateSessionId(length int) string {
|
||||
bytes := make([]byte, length) // 16 bytes = 128 bits
|
||||
_, err := rand.Read(bytes)
|
||||
if err != nil {
|
||||
panic("failed to generate session ID")
|
||||
}
|
||||
return hex.EncodeToString(bytes)
|
||||
}
|
||||
|
||||
func GenerateToken() string {
|
||||
return GenerateSessionId(16)
|
||||
}
|
||||
|
||||
func CountPagesAtPath(path string) (pages int) {
|
||||
ctx, err := api.ReadContextFile(path)
|
||||
if err != nil {
|
||||
fmt.Println("Error reading PDF:", err)
|
||||
return
|
||||
}
|
||||
|
||||
pages = ctx.PageCount
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user