Compare commits
3 Commits
4fbfb7c291
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 4dedeaaa81 | |||
| f7da8d7db9 | |||
| 65288b9833 |
@@ -6,10 +6,10 @@ and cataloguing system to help me keep track of what was there.
|
|||||||
To do that I needed to print labels for boxes, and figured it might be useful
|
To do that I needed to print labels for boxes, and figured it might be useful
|
||||||
if they also had QR codes on them.
|
if they also had QR codes on them.
|
||||||
|
|
||||||
I thought there would be a simple online tool to create pages of identical
|
I thought there would be a simple online tool to create PDF pages of identical
|
||||||
QR labels, but apparently not.
|
QR labels, but apparently not.
|
||||||
|
|
||||||
# installing
|
# Installing
|
||||||
|
|
||||||
go install code.ppl.town/justin/qr_labels/cmd/qr_labels@latest
|
go install code.ppl.town/justin/qr_labels/cmd/qr_labels@latest
|
||||||
|
|
||||||
@@ -38,3 +38,30 @@ borders between each label:
|
|||||||
|
|
||||||
Run `qr_labels -help` for all command line parameters.
|
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 flagBorders bool = true
|
||||||
var flagFilename string
|
var flagFilename string
|
||||||
var flagCodeIsLabel bool
|
var flagCodeIsLabel bool
|
||||||
|
var flagPageSize string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ func main() {
|
|||||||
flag.StringVar(&flagFontStyle, "font-style", "", "font style, combine 'B', 'U', 'S', 'I' characters")
|
flag.StringVar(&flagFontStyle, "font-style", "", "font style, combine 'B', 'U', 'S', 'I' characters")
|
||||||
flag.BoolVar(&flagBorders, "borders", false, "print borders between labels")
|
flag.BoolVar(&flagBorders, "borders", false, "print borders between labels")
|
||||||
flag.StringVar(&flagFilename, "output", "", "filename to write the PDF")
|
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")
|
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.WithFont(flagFont, flagFontSize, flagFontStyle),
|
||||||
qr_labels.WithBorders(flagBorders),
|
qr_labels.WithBorders(flagBorders),
|
||||||
qr_labels.WithGrid(int(flagRows), int(flagCols)),
|
qr_labels.WithGrid(int(flagRows), int(flagCols)),
|
||||||
|
qr_labels.WithPageSize(flagPageSize),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -66,3 +66,17 @@ func WithGrid(rows, cols int) optWithGrid {
|
|||||||
cols: cols,
|
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
|
font string
|
||||||
fontStyle string
|
fontStyle string
|
||||||
fontSize float64
|
fontSize float64
|
||||||
rows int
|
|
||||||
cols int
|
rows int
|
||||||
borders bool
|
cols int
|
||||||
|
pageSize string
|
||||||
|
|
||||||
|
borders bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultPageOptions() []Option {
|
func defaultPageOptions() []Option {
|
||||||
@@ -29,6 +32,7 @@ func defaultPageOptions() []Option {
|
|||||||
WithQRSize(40),
|
WithQRSize(40),
|
||||||
WithFont("Courier", 16.0, "B"),
|
WithFont("Courier", 16.0, "B"),
|
||||||
WithGrid(4, 3),
|
WithGrid(4, 3),
|
||||||
|
WithPageSize("A4"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +97,7 @@ func GeneratePage(w io.Writer, url, label string, opts ...Option) error {
|
|||||||
}
|
}
|
||||||
// dim := qrc.Dimension()
|
// dim := qrc.Dimension()
|
||||||
|
|
||||||
pdf := fpdf.New("P", "mm", "A4", "")
|
pdf := fpdf.New("P", "mm", po.pageSize, "")
|
||||||
pdf.SetMargins(0, 0, 0)
|
pdf.SetMargins(0, 0, 0)
|
||||||
pageWidth, pageHeight := pdf.GetPageSize()
|
pageWidth, pageHeight := pdf.GetPageSize()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user