Here's a bare-bones implementation. It uses a template file in the current directory called template.org
and substitutes name, phone, amount into placeholders in the template (%NAME%, %PHONE%, %AMOUNT% resp.) It then saves the resulting org-mode file in /tmp/munged-name.org
where the munged-name is just the name variable with spaces replaced by dashes. It then runs the org-latex-export-to-pdf
function to process the file to PDF (in /tmp/munged-name.pdf
). The function is bound to F10 z
(i.e. function key F10
followed by letter z
) although you can bind it to whatever you want - see the code for details.
The lisp code:
(defun fill-template-and-export (name phone amt)
(interactive "sName: \nsPhone: \nsAmount: ")
(with-temp-buffer
(insert-file-contents "template.org")
(save-excursion
(while (re-search-forward "%NAME%" nil t)
(replace-match name)))
(save-excursion
(while (re-search-forward "%PHONE%" nil t)
(replace-match phone)))
(while (re-search-forward "%AMOUNT%" nil t)
(replace-match amt))
(write-file (format "/tmp/%s.org" (replace-regexp-in-string " " "-" name)))
(org-latex-export-to-pdf)))
;;; define the function key F10 as a prefix key
(setq f10-keymap (make-sparse-keymap))
(define-key global-map [f10] f10-keymap)
;;; F10 z calls the function above
(define-key f10-keymap "z" 'fill-template-and-export)
The template file:
#+OPTIONS: toc:nil num:nil
#+LATEX_HEADER: \setlength{\parindent}{0pt}
* Invoice
\begin{flushright}
Name: %NAME%\\
Phone: %PHONE%\\
Amount: %AMOUNT%\\
\end{flushright}
Dear Sir/Madam:
We would appreciate your immediate attention to this invoice.
Sincerely,
\vspace{2cm}
A.U. Thor
You can of course tweak it if you don't like the design decisions I made.