I invested a bit more time (plus a couple of suggestions of members of this list and stackoverflow.) I was able to create a module that prints the current source block to PDF
without using the exporter. It now uses the pdf viewer to open it.
It might be useful to some people who simply need to create a PDF from a source block and have it open in the corresponding PDF application:
I look at your suggestions, which pointed me in the direction I needed.
At the end I realized what I wanted was simply to export the current
block to PDF without using the latex exporter. So I simply make the
selection and print that selection to ps, then convert to pdf, and open
using org-open
----------------------------------------------------------------------
(defcustom dmg-org-src-export-pdf-font-size 12
"Size of font to use "
:type 'number
:version 25
:group 'dmg-org-src-export-pdf)
(defcustom dmg-org-src-export-pdf-file-name "/tmp/source.code"
"Name of the file to export as postscript "
:type 'string
:version 25
:group 'dmg-org-src-export-pdf)
(defun dmg-org-src-export-pdf ()
"show the source code in xournal as a PDF"
(interactive)
(save-restriction
(save-excursion
(unless (executable-find "ps2pdf")
(error "ps2pdf not found"))
(let ((element (org-element-at-point))
)
(unless (eq (org-element-type element) 'src-block)
(error "Not in org-src-block"))
)
(let* (
(output-file
(or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info 'light))))
dmg-org-src-export-pdf-file-name))
(ps-file (concat output-file ".ps"))
(pdf-file (concat output-file ".pdf"))
;; this uses dynamic scoping to set the parameters of ps temporarily
(ps-font-size dmg-org-src-export-pdf-font-size)
)
(message "Exporting: %s" ps-file)
(org-babel-mark-block)
(narrow-to-region (region-beginning) (region-end))
(ps-print-buffer-with-faces ps-file)
(shell-command (concat "ps2pdf " ps-file " " pdf-file))
(delete-file ps-file)
(org-open-file pdf-file)
)
)))