Filter / backend programming for Print to PDF using CUPS from any Mac OS X application

Ok, that’s what I want to do. I want to add a print option that prints any user document in PDF format and adds some headers before sending it to the device.

I think my questions are: how to add a virtual “printer” driver for the user who will launch the application that I was developing to make a PDF (or make a PDF and launch my application with links to a newly created PDF)? How can I interact with CUPS to create a PDF file? I'm not sure I'm clearing up, so let me know if additional information is helpful.

I worked through this print with a CUPS tutorial and everything seems to be configured fine, but the file never appears at the appropriate temporary location. And if someone is looking for a custom PDF printer, this cups-pdf-for-mac-os-x is the one that works through the installer, however I have the same problem as the file specified in the specified directory when I download the source and follow the instructions in readme. If anyone can get any of them to work on a Mac through a terminal, please let me know step by step how you did it.

+8
printing pdf cocoa cups
source share
2 answers

I'm sorry that I can’t accept the two answers, because I don’t think I could have done it without any help from @Kurt Pfeifle for the specifics of the Mac and just understanding the drivers and file locations. But here is what I did:


  • Download the source code from codepoet cups-pdf-for-mac-os-x . (For non-macs, you can see http://www.cups-pdf.de/ ). The Readme is very detailed, and if you carefully read all the instructions, it will work, but I had a bit of trouble getting all the parts, so I will definitely tell you what I did in the hope of saving someone else from some trouble. For this, the source directory is called "cups-pdfdownloaddir".

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

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

    A warning may appear: ld: warning: option -s is obsolete and being ignored , but for me this is not a problem. Copy the binary to / usr / libexec / cups / backend. You will probably need the sudo , which will prompt you to enter a password. For example:

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

    In addition, do not forget to change the access rights to this file - this requires root permissions (700), which can be changed as follows after moving cupd-pdf to the backend directory:

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

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

    Find a 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 a split, under this I added the line GSCall %s %s -o %s %s

    Locate the line under PDFVer that reads #PDFVer 1.4 and changes it to PDFVer , spaces or the 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 when editing in a text editor, because newlines on UNIX and Mac environments are different and can potentially destroy scripts. You can always use the perl command to remove them, but I'm paranoid and prefer not to deal with it in the first place.

  • Now you can open the program (for example, Word, Excel, ...) and select "File → Print" and find an available printer called CUPS-PDF. Print this printer and you should find your pdf files in / var / spool / cups-pdf / yourusername / by default.


* In addition, I thought that this could be useful, because it helped me: if something is screwed in accordance with these instructions, and you need to start / get rid of it in order to remove the driver that you need (1 ) (2) remove cups-pdf.conf from /etc/cups/ (3) Go to System Preferences → Print and Fax and Remove CUPS-PDF Printer.


This is how I successfully configured the pdf file / filter for myself, however there is more detailed information and other configuration information contained in the readme file. Hope this helps someone else!

+5
source share

The way to this:

  • Configure the print queue with any driver that suits you. But I recommend using the PostScript / PPD driver. (PostScript PPD is one that does not contain the string *cupsFilter: ... ):

  • First, use a (educational) CUPS server named 2dir . This can be copied from this website: WDE . Make sure you get the correct lines (Unix-like) when copying.

  • Command line to configure the initial queue:

      lpadmin \
         -p pdfqueue \
         -v 2dir: / tmp / pdfqueue \
         -E \
         -P /path/to/postscript-printer.ppd
    
    The 2dir 2dir will now write all output to the /tmp/pdfqueue/ , and it will use the uniq name for each job. Each result must be a PostScript file . (without any changes you still want).
  • Find the PPD used by this queue in /etc/cups/ppd/ (its name should be pdfqueue.ppd ).

  • Add the following line (best at the top of the PPD):

     * cupsFilter: "application / pdf 0 -" 
    (make sure *cupsFilter starts at the very beginning of the line.) This line tells cupsd set up a filter chain that creates a PDF, and then the last filter called '-' called before it sends the file through the backend to the printer. This '-' filter is special: it does nothing, it is a pass-through filter.
  • Launch the CUPS Scheduler:

      sudo launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist
     sudo launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist 
  • Now your pdfqueue will cause each job to be printed before as a PDF in /tmp/pdfqueue/*.pdf .

  • Explore the 2dir script backend. It is simple Bash and well commented enough.

  • Change 2dir so that it adds your desired changes to your PDF before saving the result in /tmp/pdfqueue/*.pdf ...


Update: Looks like I forgot 2 quotes in my originally given string *cupsFilter: ... above. Sorry!

+10
source share

All Articles