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

后端 未结 1 700
情书的邮戳
情书的邮戳 2021-01-28 17:29

The existing code written by Rupert Swarbrick, later modified by Rory Yorke, still leaves open the need to specify the file location with a save-as function (e.g. on OSX, this w

相关标签:
1条回答
  • 2021-01-28 18:16

    You can modify the last function to take a filename 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 some code that tests if the PDF file already exist though, to avoid overwriting anything.

    0 讨论(0)
提交回复
热议问题