working printer
bypasstray leads to problems still
This commit is contained in:
@@ -2,14 +2,19 @@ package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PrintOption string
|
||||
|
||||
const (
|
||||
CoverPage PrintOption = "-o FrontCoverPage=Printed -o FrontCoverTray=BypassTray -o InputSlot=Tray1"
|
||||
Colored PrintOption = "-o SelectColor=Color"
|
||||
Grayscale PrintOption = "-o SelectColor=Grayscale"
|
||||
CoverPage PrintOption = "-o FrontCoverPage=Printed -o FrontCoverTray=Tray2 -o InputSlot=Tray1"
|
||||
Colored PrintOption = "-o SelectColor=Color"
|
||||
Grayscale PrintOption = "-o SelectColor=Grayscale"
|
||||
CreateBooklet PrintOption = "-o Combination=Booklet -o PageSize=A5"
|
||||
LongEdge PrintOption = ""
|
||||
ShortEdge PrintOption = "-o Binding=TopBinding"
|
||||
)
|
||||
|
||||
type PrintJob struct {
|
||||
@@ -18,6 +23,18 @@ type PrintJob struct {
|
||||
Options []PrintOption
|
||||
}
|
||||
|
||||
func GetPrintMode(mode string) PrintOption {
|
||||
if mode == "LongEdge" {
|
||||
return LongEdge
|
||||
}
|
||||
|
||||
if mode == "ShortEdge" {
|
||||
return ShortEdge
|
||||
}
|
||||
|
||||
return CreateBooklet
|
||||
}
|
||||
|
||||
func NewPrintJob(shopItem ShopItem, variant ItemVariant, coverPage bool, amount uint) (PrintJob, error) {
|
||||
if shopItem.Pdf == "" {
|
||||
return PrintJob{}, fmt.Errorf("ShopItem has no PDF assigned")
|
||||
@@ -39,12 +56,14 @@ func NewPrintJob(shopItem ShopItem, variant ItemVariant, coverPage bool, amount
|
||||
result.Options = append(result.Options, CoverPage)
|
||||
}
|
||||
|
||||
result.Options = append(result.Options, GetPrintMode(shopItem.PrintMode))
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (p *PrintJob) Execute() error {
|
||||
baseCommand := "lp -p KONICA_MINOLTA_KONICA_MINOLTA_bizhub_C258/Booklet "
|
||||
baseCommand += fmt.Sprintf("-n %v ", p.Amount)
|
||||
baseCommand := "lp -d KONICA_MINOLTA_KONICA_MINOLTA_bizhub_C258/BookletPrint -o Fold=HalfFold"
|
||||
baseCommand += fmt.Sprintf(" -n %v ", p.Amount)
|
||||
|
||||
for _, option := range p.Options {
|
||||
baseCommand += fmt.Sprintf(" %v ", option)
|
||||
@@ -52,6 +71,18 @@ func (p *PrintJob) Execute() error {
|
||||
|
||||
baseCommand += fmt.Sprintf(" -- %s", p.Pdf)
|
||||
|
||||
fmt.Println(baseCommand)
|
||||
parts := strings.Fields(baseCommand)
|
||||
|
||||
// The first part is the command, the rest are the arguments
|
||||
fmt.Println(parts)
|
||||
cmd := exec.Command(parts[0], parts[1:]...)
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Output:\n%s\n", output)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user