通过Winspool打印

huangapple go评论85阅读模式
英文:

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? 通过Winspool打印

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

huangapple
  • 本文由 发表于 2015年1月13日 16:36:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/27917857.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定