Created
July 28, 2011 01:09
-
-
Save condotti/1110718 to your computer and use it in GitHub Desktop.
orgからpdfにexport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defcustom my-htmltopdf-program | |
"wkhtml2pdf" | |
"Program to convert html into pdf." | |
:type 'string | |
:group 'my) | |
(defcustom my-htmltopdf-args | |
"" | |
"command arguments for my-htmltopdf-program" | |
:type 'string | |
:group 'my) | |
(defun my-org-export-as-pdf () | |
(interactive) | |
(save-excursion | |
(when (eq major-mode 'org-mode) | |
(let ((file (concat (make-temp-name temporary-file-directory) ".pdf")) | |
(html-file (concat (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) ".html")) | |
(pdf-file (concat (file-name-sans-extension (buffer-file-name)) ".pdf"))) | |
(org-export-as-html nil) | |
(with-current-buffer html-file | |
(save-restriction | |
(goto-char (point-min)) | |
(narrow-to-region (re-search-forward "<html.*>") | |
(progn | |
(search-forward "</html") | |
(end-of-line 0) | |
(point))) | |
(replace-regexp "$" "<!--" nil (point-min) (point-max))) | |
(save-restriction | |
(goto-char (point-min)) | |
(narrow-to-region (progn | |
(re-search-forward "<html.*>") | |
(forward-line) | |
(point)) | |
(re-search-forward "</html>")) | |
(replace-regexp "^\\( *\\)" "\\1-->" nil (point-min) (point-max))) | |
(save-buffer) | |
(shell-command (concat my-htmltopdf-program " " my-htmltopdf-args " " | |
(encode-coding-string (file-name-sans-extension (buffer-file-name)) 'shift_jis) ".html " | |
file)) | |
(rename-file file pdf-file t) | |
(shell-command pdf-file)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment