80 lines
2.0 KiB
Go
80 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"code.ppl.town/justin/qr_labels/qr_labels"
|
|
)
|
|
|
|
var flagLabel string
|
|
var flagQRCode string
|
|
var flagQRSize float64
|
|
var flagRows, flagCols uint
|
|
var flagFontSize float64
|
|
var flagFont string
|
|
var flagFontStyle string
|
|
var flagBorders bool = true
|
|
var flagFilename string
|
|
var flagCodeIsLabel bool
|
|
|
|
func main() {
|
|
|
|
flag.StringVar(&flagLabel, "label", "", "label (printed above QR code)")
|
|
flag.StringVar(&flagQRCode, "code", "", "string to turn into a QR code (URL, text etc)")
|
|
flag.Float64Var(&flagQRSize, "size", 50.0, "size of the QR code")
|
|
|
|
flag.UintVar(&flagRows, "rows", 4, "number of rows on the page")
|
|
flag.UintVar(&flagCols, "cols", 3, "number of columns on the page")
|
|
flag.StringVar(&flagFont, "font", "Helvetica", "name of the font")
|
|
flag.Float64Var(&flagFontSize, "font-size", 24.0, "font-size, in pts")
|
|
flag.StringVar(&flagFontStyle, "font-style", "", "font style, combine 'B', 'U', 'S', 'I' characters")
|
|
flag.BoolVar(&flagBorders, "borders", false, "print borders between labels")
|
|
flag.StringVar(&flagFilename, "output", "", "filename to write the PDF")
|
|
|
|
flag.BoolVar(&flagCodeIsLabel, "code-is-label", false, "use the -code as the -label")
|
|
|
|
flag.Parse()
|
|
|
|
if flagFilename == "" {
|
|
fmt.Println("you need to supply an -output filename")
|
|
os.Exit(1)
|
|
}
|
|
|
|
if flagQRCode == "" {
|
|
fmt.Println("you need to supply a QR -code string")
|
|
os.Exit(1)
|
|
}
|
|
|
|
if flagCodeIsLabel && flagLabel != "" {
|
|
fmt.Println("you cannot use both -code-is-label and -label")
|
|
os.Exit(1)
|
|
}
|
|
|
|
if flagCodeIsLabel {
|
|
flagLabel = flagQRCode
|
|
}
|
|
|
|
f, err := os.Create(flagFilename)
|
|
if err != nil {
|
|
fmt.Printf("failed to create output file: %s\n", err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
err = qr_labels.GeneratePage(f,
|
|
flagQRCode,
|
|
flagLabel,
|
|
qr_labels.WithQRSize(flagQRSize),
|
|
qr_labels.WithFont(flagFont, flagFontSize, flagFontStyle),
|
|
qr_labels.WithBorders(flagBorders),
|
|
qr_labels.WithGrid(int(flagRows), int(flagCols)),
|
|
)
|
|
|
|
if err != nil {
|
|
fmt.Printf("could not generate pdf: %s\n", err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
}
|