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

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

问题描述

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



我想我的问题是:如何为用户添加虚拟打印机驱动程序,将启动我开发的应用程序,将使PDF或者通过引用新生成的PDF来生成PDF并启动我的应用程序)?如何与CUPS连接以生成PDF?我不确定我是否清楚,所以让我知道更多的信息是有帮助的。



我通过了这打印与CUPS教程和似乎得到一切设置好,但文件似乎不会出现在适当的临时位置。如果任何人正在寻找用户端PDF打印机, this cups-pdf-for -mac-os-x 是一个通过安装程序工作,但是我有同样的问题没有文件出现在指定的目录,当我下载源,并按照readme中的说明。

解决方案

如果任何人可以通过终端在mac上工作,请告诉我一步一步。 div>

我真的希望我可以接受两个答案,因为我不认为我可以这样做没有所有的@Kurt Pfeifle的帮助Mac的具体情况,只是了解打印机驱动程序和文件的位置。但这里是我做的:







  1. 从codepoet下载源代码 cups-pdf-for-mac-os-x 。 (对于非mac,您可以查看 http://www.cups-pdf.de/ )自述很大程度上详细,如果你仔细阅读所有的说明,它会工作,但我有一点麻烦获取所有的部分,所以我将概述我做了什么,希望节省别人一些麻烦。为此,具有源代码的目录称为cups-pdfdownloaddir。


  2. 编译cups-pdf.c作为readme指定包含在src文件夹中:



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



    可能有一个警告: ld:warning:option -s已过时并被忽略,但这对我没有问题。将二进制文件复制到/ usr / libexec / cups / backend中。您可能需要使用 sudo 命令,它将提示您输入密码。例如:



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



    此外,不要忘记更改此文件的权限 - 它需要root权限(700),可以在移动cupd-pdf到后端目录:



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


  3. 编辑/cups-pdfdownloaddir/extra/cups-pdf.conf中包含的文件。在PDF转换设置标题下,在GhostScript下找到一行 #GhostScript / usr / bin / gs 。我没有注销它,以防万一我需要它,但只是在它下面添加行 Ghostscript / usr / bin / pstopdf



    在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



    在PDFVer下找到 #PDFVer 1.4 ,并将其更改为



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

    p>

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



    在文本编辑器中小心编辑,因为UNIX和Mac环境中的换行符不同,可能会破坏脚本。


  4. 您可以使用perl命令来删除它们,但我是偏执的,您现在应该能够打开一个程序(例如Word,Excel,...),然后选择文件>>打印并找到一个名为CUPS-PDF的可用打印机。打印到此打印机,默认情况下,您应该在/ var / spool / cups-pdf / yourusername /中找到您的pdf。







*此外,我认为这可能有帮助,因为它帮助我:如果有些东西在以下这些方向被拧紧,你需要重新开始/摆脱它,为了删除你需要的驱动程序(1)从 / usr删除cups-pdf后端/ etc / cups / (3)转到系统首选项> / libexec / cups / backend >打印&传真并删除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.

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.

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.

解决方案

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. 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".

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

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

    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

    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

  3. 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)

    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

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

    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

    Be careful of editing in a text editor because newlines in UNIX and Mac environments are different and can potentially ruin scripts. You can always use a perl command to remove them, but I'm paranoid and prefer not to deal with it in the first place.

  4. 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.


*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.


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!

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

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