winapiwindows-8goprint-spooler-api

Printing via Winspool


I'm trying to set up a kind of print service for a website to communicate with and send printable documents to (pdf, html, excel). I decided on Go.

I created the simple program below. On some PCs it works (Windows 7) on other ones (Windows 8) it doesn't work (right). When it doesn't work the job is visible in the print queue for less then a second and then disappears. The code doesn't output any errors. I can't find anything in the Windows event log.

I also tried a RawPrinter example in c++ I could find online but that shows the same behavior.

Does anyone know what I'm doing wrong? :(

package main

import (
    "fmt"
    "code.google.com/p/brainman/printer"
)


func main() {
    defaultPrinterName, _ := printer.Default()
    fmt.Println(defaultPrinterName)
    p, err := printer.Open(defaultPrinterName)

    if err != nil {
        fmt.Println("Open failed: %v", err)
    }

    defer p.Close()

    err = p.StartDocument("my document", "RAW")

    if err != nil {
        fmt.Println("StartDocument failed: %v", err)
    }

    defer p.EndDocument()

    err = p.StartPage()

    if err != nil {
        fmt.Println("StartPage failed: %v", err)
    }

    str := "testing 123"
    mySlice := []byte(str)

    _, err = p.Write(mySlice)

    if err != nil {
        fmt.Println("Write failed: %v", err)
    }

    err = p.EndPage()

    if err != nil {
        fmt.Println("EndPage failed: %v", err)
    }
}

Solution

  • You're using the datatype "RAW", it should be "XPS_PASS".

    Windows 8 (and Server 2012) uses XPS-based drivers so you can't use the RAW flag.

    Check out these articles: http://support.microsoft.com/kb/2779300 http://msdn.microsoft.com/en-us/library/windows/desktop/ff686812%28v=vs.85%29.aspx