Add page size configurability
This commit is contained in:
27
README.md
27
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)
|
||||
```
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user