working printer
bypasstray leads to problems still
This commit is contained in:
@@ -79,6 +79,7 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
|||||||
tagIds := ctx.PostFormArray("tags[]")
|
tagIds := ctx.PostFormArray("tags[]")
|
||||||
image, err := ctx.FormFile("image")
|
image, err := ctx.FormFile("image")
|
||||||
dstImage := defaultImagePath
|
dstImage := defaultImagePath
|
||||||
|
printMode := ctx.PostForm("print-mode")
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dstImage = filepath.Join("static/uploads", image.Filename)
|
dstImage = filepath.Join("static/uploads", image.Filename)
|
||||||
@@ -150,6 +151,7 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
|||||||
Image: dstImage,
|
Image: dstImage,
|
||||||
Pdf: dstPdf,
|
Pdf: dstPdf,
|
||||||
Variants: variants,
|
Variants: variants,
|
||||||
|
PrintMode: printMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tagId := range tagIds {
|
for _, tagId := range tagIds {
|
||||||
@@ -381,6 +383,7 @@ func (rc *shopItemController) AddItemsHandler(c *gin.Context) {
|
|||||||
Image: dstImage,
|
Image: dstImage,
|
||||||
Pdf: dstPdf,
|
Pdf: dstPdf,
|
||||||
Variants: variants,
|
Variants: variants,
|
||||||
|
PrintMode: "CreateBooklet",
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = repositories.ShopItems.Create(shopItem)
|
_, err = repositories.ShopItems.Create(shopItem)
|
||||||
@@ -448,6 +451,7 @@ func (rc *shopItemController) EditItemHandler(c *gin.Context) {
|
|||||||
newShopItem.IsPublic = shopItem.IsPublic
|
newShopItem.IsPublic = shopItem.IsPublic
|
||||||
newShopItem.Tags = shopItem.Tags
|
newShopItem.Tags = shopItem.Tags
|
||||||
newShopItem.Variants = shopItem.Variants
|
newShopItem.Variants = shopItem.Variants
|
||||||
|
newShopItem.PrintMode = shopItem.PrintMode
|
||||||
|
|
||||||
tags, err := repositories.Tags.GetAll()
|
tags, err := repositories.Tags.GetAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -2,14 +2,19 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PrintOption string
|
type PrintOption string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CoverPage PrintOption = "-o FrontCoverPage=Printed -o FrontCoverTray=BypassTray -o InputSlot=Tray1"
|
CoverPage PrintOption = "-o FrontCoverPage=Printed -o FrontCoverTray=Tray2 -o InputSlot=Tray1"
|
||||||
Colored PrintOption = "-o SelectColor=Color"
|
Colored PrintOption = "-o SelectColor=Color"
|
||||||
Grayscale PrintOption = "-o SelectColor=Grayscale"
|
Grayscale PrintOption = "-o SelectColor=Grayscale"
|
||||||
|
CreateBooklet PrintOption = "-o Combination=Booklet -o PageSize=A5"
|
||||||
|
LongEdge PrintOption = ""
|
||||||
|
ShortEdge PrintOption = "-o Binding=TopBinding"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PrintJob struct {
|
type PrintJob struct {
|
||||||
@@ -18,6 +23,18 @@ type PrintJob struct {
|
|||||||
Options []PrintOption
|
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) {
|
func NewPrintJob(shopItem ShopItem, variant ItemVariant, coverPage bool, amount uint) (PrintJob, error) {
|
||||||
if shopItem.Pdf == "" {
|
if shopItem.Pdf == "" {
|
||||||
return PrintJob{}, fmt.Errorf("ShopItem has no PDF assigned")
|
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, CoverPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.Options = append(result.Options, GetPrintMode(shopItem.PrintMode))
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PrintJob) Execute() error {
|
func (p *PrintJob) Execute() error {
|
||||||
baseCommand := "lp -p KONICA_MINOLTA_KONICA_MINOLTA_bizhub_C258/Booklet "
|
baseCommand := "lp -d KONICA_MINOLTA_KONICA_MINOLTA_bizhub_C258/BookletPrint -o Fold=HalfFold"
|
||||||
baseCommand += fmt.Sprintf("-n %v ", p.Amount)
|
baseCommand += fmt.Sprintf(" -n %v ", p.Amount)
|
||||||
|
|
||||||
for _, option := range p.Options {
|
for _, option := range p.Options {
|
||||||
baseCommand += fmt.Sprintf(" %v ", option)
|
baseCommand += fmt.Sprintf(" %v ", option)
|
||||||
@@ -52,6 +71,18 @@ func (p *PrintJob) Execute() error {
|
|||||||
|
|
||||||
baseCommand += fmt.Sprintf(" -- %s", p.Pdf)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,4 +52,5 @@ type ShopItem struct {
|
|||||||
Tags []Tag `gorm:"many2many:item_tags;"`
|
Tags []Tag `gorm:"many2many:item_tags;"`
|
||||||
Image string
|
Image string
|
||||||
Pdf string
|
Pdf string
|
||||||
|
PrintMode string `json:"printMode" gorm:"default:CreateBooklet"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1301,11 +1301,6 @@ video {
|
|||||||
color: rgb(255 255 255 / var(--tw-text-opacity, 1));
|
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 {
|
.underline {
|
||||||
text-decoration-line: underline;
|
text-decoration-line: underline;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</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">
|
<p class="mt-10 text-center text-sm/6 text-red-500">
|
||||||
{{ .data.error }}
|
{{ .data.error }}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -123,6 +123,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</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">
|
<p class="mt-10 text-center text-sm/6 text-red-500">
|
||||||
{{ .data.error }}
|
{{ .data.error }}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user