Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6551575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:21:16+00:00 2026-05-25T12:21:16+00:00

I use this function for printing a buffer’s content to PDF (from my .emacs

  • 0

I use this function for printing a buffer’s content to PDF

(from my .emacs file:)

(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"))  
  )

I cannot, however, find a way to enable or apply the visual-line minor mode to the PostScript buffer before it gets written to disk so to enable word wrap in the output.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:21:17+00:00Added an answer on May 25, 2026 at 12:21 pm

    The problem with getting visual line mode to be respected is that it inserts “soft newlines” (which get ignored by the PS renderer). A solution is to replace these with hard newlines. The code below does what you want, I think. Note that we call harden-newlines in a temporary buffer so as not to mess up the current document. Also, I’ve changed the output destination to always land in /tmp/print.pdf. It seems… unwise to overwrite documents in your /home without any sort of warning! You can always move the PDF afterwards.

    Anyway, here you go. Is this what you wanted?

    (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")))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use this function from a COM API which enables the
I currently use this function to wrap executing commands and logging their execution, and
I want to use this function EnumWindows(EnumWindowsProc, NULL);. The EnumWindowsProc is a Callback function:
I want to use this function: http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html Its used to post to Wordpress using
I use this script to equalize heights of elements: (function ($) { $.fn.autoheight =
I use this pseudo-class to make Ajax request to server: function RequestManager(url, params, success,
I generally use this in jquery $(document).ready(function() { //stuff } I was just on
I use the following jquery statements but i get error in this function onGetDataSuccess(result)
I used to use this script for jquery email obfuscation: $(.replaceAt).replaceWith(@); $(.obfuscate).each(function () {
I came across the function InterlockedExchange and was wondering when I should use this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.