我使用此功能将缓冲区的内容打印为 PDF
(来自我的 .emacs 文件:)
(defun print-to-pdf ()
(interactive)
(ps-spool-buffer-with-faces)
(switch-to-buffer "*PostScript*")
(write-file "/tmp/tmp.ps")
(kill-buffer "tmp.ps")
(setq cmd (concat "ps2pdf14 /tmp/tmp.ps /home/user/" (buffer-name) ".pdf"))
(shell-command cmd)
(shell-command "rm /tmp/tmp.ps")
(message (concat "Saved to: /home/user/" (buffer-name) ".pdf"))
)
但是,我无法找到一种方法在 PostScript 缓冲区被写入磁盘之前启用或应用可视线次要模式,以便在输出中启用自动换行。
最佳答案
获得视觉线模式的问题在于它插入了“软换行符”(被 PS 渲染器忽略)。一个解决方案是用硬换行符替换这些。我认为下面的代码可以满足您的需求。请注意,我们在临时缓冲区中调用 harden-newlines 以免弄乱当前文档。此外,我已将输出目的地更改为始终位于 /tmp/print.pdf
.似乎...覆盖您的 /home
中的文档是不明智的。没有任何警告!之后您可以随时移动 PDF。
无论如何,给你。这是你想要的吗?
(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 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)
(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")))
关于emacs - Emacs 打印缓冲区的自动换行到 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7362625/