How to write a virtual printer driver for Mac OSX [closed]

▼魔方 西西 提交于 2019-12-04 07:59:46

问题


I need to write a "virtual printer driver" for OSX, so that when the user presses Command+P to open the Print dialog, he sees my virtual printer...which will be used to generate files of various types, instead of physically printing to paper.

I'm new to the subject, I looked around a bit but found nothing. Do you have any link or reference to documentation that cover this topic?


回答1:


Rather than writing a driver, consider using the PDF Services feature of OS X print dialogs. In either the system-wide /Library/PDF Services or a user's ~/Library/PDF Services directory, you can put AppleScripts, Automator workflows, or symlinks/aliases to applications or folders. Those items will appear in the PDF pop-up menu in the print dialog, and if the user selects the item, a PDF of the file will be placed in the folder or be passed to the application, script, or workflow.




回答2:


It is called VipRiser - an extensible virtual PDF printer

There is already a driver that does that. VipRiser installs a printer that saves to a file. I use it to 'print out' to a file sheet music I buy online. The existing 'Save to PDF' options at the bottom of the printer dialog won't work because the vendor of the music has disabled this function and you must print to a printer.

For the broadest and simplest support for printing to a virtual printer I use VipRiser rather than using PDF services. PDF Services work in some cases but many sites are preventing the use of PDF Services.




回答3:


In case the printer driver is absolutely needed and the PDF services are not suitable.

The solution is to write your own CUPS driver - both Mac OS and Linux use CUPS for printing, so solution could work for both systems.

The documentation for CUPS provides an instruction on writing a driver (https://www.cups.org/doc/postscript-driver.html), which generally consists of creating:

  • A "filter" program that converts the input to printer code and sends it to a printer.
  • A PPD file that describes the printer (https://en.wikipedia.org/wiki/PostScript_Printer_Description)

There's a good tutorial on how to write one in python: https://behind.pretix.eu/2018/01/20/cups-driver/ and provides example open source for driving a FGL printer: https://github.com/pretix/cups-fgl-printers that can be adapted to your needs.



来源:https://stackoverflow.com/questions/2273213/how-to-write-a-virtual-printer-driver-for-mac-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!