英文:
Printing via Winspool
问题
我正在尝试为一个网站设置一种打印服务,用于与之通信并发送可打印文档(pdf、html、excel)。我决定使用Go语言。
我创建了下面这个简单的程序。在某些电脑上(Windows 7)它可以工作,而在其他电脑上(Windows 8)却不能工作(正确)。当它不能工作时,作业在打印队列中可见不到一秒钟就消失了。代码没有输出任何错误。我在Windows事件日志中找不到任何信息。
我还尝试了在网上找到的一个C++的RawPrinter示例,但它显示相同的行为。
有人知道我做错了什么吗?:(
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)
}
}
英文:
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)
}
}
答案1
得分: 5
你正在使用数据类型"RAW",应该使用"XPS_PASS"。
Windows 8(和Server 2012)使用基于XPS的驱动程序,因此无法使用RAW标志。
请查看以下文章:
http://support.microsoft.com/kb/2779300
http://msdn.microsoft.com/en-us/library/windows/desktop/ff686812%28v=vs.85%29.aspx
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论