Save buffer as * .pdf using `ns-write-file-using-panel` or a similar option

Existing code written by Rupert Swarbrick, later modified by Rory Yorke, still leaves open the indication to specify the file location using the save-as function (for example, in OSX it will be ns-write-file-using-panel ). Does anyone have a suggestion, please add a parameter similar to ns-write-file-using-panel and / or maybe change the directory parameter / tmp written in the script?

Transfer Word for Emacs Print Buffer to PDF

Formatting a header in an Emacs function to print a buffer in line feed PDF format

 (defun harden-newlines () (interactive) "Make all the newlines in the buffer hard." (save-excursion (goto-char (point-min)) (while (search-forward "\n" nil t) (backward-char) (put-text-property (point) (1+ (point)) 'hard t) (forward-char)))) ;; (defun spool-buffer-given-name (name) ;; (load "ps-print") ;; (let ((tmp ps-left-header)) ;; (unwind-protect ;; (progn ;; (setq ps-left-header ;; (list (lambda () name) 'ps-header-dirpart)) ;; (ps-spool-buffer-with-faces)) ;; (setf ps-left-header tmp)))) (defun spool-buffer-given-name (name) (let ((ps-left-header (list (format "(%s)" name)))) (ps-spool-buffer-with-faces))) (defun print-to-pdf () "Print the current file to /tmp/print.pdf" (interactive) (let ((wbuf (generate-new-buffer "*Wrapped*")) (sbuf (current-buffer))) (jit-lock-fontify-now) (save-current-buffer (set-buffer wbuf) (insert-buffer sbuf) ;; (longlines-mode t) (visual-line-mode t) (harden-newlines) (spool-buffer-given-name (buffer-name sbuf)) (kill-buffer wbuf) (switch-to-buffer "*PostScript*") (write-file "/tmp/print.ps") (kill-buffer (current-buffer))) (call-process "ps2pdf14" nil nil nil "/tmp/print.ps" "/tmp/print.pdf") (delete-file "/tmp/print.ps") (message "PDF saved to /tmp/print.pdf"))) 
0
source share
1 answer

You can change the last function to take the file name as a parameter:

 (defun print-to-pdf (pdf-file-name) "Print the current file to the given file." (interactive "FWrite PDF file: ") (let ((ps-file-name (concat (file-name-sans-extension pdf-file-name) ".ps")) (wbuf (generate-new-buffer "*Wrapped*")) (sbuf (current-buffer))) (jit-lock-fontify-now) (save-current-buffer (set-buffer wbuf) (insert-buffer sbuf) (setq fill-column 95) (longlines-mode t) (harden-newlines) (message (buffer-name sbuf)) (spool-buffer-given-name (buffer-name sbuf)) (kill-buffer wbuf) (switch-to-buffer "*PostScript*") (write-file ps-file-name t) (kill-buffer (current-buffer))) (call-process "ps2pdf14" nil nil nil ps-file-name pdf-file-name) (delete-file ps-file-name) (message "PDF saved to %s" pdf-file-name))) 

You might want to add code that checks if a PDF file exists to avoid overwriting.

+2
source

All Articles