如何用golang打印?

I am trying to print on printer with go, but printer only prints strange characters ... I don't know how can I solve it.

If I print string it works, if I try print pdf on external software it works, only fail on go.

I used "github.com/jadefox10200/goprint"

printerHandle, err := goprint.GoOpenPrinter("CUSTOM K80")   
if err != nil {log("Failed to open printer")}
defer goprint.GoClosePrinter(printerHandle)

err = goprint.GoPrint(printerHandle, "hello.pdf")
if err != nil { log("during the func sendToPrinter, there was an error") }

Result:

> %PDF-1.3 3 0 obj <</Type /Page /Parent 1 0 R /Resources 2 0 R
> /Contents 4 0 R>> endobj 4 0 obj <</Filter /FlateDecode /Length 215>>
> stream
> x�ϿJ4A�|�����?�

Possible areas to check

  • jadefox goprint package might not perform rasterisation, or at least not for your "CUSTOM K80" printer. It might therefore pass the raw file contents to the printer for it to rasterise.

  • your printer might not support PDF internally. Many mid range and higher-end laser printers do. Cheaper printers often don't. Printers that don't parse PDF may instead treat the received data as plain ASCII text.