dbh789

Q: cupsfilter not working after El Capitan upgrade

I upgraded to 2 machines to El Capitan today and a script that has been working for years no longer works on either of them. This script worked just last week under the latest Yosemite. The problem occurs when it tries to convert an rtf file to pdf using the cupsfilter command. I've tried doing things "by hand" in the terminal and both-

 

"/usr/sbin/cupsfilter myText.rtf > test" and "cupsfilter myText.rtf > test"

 

give the same error message-

 

"cupsfilter: No filter to convert from text/rtf to application/pdf."

 

I checked that I can print to pdf from textedit and there is no problem doing the conversion.

 

Is anyone else having this problem? Any thoughts as to a solution?

iMac (21.5-inch, Late 2012), OS X El Capitan (10.11), null

Posted on Oct 1, 2015 10:31 PM

Close

Q: cupsfilter not working after El Capitan upgrade

  • All replies
  • Helpful answers

  • by Hiroto,

    Hiroto Hiroto Oct 2, 2015 4:25 AM in response to dbh789
    Level 5 (7,306 points)
    Oct 2, 2015 4:25 AM in response to dbh789

    Hello

     

    FYI, cupsfilter conversion from text/rtf to application/pdf is done by filter named nstexttopdf located at:

     

    /usr/libexec/cups/filter/nstexttopdf
    

     

     

    (under OS X 10.6.8)

     

    Is there this filter under OS X 10.11?

     

    H

  • by VikingOSX,

    VikingOSX VikingOSX Oct 3, 2015 7:59 AM in response to Hiroto
    Level 7 (21,061 points)
    Mac OS X
    Oct 3, 2015 7:59 AM in response to Hiroto

    Hiroto,

     

    OS X El Capitan build omitted the nstexttopdf filter. This is the default (only) filter that converts RTF to PDF, and does work on Yosemite 10.10.5. Well, it works if you don't mind it stripping out html links. I copied the nstexttopdf filter (from Yosemite) to its rightful spot in El Capitan, and same permissions/ownership as the other filters. The El Capitan cupsfilter command continues to utter the “No filter to convert from text/rtf to application/pdf.” Even when I force the -p nstexttopdf and -i text/rtf options. It would appear that Apple must have a list of valid filters in cupsfilter and removed nstexttopdf entry.

     

    I was thinking, about an NSAttributedString to PDFkit solution to process RTF/RTFD into PDF. Something that you can whip up in a few lines of Python bridge code?

     

    Just a note. RubyCocoa 1.2.0 for Yosemite will not install on El Capitan due to operating system too new.

  • by Hiroto,

    Hiroto Hiroto Oct 3, 2015 1:01 PM in response to VikingOSX
    Level 5 (7,306 points)
    Oct 3, 2015 1:01 PM in response to VikingOSX

    Hello

     

    As I understand, cupsfilters are to be defined in the form as:

     

    source-mime-type    destination-mime-type   cost    filter
    

     

     

    in

     

    /usr/share/cups/mime/apple.convs
    /usr/share/cups/mime/mime.types
    

     

     

    Under OS X 10.6.8, the following entry is in /usr/share/cups/mime/apple.convs:

     

    text/rtf        application/pdf 33  nstexttopdf
    

     

     

    And mime types with detection rules are to be defined in:

     

    /usr/share/cups/mime/apple.types
    /usr/share/cups/mime/mime.types
    

     

     

    Under OS X 10.6.8, the following entry is in /usr/share/cups/mime/apple.types:

     

    text/rtf            rtf string(0,"{\rtf") priority(200)
    

     

     

    cf.

    mime.convs(5), mime.types(5)

     

     

    ---

    As for converting rtf or rtfd to pdf via cocoa methods, we'd need to load NSAttributedString obtained from rtf or rtfd into NSTextView and perform NSPrintOperation on the view. I have written a rubycocoa script as proof of concept some years ago. It is simple but I'd like to refine it decently if I should publish it here.

     

    Regards,

    H

  • by Hiroto,

    Hiroto Hiroto Oct 3, 2015 1:38 PM in response to Hiroto
    Level 5 (7,306 points)
    Oct 3, 2015 1:38 PM in response to Hiroto

    Oops. The lines

     

    /usr/share/cups/mime/apple.convs
    /usr/share/cups/mime/mime.types
    

     

    should read

     

    /usr/share/cups/mime/apple.convs
    /usr/share/cups/mime/mime.convs
    

     

    H

  • by VikingOSX,

    VikingOSX VikingOSX Oct 3, 2015 2:57 PM in response to Hiroto
    Level 7 (21,061 points)
    Mac OS X
    Oct 3, 2015 2:57 PM in response to Hiroto

    Hiroto,

     

    For El Capitan, the only file in /usr/share/cups/mime directory that contains an rtf string as you noted above, is in apple.types. The mime.convs, and mime.types files are read only, and apparently, even by root, and with me as a member of group wheel, these permissions are unchangeable (no ACLS set).

  • by Hiroto,

    Hiroto Hiroto Oct 4, 2015 2:28 AM in response to VikingOSX
    Level 5 (7,306 points)
    Oct 4, 2015 2:28 AM in response to VikingOSX

    Hello

     

    It is some System Integrity Protection (SIP) newly introduced in OS X 10.11, I'd presume. You'd need to boot to Recovery OS, run the following command in Terminal and reboot to disbale SIP:

     

    csrutil disable
    

     

     

    cf.

    https://developer.apple.com/library/mac/documentation/Security/Conceptual/System _Integrity_Protection_Guide/

    https://developer.apple.com/library/mac/documentation/Security/Conceptual/System _Integrity_Protection_Guide/System_Integrity_Protection_Guide.pdf

     

     

    Honestly it would be the first thing I do if I were to use OS X 10.11.

     

    H

  • by VikingOSX,Helpful

    VikingOSX VikingOSX Oct 5, 2015 2:03 PM in response to Hiroto
    Level 7 (21,061 points)
    Mac OS X
    Oct 5, 2015 2:03 PM in response to Hiroto

    Hiroto,

     

    Thanks for the SIP information. You and I know what to do about that.

     

    Even if I could re-engineer the cups mime content to support the nstexttopdf filter again, I am not certain that I want to glorify defeating SIP, and the several root privilege steps to the potential solution, in an open community.

     

    The nstexttopdf filter drops hyperlinks in the RTF to PDF conversion on Yosemite, and soffice in the LibreOffice package does not. In the latter case, I set up a Bash function (to_pdf) to reduce typing. On the occasion where I have an RTFD document, I drop it on an AppleScript application that uses Pages '09 to do the RTFD to PDF conversion.

  • by Roote,Solvedanswer

    Roote Roote Oct 5, 2015 2:03 PM in response to dbh789
    Level 2 (417 points)
    Oct 5, 2015 2:03 PM in response to dbh789

    Hi dbh789. As mentioned by VikingOSX, until the cupsfilter issue is resolved one alternative is to use LibreOffice in headless mode. Assuming LibreOffice is installed in your Applications folder and the intended destination for the PDF is the current working directory, you can use the command:

    /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf /path/to/file
    

     

    Or you can specify the directory destination:

    Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf /path/to/file --outdir /path/to/directory
    

     

    The soffice conversion won't be as fast as using cupsfilter. There is also at least one conversion bug I'm aware of: emoji won't appear in the PDF.

  • by dbh789,

    dbh789 dbh789 Oct 5, 2015 2:00 PM in response to Roote
    Level 1 (0 points)
    Oct 5, 2015 2:00 PM in response to Roote

    This might be the solution. Thanks for the commands to do the conversion. (I've been quiet since deciding to boot into Yosemite from the clone I made just before installing El Capitan. I intended to check the cups filters there but ended up some how corrupting my El Capitan install to the point where even safe mode would not boot. One nuke and pave later and things are working fine).

     

    I looked into doing some gui scripting to use textedit for conversion but not so thrilled. Headless LibreOffice from a shell call sounds better than that for a long term fix. No emoji is no problem, I never even noticed the html link problem with the cups filter. If it can handle commas and colons, it would work for me.

     

    I'm also thinking about installing Yosemite on virtual box since that should solve this problem (I run my script for conversion only every so often but then it loops through 50 or so items at once, so I wouldn't need to start up the VM all that often and then I would be doing enough to make it worthwhile) It should also solve the fact that WINE is currently broken (unless you turn SIP off but that isn't so thrilling either and it means multiple reboots while I'm try to work. Done it a few times now and it does work but not exactly habit forming). Seems strange to consider running Yosemite in a VM in order to run Windows programs but I'm assuming WINE will work under El Capitan at some point, so that weird setup would be temporary.

  • by VikingOSX,

    VikingOSX VikingOSX Oct 5, 2015 2:22 PM in response to dbh789
    Level 7 (21,061 points)
    Mac OS X
    Oct 5, 2015 2:22 PM in response to dbh789

    I have used a bash function set up in my .bashrc file that allows me to forego the long headless LibreOffice command syntax. In my .bash_profile, I check for the .bashrc file, and then source it so this Bash to_pdf function is always present. LibreOffice cannot handle RTFD documents (with attachments). LibreOffice will retain formatting, text attributes, and hyperlinks.

     

    .bashrc

    to_pdf () {
    for file in "$@";
    do
        if [ -s $file ]; then
        /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf "${file}"
      else
      printf "\n%s\n\n" ">>> $file not found or zero length."
        continue
      fi
    done
    }
    
    

     

    The above will write the PDF in the same directory as the RTF document. By adding --outdir /path/to/PDF folder, you can redirect the conversion output.

     

    Usage in Bash shell:

    to_pdf foo.rtf bar.rtf baz.rtf

    to_pdf *.rtf

     

    .bash_profile

    [[ -s ~/.bashrc ]] && source ~/.bashrc