From: Francesco Pizzolante <fpz-djc/iPCCuDYQheJpep6IedvLeJWuRmrY@public.gmane.org>
To: Eric Schulte <schulte.eric-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: mailing-list-org-mode <emacs-orgmode-mXXj517/zsQ@public.gmane.org>
Subject: Blorgit > Adding PDF export
Date: Mon, 23 Nov 2009 13:58:54 +0100 [thread overview]
Message-ID: <873a451jox.fsf_-_@missioncriticalit.com> (raw)
In-Reply-To: <m2skcazgr6.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> (Eric Schulte's message of "Thu, 19 Nov 2009 08:17:01 -0700")
Eric,
> Also, rather than using a shell script, would it be possible to use the
> built in `org-export-as-pdf' function. This may obviate the need for a
> shell script at all. In this case you probably wouldn't need to remove
> the leading "." in the file names, and if you did, it could be done in
> elisp right around export with the `rename-file' function.
Regarding the addition of an extra link in order to get the PDF export, I took
your remarks into account and here's what I finally went to.
First, add the ".pdf" link to the page:
--8<---------------cut here---------------start------------->8---
diff --git a/blorgit.rb b/blorgit.rb
index 077b5d9..93bea47 100644
--- a/blorgit.rb
+++ b/blorgit.rb
@@ -197,6 +197,8 @@ __END__
%a{ :href => path_for(@blog, :format => 'org'), :title => 'download as org-mode' } .org
%li
%a{ :href => path_for(@blog, :format => 'tex'), :title => 'download as LaTeX' } .tex
+ %li
+ %a{ :href => path_for(@blog, :format => 'pdf'), :title => 'download as PDF' } .pdf
#title_separator
@@ sidebar
--8<---------------cut here---------------end--------------->8---
In "acts_as_org.rb", call a "org-file-to-pdf" emacs function:
--8<---------------cut here---------------start------------->8---
diff --git a/lib/acts_as_org.rb b/lib/acts_as_org.rb
index 458741d..8e027fc 100644
--- a/lib/acts_as_org.rb
+++ b/lib/acts_as_org.rb
@@ -80,6 +80,24 @@ PREAMBLE
l_path = self.latex_path(path)
File.exist?(l_path) and File.mtime(l_path) > File.mtime(path)
end
+
+ def pdf_path(path)
+ File.join(File.dirname(path),
+ ActiveFile::Acts::Org::EXP_PREFIX + File.basename(path) + ".pdf")
+ end
+
+ def to_pdf(path, options = {})
+ p_path = self.pdf_path(path)
+ options = {:postamble => false}.merge(options)
+ self.emacs_run("(org-file-to-pdf \"#{path}\")") unless self.clean_pdf?(path)
+ return nil unless File.exist?(p_path)
+ html = File.read(p_path)
+ end
+
+ def clean_pdf?(path)
+ p_path = self.pdf_path(path)
+ File.exist?(p_path) and File.mtime(p_path) > File.mtime(path)
+ end
end
module InstanceMethods
@@ -107,6 +125,19 @@ PREAMBLE
self.class.to_latex(self.full_path, options)
end
alias :to_tex :to_latex
+
+ def pdf_path
+ self.class.pdf_path(self.full_path)
+ end
+
+ def clean_pdf?
+ self.class.clean_pdf?(self.full_path)
+ end
+
+ def to_pdf(options = {})
+ self.class.to_pdf(self.full_path, options)
+ end
+
end
end
end
--8<---------------cut here---------------end--------------->8---
In "org-interaction.el", added the "org-file-to-pdf" function:
--8<---------------cut here---------------start------------->8---
diff --git a/elisp/org-interaction.el b/elisp/org-interaction.el
index 2311156..9b0d695 100644
--- a/elisp/org-interaction.el
+++ b/elisp/org-interaction.el
@@ -24,6 +24,7 @@ evaluating BODY."
,temp-result)))
(defvar org-interaction-prefix ".exported_")
+(defvar tmp-prefix "exported_")
(defun org-file-to-html (file-path)
"Open up an org file, publish it to html, and then return the
@@ -65,6 +66,31 @@ latex as a string."
(write-file latex-path)
(kill-buffer (current-buffer)))))))
+(defun org-file-to-pdf (file-path)
+ "Open up an org file and export it as pdf."
+ (let* ((file-name (file-name-nondirectory file-path))
+ (file-dir (file-name-directory file-path))
+ (org-tmp-path (expand-file-name (concat tmp-prefix file-name ".org") "/tmp/"))
+ (pdf-tmp-path (expand-file-name (concat tmp-prefix file-name ".pdf") "/tmp/"))
+ (tex-tmp-path (expand-file-name (concat tmp-prefix file-name ".tex") "/tmp/"))
+ (pdf-path (expand-file-name (concat org-interaction-prefix file-name ".pdf") file-dir)))
+ (if (and (file-exists-p pdf-path)
+ (< 0 (time-to-seconds
+ (time-subtract
+ (nth 5 (file-attributes pdf-path))
+ (nth 5 (file-attributes file-path))))))
+ pdf-path
+ (with-temp-filebuffer
+ file-path
+ (write-file org-tmp-path)
+ (org-mode)
+ (save-window-excursion
+ (org-export-as-pdf nil)
+ (rename-file pdf-tmp-path pdf-path)
+ (delete-file org-tmp-path)
+ (delete-file tex-tmp-path)
+ (kill-buffer (current-buffer)))))))
+
;; customization
(setq org-export-blocks-witheld '(hidden comment))
--8<---------------cut here---------------end--------------->8---
Note that I use the /tmp folder to store temporary files without the leading
dot (the export do PDF does not work with a leading dot).
What do you think?
Thanks for your feedback.
Regards,
Francesco
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
next prev parent reply other threads:[~2009-11-23 12:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-13 15:47 Blorgit > SVN integration Francesco Pizzolante
2009-11-13 17:45 ` Eric Schulte
[not found] ` <m2r5s2gvyc.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-11-19 10:06 ` Francesco Pizzolante
2009-11-19 15:17 ` Eric Schulte
[not found] ` <m2skcazgr6.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-11-20 12:36 ` Francesco Pizzolante
2009-11-20 17:15 ` Eric Schulte
2009-11-23 12:58 ` Francesco Pizzolante [this message]
2009-11-23 14:43 ` Blorgit > Adding PDF export Eric Schulte
[not found] ` <m2ljhxi9oi.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-11-23 15:23 ` Francesco Pizzolante
2009-11-23 15:38 ` Eric Schulte
2009-12-03 15:59 ` Blorgit > SVN integration Francesco Pizzolante
2009-12-05 3:54 ` Eric Schulte
[not found] ` <m27ht23wj2.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-12-07 12:33 ` Francesco Pizzolante
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=873a451jox.fsf_-_@missioncriticalit.com \
--to=fpz-djc/ipccudyqhejpep6iedvlejwurmry@public.gmane.org \
--cc=emacs-orgmode-mXXj517/zsQ@public.gmane.org \
--cc=schulte.eric-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.