Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to create a bash function called url2pdf:

wget -O "$1" | /System/Library/Printers/Libraries/convert | open -a Preview

However, whenever I try and execute this, I get:

HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “STDOUT”

[ <=>                                                                          ] 0 --.-K/s   in 0s      


Cannot write to “-” (Broken pipe).

So I am guessing there is something wrong with my pipe redirection. Any suggestions?

share|improve this question
    
I normally wouldn't comment on such an old post, but this one was a relatively high result when I googled for "url to pdf" so I thought it was worth mentioning: 'convert' is no longer part of Mac OS X 10.8 but you can get much of the same thing accomplished with cupsfilter (part of OS X) but the args are different. Most notably, it takes one file as an arg, and sends its output to stdout, so you have to redirect to a file if you want to save to PDF. Hope this helps someone else. –  TJ Luoma Aug 6 '13 at 20:17
add comment

1 Answer

up vote 0 down vote accepted

the convert program doesn't seem to like STDIN streams that come from pipes:

ian-cs-macbook-pro:temp ianc$ echo "Hello world" | /System/Library/Printers/Libraries/convert
Usage: convert [ options ]

Options:
...snipped...

Try using TMPDIR instead:

function url2pdf {
    HTML=$TMPDIR`basename $1`'.html'
    PDF=`basename $1`'.pdf'
    wget -O $HTML $1
    /System/Library/Printers/Libraries/convert -f $HTML -o $PDF
    rm -f $HTML
    open -a Preview $PDF
}

That's crude, but it works. You can tweak to suit your tastes for saving the PDF on disk or not.

share|improve this answer
    
Good enough for me!! thanks!! –  osxgai Oct 11 '10 at 17:05
1  
Hooray for process substitution. /System/.../convert -f <(wget ...) -o >(open -a Preview) –  Ignacio Vazquez-Abrams Oct 11 '10 at 17:08
    
@Ignacio: Nice. New trick learned. Didn't know you could bracket like that to sub a process for a file name. Difference between your output and mine is mine produces a rendered view of the page, yours is a PDF version of the HTML source. I wonder what rendered the page in my version? Preview? –  Ian C. Oct 11 '10 at 17:12
    
convert probably can't tell what it is since there's no extension to parse. –  Ignacio Vazquez-Abrams Oct 11 '10 at 17:13
    
@Ignacio: with your sol'n quitting Preview doesn't get you back the prompt. It stays held by convert with the message: Cannot write to `-' (Broken pipe). –  Ian C. Oct 11 '10 at 17:13
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.