I was recently managing a set of interviews and I had my notes on all of the candidates in a single org file, with each candidate under their own top-level headline:
* J Kepler
- Nice work on orbits
* I Newton
- Versatile
- Hard to work with
* C Sagan
- Good communication skills
However, I wanted to generate a separate pdf file for each candidate that I could circulate to interviewers (since each interviewer was only interviewing a subset of applicants).
I came across this stackexchange answer that demonstrated how to build a function to export top level headlines to separate files. There are a few variations on that page, and I put together the slightly tweaked version below. All of the credit goes to stackexchange user itsjeyd
for a very detailed answer. In my version I hard code it to export to pdf, save the file first, and apply the export options from the parent file to each of the new files that are created. The new files have a name taken from the headline, with spaces replaced by underscores, unless the :EXPORT_FILE_NAME:
property is set for a headline.
;; export headlines to separate files
;; http://emacs.stackexchange.com/questions/2259/how-to-export-top-level-headings-of-org-mode-buffer-to-separate-files
(defun org-export-headlines-to-pdf ()
"Export all subtrees that are *not* tagged with :noexport: to
separate files.
Subtrees that do not have the :EXPORT_FILE_NAME: property set
are exported to a filename derived from the headline text."
(interactive)
(save-buffer)
(let ((modifiedp (buffer-modified-p)))
(save-excursion
(goto-char (point-min))
(goto-char (re-search-forward "^*"))
(set-mark (line-beginning-position))
(goto-char (point-max))
(org-map-entries
(lambda ()
(let ((export-file (org-entry-get (point) "EXPORT_FILE_NAME")))
(unless export-file
(org-set-property
"EXPORT_FILE_NAME"
(replace-regexp-in-string " " "_" (nth 4 (org-heading-components)))))
(deactivate-mark)
(org-latex-export-to-pdf nil t)
(unless export-file (org-delete-property "EXPORT_FILE_NAME"))
(set-buffer-modified-p modifiedp)))
"-noexport" 'region-start-level))))