从任何 Mac OS X 应用程序使用 CUPS 将过滤器/后端编程为“打印到 PDF" [英] Programming a Filter/Backend to 'Print to PDF' with CUPS from any Mac OS X application

查看:32
本文介绍了从任何 Mac OS X 应用程序使用 CUPS 将过滤器/后端编程为“打印到 PDF"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这就是我想要做的.我想添加一个打印选项,将用户的文档打印到 PDF 并在将其发送到设备之前添加一些标题.

Okay so here is what I want to do. I want to add a print option that prints whatever the user's document is to a PDF and adds some headers before sending it off to a device.

我想我的问题是:我如何为用户添加一个虚拟打印机"驱动程序,该驱动程序将启动我一直在开发的应用程序来制作 PDF(或制作 PDF 并启动我的应用程序并参考新生成的PDF)?如何与 CUPS 交互以生成 PDF?我不确定我是否清楚,所以如果更多信息有帮助,请告诉我.

I guess my questions are: how do I add a virtual "printer" driver for the user that will launch the application I've been developing that will make the PDF (or make the PDF and launch my application with references to the newly generated PDF)? How do I interface with CUPS to generate the PDF? I'm not sure I'm being clear, so let me know if more information would be helpful.

我已经完成了使用 CUPS 打印教程 并且似乎一切设置正常,但该文件似乎从未出现在适当的临时位置.如果有人正在寻找用户端 PDF 打印机,这个cups-pdf-for-mac-os-x 是通过安装程序运行的一个,但是当我下载源代码并按照自述文件中的说明进行操作时,我遇到了相同的问题,即指定目录中没有文件出现.如果有人可以通过终端让其中任何一个在 Mac 上工作,请告诉我您是如何做到的.

I've worked through this printing with CUPS tutorial and seem to get everything set up okay, but the file never seems to appear in the appropriate temporary location. And if anyone is looking for a user-end PDF-printer, this cups-pdf-for-mac-os-x is one that works through the installer, however I have the same issue of no file appearing in the indicated directory when I download the source and follow the instructions in the readme. If anyone can get either of these to work on a mac through the terminal, please let me know step-by-step how you did it.

推荐答案

我真的希望我能接受两个答案,因为如果没有 @Kurt Pfeifle 对 Mac 细节的所有帮助,我认为我无法做到这一点,而且只是了解打印机驱动程序和文件位置.但这是我所做的:

