Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printer.go:43:27: undefined: syscall.Filetime #13

Open
joeblew99 opened this issue Oct 14, 2019 · 1 comment
Open

printer.go:43:27: undefined: syscall.Filetime #13

joeblew99 opened this issue Oct 14, 2019 · 1 comment

Comments

@joeblew99
Copy link

joeblew99 commented Oct 14, 2019

I am on darwin BTW. Might be because of this ?

clean first:

	go clean --modcache

example:

package main

import (
    "bytes"
    "flag"
    "fmt"
    "log"
    "runtime"
    "time"

    prt "github.com/alexbrainman/printer"

    "github.com/jung-kurt/gofpdf"
)

func main() {
    log.SetFlags(log.LstdFlags | log.Llongfile)
    printFormat := flag.String("format", "pdf", "print the pdf content")
    savePDF := flag.Bool("s", false, "save pdf only")
    flag.Parse()

    // pdf output
    if *savePDF {
        // create pdf
        pdf := newReport()

        // Save pdf to disc
        pdf.OutputFileAndClose("report.pdf")
    } else {
        var buf []byte
        var datatype string

        // switch between formats
        switch *printFormat {
        case "text":
            buf = []byte("Text report")
            datatype = "text"
        case "pdf":
            // create pdf
            pdf := newReport()
            var b bytes.Buffer
            err := pdf.Output(&b)
            if err != nil {
                fmt.Println(err)
            }
            buf = b.Bytes()
            datatype = "raw"
        }

        // send content to printer
        fmt.Println(string(buf))
        printContent(datatype, buf)
    }
}

func newReport() *gofpdf.Fpdf {
    pdf := gofpdf.NewCustom(&gofpdf.InitType{
        UnitStr:        "mm",
        Size:           gofpdf.SizeType{Wd: 62, Ht: 90},
        OrientationStr: "P",
    })

    // Pagebreak
    pdf.SetAutoPageBreak(false, 0)

    // Fileinformations
    pdf.SetTitle("Test PDF", true)

    // Page Margin
    pdf.SetMargins(1, 1, 1)

    // We start by adding a new page to the document.
    pdf.AddPage()

    // UTF8 from File
    trans := pdf.UnicodeTranslatorFromDescriptor("")

    // Title
    pdf.SetFont("Arial", "B", 6)
    pdf.CellFormat(0, 2, trans("Test PDF"), "", 0, "C", false, 0, "")

    // The `Ln()` function moves the current position to a new line, with
    // an optional line height parameter.
    pdf.Ln(-1)

    pdf.SetFont("Arial", "", 5)
    pdf.CellFormat(0, 2, time.Now().Format("02.01.2006   15:04"), "", 0, "C", false, 0, "")
    pdf.Ln(-1)
    pdf.SetFont("Arial", "B", 5)
    pdf.CellFormat(0, 2, trans("new text in pdf"), "", 0, "C", false, 0, "")
    pdf.Ln(3)

    return pdf
}

func printContent(datatype string, content []byte) {
    if runtime.GOOS == "windows" {
        name, err := prt.Default() // returns name of Default Printer as string
        if err != nil {
            fmt.Println(err)
        }
        fmt.Println(name)
        p, err := prt.Open(name) // Opens the named printer and returns a *Printer
        if err != nil {
            fmt.Println(err)
        }

        err = p.StartDocument("test", datatype)
        if err != nil {
            fmt.Println(err)
        }
        err = p.StartPage() // begin a new page
        if err != nil {
            fmt.Println(err)
        }

        n, err := p.Write(content) // Send some text to the printer
        if err != nil {
            fmt.Println(err)
        }
        fmt.Println("Num of bytes written to printer:", n)

        err = p.EndPage() // end of page
        if err != nil {
            fmt.Println(err)
        }
        err = p.EndDocument() // end of document
        if err != nil {
            fmt.Println(err)
        }
        err = p.Close() // close the resource
        if err != nil {
            fmt.Println(err)
        }
    }
}

@alexbrainman
Copy link
Owner

I am on darwin BTW. Might be because of this ?

I am sure, that is the reason. This package is only designed to work on Windows.

If I try to build this on my Linux computer, I get the same error as you are.

$ go build -v -o /dev/null github.com/alexbrainman/printer
github.com/alexbrainman/printer
# github.com/alexbrainman/printer
src/github.com/alexbrainman/printer/printer.go:43:27: undefined: syscall.Filetime
src/github.com/alexbrainman/printer/printer.go:55:27: undefined: syscall.Filetime
src/github.com/alexbrainman/printer/printer.go:72:15: undefined: syscall.Systemtime
src/github.com/alexbrainman/printer/printer.go:155:4: undefined: syscall.Handle
src/github.com/alexbrainman/printer/zapi.go:38:21: undefined: syscall.Handle
src/github.com/alexbrainman/printer/zapi.go:50:35: undefined: syscall.Handle
src/github.com/alexbrainman/printer/zapi.go:62:24: undefined: syscall.Handle
src/github.com/alexbrainman/printer/zapi.go:74:22: undefined: syscall.Handle
src/github.com/alexbrainman/printer/zapi.go:86:21: undefined: syscall.Handle
src/github.com/alexbrainman/printer/zapi.go:98:25: undefined: syscall.Handle
src/github.com/alexbrainman/printer/zapi.go:98:25: too many errors
$ GOOS=windows go build -v -o /dev/null github.com/alexbrainman/printer
github.com/alexbrainman/printer
$

I don't plan extending this package to work on any non-Windows OS.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants