working printer

bypasstray leads to problems still
This commit is contained in:
2025-04-10 19:38:32 +02:00
parent 0436d3a2bd
commit e864a75678
6 changed files with 65 additions and 11 deletions

View File

@@ -79,6 +79,7 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
tagIds := ctx.PostFormArray("tags[]")
image, err := ctx.FormFile("image")
dstImage := defaultImagePath
printMode := ctx.PostForm("print-mode")
if err == nil {
dstImage = filepath.Join("static/uploads", image.Filename)
@@ -150,6 +151,7 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
Image: dstImage,
Pdf: dstPdf,
Variants: variants,
PrintMode: printMode,
}
for _, tagId := range tagIds {
@@ -381,6 +383,7 @@ func (rc *shopItemController) AddItemsHandler(c *gin.Context) {
Image: dstImage,
Pdf: dstPdf,
Variants: variants,
PrintMode: "CreateBooklet",
}
_, err = repositories.ShopItems.Create(shopItem)
@@ -448,6 +451,7 @@ func (rc *shopItemController) EditItemHandler(c *gin.Context) {
newShopItem.IsPublic = shopItem.IsPublic
newShopItem.Tags = shopItem.Tags
newShopItem.Variants = shopItem.Variants
newShopItem.PrintMode = shopItem.PrintMode
tags, err := repositories.Tags.GetAll()
if err != nil {

View File

@@ -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
}

View File

@@ -52,4 +52,5 @@ type ShopItem struct {
Tags []Tag `gorm:"many2many:item_tags;"`
Image string
Pdf string
PrintMode string `json:"printMode" gorm:"default:CreateBooklet"`
}

View File

@@ -1301,11 +1301,6 @@ video {
color: rgb(255 255 255 / var(--tw-text-opacity, 1));
}
.text-red-900 {
--tw-text-opacity: 1;
color: rgb(127 29 29 / var(--tw-text-opacity, 1));
}
.underline {
text-decoration-line: underline;
}

View File

@@ -123,6 +123,19 @@
</div>
</div>
<label class="block text-sm font-medium text-gray-900">
Print Mode
</label>
<select name="print-mode" required class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<option selected value="CreateBooklet">Create Booklet</option>
<option value="LongEdge">Long Edge</option>
<option value="ShortEdge">Short Edge</option>
</select>
<p class="text-sm">Choose 'Create Booklet' if its just a normal PDF (not converted to booklet already)</p>
<p class="mt-10 text-center text-sm/6 text-red-500">
{{ .data.error }}
</p>

View File

@@ -123,6 +123,16 @@
</div>
</div>
<label class="block text-sm font-medium text-gray-900">
Print Mode
</label>
<select name="print-mode" required class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<option selected value="CreateBooklet">Create Booklet</option>
<option value="LongEdge">Long Edge</option>
<option value="ShortEdge">Short Edge</option>
</select>
<p class="mt-10 text-center text-sm/6 text-red-500">
{{ .data.error }}
</p>