I really wish I could accept two answers because I don't think I could have done this without all of @Kurt Pfeifle 's help for Mac specifics and just understanding printer drivers and locations of files. But here's what I did:

  1. 从codepoet下载源代码cups-pdf-for-mac-os-x.(非macs可以看http://www.cups-pdf.de/)readme很大详细,如果您仔细阅读所有说明,它将起作用,但是我在获取所有部分时遇到了一些麻烦,因此我将准确概述我所做的工作,希望能给其他人带来一些麻烦.为此,包含源代码的目录称为cups-pdfdownloaddir".

  1. Download the source code from codepoet cups-pdf-for-mac-os-x. (For non-macs, you can look at http://www.cups-pdf.de/) The readme is greatly detailed and if you read all of the instructions carefully, it will work, however I had a little trouble getting all the pieces, so I will outline exactly what I did in the hopes of saving someone else some trouble. For this, the directory with the source code is called "cups-pdfdownloaddir".

按照自述文件的规定编译 src 文件夹中包含的 cups-pdf.c:

Compile cups-pdf.c contained in the src folder as the readme specifies:

gcc -09 -s -lcups -o cups-pdf cups-pdf.c

可能会有一个警告:ld:warning: option -s is obsolete and being disabled,但这对我来说没有问题.将二进制文件复制到/usr/libexec/cups/backend.您可能需要使用 sudo 命令,它会提示您输入密码.例如:

There may be a warning: ld: warning: option -s is obsolete and being ignored, but this posed no issue for me. Copy the binary into /usr/libexec/cups/backend. You will likely have to the sudo command, which will prompt you for your password. For example:

sudo cp/cups-pdfdownloaddir/src/cups-pdf/usr/libexec/cups/backend

另外,不要忘记更改此文件的权限——它需要 root 权限(700),可以在将 cupd-pdf 移动到后端目录后使用以下内容进行更改:

Also, don't forget to change the permissions on this file--it needs root permissions (700) which can be changed with the following after moving cupd-pdf into the backend directory:

sudo chmod 700/usr/libexec/cups/backend/cups-pdf

编辑包含在/cups-pdfdownloaddir/extra/cups-pdf.conf 中的文件.在PDF Conversion Settings"标题下,在 GhostScript 下找到一行,内容为 #GhostScript/usr/bin/gs.我没有取消注释,以防万一我需要它,只是在它下面添加了 Ghostscript/usr/bin/pstoppdf 行.(任何这些修改都不应有前标 #)

Edit the file contained in /cups-pdfdownloaddir/extra/cups-pdf.conf. Under the "PDF Conversion Settings" header, find a line under the GhostScript that reads #GhostScript /usr/bin/gs. I did not uncomment it in case I needed it, but simply added beneath it the line Ghostscript /usr/bin/pstopdf. (There should be no pre-cursor # for any of these modifications)

在 GSCall 下找到读取 #GSCall %s -q -dCompatibilityLevel=%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile="%s" -dAutoRotatePage 的行s=/PageByPage -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dPDFSETTINGS=/prepress -c .setpdfwrite -f %s 再次没有取消注释,在此之下我添加了行 GSCall %s %s -o %s %s

Find the line under GSCall that reads #GSCall %s -q -dCompatibilityLevel=%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile="%s" -dAutoRotatePage s=/PageByPage -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dPDFSETTINGS=/prepress -c .setpdfwrite -f %s Again without uncommenting this, under this I added the line GSCall %s %s -o %s %s

在 PDFVer 下找到读取 #PDFVer 1.4 的行并将其更改为 PDFVer,没有空格或后面的字符.

Find the line under PDFVer that reads #PDFVer 1.4 and change it to PDFVer, no spaces or following characters.

现在保存并退出编辑,然后使用以下命令将此文件复制到/etc/cups

Now save and exit editing before copying this file to /etc/cups with the following command

sudo cp cups-pdfdownloaddir/extra/cups-pdf.conf/etc/cups

在文本编辑器中编辑时要小心,因为 UNIX 和 Mac 环境中的换行符不同,可能会破坏脚本.你总是可以使用 perl 命令来删除它们,但我很偏执,不想一开始就处理它.

您现在应该能够打开一个程序(例如 Word、Excel 等)并选择文件 >> 打印并找到名为 CUPS-PDF 的可用打印机.打印到这台打印机,默认情况下您应该在/var/spool/cups-pdf/yourusername/中找到您的 pdf.

You should now be able to open a program (e.g. Word, Excel, ...) and select File >> Print and find an available printer called CUPS-PDF. Print to this printer, and you should find your pdfs in /var/spool/cups-pdf/yourusername/ by default.

<小时>

*此外,我认为这可能会有所帮助,因为它对我有所帮助:如果按照这些说明操作时出现问题,您需要重新开始/摆脱它,为了删除驱动程序,您需要 (1)从/usr/libexec/cups/backend 中删除cups-pdf backend (2) 从/etc/cups/ 中删除cups-pdf.conf (3) 进入系统偏好设置 >> 打印 &传真并删除 CUPS-PDF 打印机.


*Also, I figured this might be helpful because it helped me: if something gets screwed up in following these directions and you need to start over/get rid of it, in order to remove the driver you need to (1) remove the cups-pdf backend from /usr/libexec/cups/backend (2) remove the cups-pdf.conf from /etc/cups/ (3) Go into System Preferences >> Print & Fax and delete the CUPS-PDF printer.

这就是我为自己成功设置 pdf 后端/过滤器的方式,但是自述文件中包含更多详细信息和其他有关自定义的信息.希望这对其他人有帮助!

This is how I successfully set up a pdf backend/filter for myself, however there are more details, and other information on customization contained in the readme file. Hope this helps someone else!

这篇关于从任何 Mac OS X 应用程序使用 CUPS 将过滤器/后端编程为“打印到 PDF"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