diff --git a/README.md b/README.md index f3abb62..efb5caf 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,30 @@ borders between each label: Run `qr_labels -help` for all command line parameters. +``` +Usage of qr_labels: + -borders + print borders between labels + -code string + string to turn into a QR code (URL, text etc) + -code-is-label + use the -code as the -label + -cols uint + number of columns on the page (default 3) + -font string + name of the font (default "Helvetica") + -font-size float + font-size, in pts (default 24) + -font-style string + font style, combine 'B', 'U', 'S', 'I' characters + -label string + label (printed above QR code) + -output string + filename to write the PDF + -page-size string + page size (A1, A2, A3, A4, A5, A6, A7, Letter, Legal, Tabloid) (default "A4") + -rows uint + number of rows on the page (default 4) + -size float + size of the QR code (default 50) +``` \ No newline at end of file diff --git a/cmd/qr_labels/main.go b/cmd/qr_labels/main.go index 75d0e27..5494e9e 100644 --- a/cmd/qr_labels/main.go +++ b/cmd/qr_labels/main.go @@ -18,6 +18,7 @@ var flagFontStyle string var flagBorders bool = true var flagFilename string var flagCodeIsLabel bool +var flagPageSize string func main() { @@ -32,6 +33,7 @@ func main() { 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.StringVar(&flagPageSize, "page-size", "A4", "page size (A1, A2, A3, A4, A5, A6, A7, Letter, Legal, Tabloid)") flag.BoolVar(&flagCodeIsLabel, "code-is-label", false, "use the -code as the -label") @@ -69,6 +71,7 @@ func main() { qr_labels.WithFont(flagFont, flagFontSize, flagFontStyle), qr_labels.WithBorders(flagBorders), qr_labels.WithGrid(int(flagRows), int(flagCols)), + qr_labels.WithPageSize(flagPageSize), ) if err != nil { diff --git a/qr_labels/options.go b/qr_labels/options.go index ce04fe4..c1fbbcd 100644 --- a/qr_labels/options.go +++ b/qr_labels/options.go @@ -66,3 +66,17 @@ func WithGrid(rows, cols int) optWithGrid { cols: cols, } } + +type optWithPageSize struct { + size string +} + +func (o optWithPageSize) apply(po *pageOptions) { + po.pageSize = o.size +} + +func WithPageSize(size string) optWithPageSize { + return optWithPageSize{ + size: size, + } +} diff --git a/qr_labels/qr_labels.go b/qr_labels/qr_labels.go index 031c589..acbef81 100644 --- a/qr_labels/qr_labels.go +++ b/qr_labels/qr_labels.go @@ -18,9 +18,12 @@ type pageOptions struct { font string fontStyle string fontSize float64 - rows int - cols int - borders bool + + rows int + cols int + pageSize string + + borders bool } func defaultPageOptions() []Option { @@ -29,6 +32,7 @@ func defaultPageOptions() []Option { WithQRSize(40), WithFont("Courier", 16.0, "B"), WithGrid(4, 3), + WithPageSize("A4"), } } @@ -93,7 +97,7 @@ func GeneratePage(w io.Writer, url, label string, opts ...Option) error { } // dim := qrc.Dimension() - pdf := fpdf.New("P", "mm", "A4", "") + pdf := fpdf.New("P", "mm", po.pageSize, "") pdf.SetMargins(0, 0, 0) pageWidth, pageHeight := pdf.GetPageSize()