简体   繁体   English

Ghostscript PDF 打印

[英]Ghostscript PDF printing

I would like to make my own "PDF printer" using Ghostscript.我想使用 Ghostscript 制作我自己的“PDF 打印机”。

Most of solutions I find on the internet involve a 3rd party like Redmon to redirect the PS printer to the Gs executable.我在互联网上找到的大多数解决方案都涉及像 Redmon 这样的第 3 方将 PS 打印机重定向到 Gs 可执行文件。

Is there a way to do the same without a 3rd party (other than Gs) ?有没有办法在没有 3rd 方(Gs 除外)的情况下做同样的事情?

Here is my 2 ideas:这是我的2个想法:

  • Bypass the printing driver and generate Postscript directly by software (From GDI to postscript, using maybe a custom device context like the Metafile device context exist)绕过打印驱动程序并直接通过软件生成 Postscript(从 GDI 到 postscript,使用可能存在像元文件设备上下文这样的自定义设备上下文)

  • Create programmatically a new local port for each document to convert.以编程方式为每个要转换的文档创建一个新的本地端口。 Maybe using this technique : https://stackoverflow.com/a/1331777/99276也许使用这种技术: https : //stackoverflow.com/a/1331777/99276

The first solution would be great, but can't find anything about it.第一个解决方案会很棒,但找不到任何相关信息。

And I am efraid the second is not efficient at all (and detect when the document is fully printed can be tricky)而且我害怕第二个根本没有效率(并且检测文档何时完全打印可能很棘手)

Update: I used print apis to print in a temp file (the print is synchronous) and then convert the PS file with Gs更新:我使用print apis 在临时文件中打印(打印是同步的),然后用Gs 转换PS 文件

Firstly;首先; note that the Windows printing system has been redesigned in Windows Vista and beyond.请注意,Windows 打印系统已在 Windows Vista 及更高版本中重新设计。 While the old system still works in WIndows 7 and 8, I am unsure of exactly how usable it is in Windows 10. In Windows 10 everything goes via XPS, and I think (could be wrong) that PostScript is generated by going via XPS first.虽然旧系统在 WINdows 7 和 8 中仍然可以使用,但我不确定它在 Windows 10 中的可用性究竟如何。在 Windows 10 中,一切都通过 XPS,我认为(可能是错误的)PostScript 是通过首先通过 XPS 生成的.

Your first idea doesn't sound plausible to me.你的第一个想法对我来说听起来不合理。 How can you have a printer (and allow your application to print to it) if you don't have a printer driver ?如果您没有打印机驱动程序,您如何拥有打印机(并允许您的应用程序打印到它)? Even if you could do so, why would you create PostScript from GDI just to send it to Ghostscript and have it create PDF ?即使你可以这样做,你为什么要从 GDI 创建 PostScript 只是为了将它发送到 Ghostscript 并让它创建 PDF ? It would be far more reasonable to create PDF directly.直接创建 PDF 会更合理。

In the second case I don't see how adding a new local port would help you at all.在第二种情况下,我根本看不出添加新的本地端口对您有什么帮助。 Ports are simply where the output of the printer driver is directed.端口只是指向打印机驱动程序输出的地方。 What a Port Monitor (RedMon is a Port Monitor) does is redirect the data stream sent to the port, and 'do something' with it.端口监视器(RedMon 是端口监视器)所做的是重定向发送到端口的数据流,并对其进行“处理”。 In the case of Ghostscript + RedMon the 'something' is create a PDF file.在 Ghostscript + RedMon 的情况下,“东西”是创建一个 PDF 文件。

I'm unclear why you don't want to use RedMon, given that you are apparently happy with using Ghostscript.我不清楚您为什么不想使用 RedMon,因为您显然对使用 Ghostscript 感到满意。 However, if you really don't want to do that then write your own Port Monitor.但是,如果您真的不想这样做,请编写您自己的端口监视器。 The process is documented in the Windows Device Driver Development Kit and isn't especially hard.该过程记录在 Windows 设备驱动程序开发工具包中,并不是特别困难。 If you get stuck you can even look at the RedMon code as a guide.如果您遇到困难,您甚至可以查看 RedMon 代码作为指南。 For example, see here例如,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM