VimでPDFを開いて保存
vimでPDFが開けるようになるよ、っていうのがあったのでやってみたことのメモ。
Open PDF files | Vim Tips Wiki | FANDOM powered by Wikia
1. xpdfのインストール
2. cups-pdfのインストール
3. .vimrcに文を追加
xpdfのインストール
XpdfReader
$ sudo port install xpdf したら何故か止まってしまってうまくいかないので
したら普通に出来たメモ:
$ apt-get install xpdf
Xpdf: a viewer for Portable Document Format (PDF) files.
cups-pdfのインストール
http://www.physik.uni-wuerzburg.de/~vrbehr/cups-pdf/documentation.shtml
http://www.codepoetry.net/projects/cups-pdf-for-mosx
すると、
$ sudo sudo port install cups-pdf
************************************************************* If this is the first installation, there are a couple of items to do: - First, symlinks in /usr are needed for CUPS to see cups-pdf, so run (it will run sudo so may ask for your password): /opt/local/libexec/cups-pdf_links.sh - Edit /opt/local/etc/cups/cups-pdf.conf as needed - Finally, tell cupsd to update (it may not be running on 10.5): sudo killall -1 cupsd *************************************************************
というのが出た。とりあえず言う通りにやっておいた。
1. まず、CUPS用にシンボリックリンクが必要らしく、
すると、
$ /opt/local/libexec/cups-pdf_links.sh
で↓の結果に:
Creating symlink /usr/libexec/cups/backend/cups-pdf
Creating symlink /usr/share/cups/model/CUPS-PDF.ppd
2. /opt/local/etc/cups/cups-pdf.confを必要に応じて編集しろ、
と言われてもわからないので編集しなかった。
3. cupsdをupdateさせる
$ sudo killall -1 cupsd
cups-pdfを入れたら、メニュー>印刷でプリンターにCUPS-PDFというものを追加出来るようになった。
追加してそのCUPS-PDFプリンタで印刷すると、~/Desktop/cups-pdf/内にpdfが出力されるようだ。
2のcups-pdf.confに出力先が記述されている。
GUIでは「CUPS-PDF」と表示されていたが、lpコマンドでうまくいかない。
すると「CUPS_PDF」となっていたので、lpコマンドではこちらの名前を使うとうまくいった。
$ lpc
lpc > status
とやってみると~/Desktop/cups-pdf/にpdf化したファイルが出力された
$ lp -d CUPS_PDF pdfにしたいファイル
メモ:
- cups-pdf
- designed to produce PDF files in a heterogeneous network by providing a PDF printer on the central fileserver.
heterogeneous: 異種の
詳細:LinuxでPDFファイルを作成するには − @IT
.vimrcに書く
" ~/.vimrcに追加 autocmd BufReadPre *.pdf set ro nowrap autocmd BufReadPost *.pdf %!pdftotext "%" -nopgbrk -layout -q -eol unix - autocmd BufWritePost *.pdf !rm -rf ~/Desktop/cups-pdf/% autocmd BufWritePost *.pdf !lp -s -d CUPS_PDF "%" ""autocmd BufWritePost *.pdf !until [ -e ~/Desktop/cups-pdf/% ]; do sleep 1; done ""autocmd BufWritePost *.pdf !mv ~/Desktop/cups-pdf/% %:p:h
・開いたpdfを編集して保存しない場合は、BufReadPostの行まででいける
・rmで今開いているpdfファイルと同じ名前のものをcups-pdfの出力先フォルダから削除している
・lpでpdfを出力、CUPS_PDFはlpcで出てきたcups-pdf仮想プリンタの名前
・untilのところでエラーが出るのでコメントアウトで保留