I want to save an email receipt as a PDF. I type a and v (for Action and View as PDF) and get Wrong type argument: stringp, nil. How can I save a message as a PDF file?

  • 1
    You might need to put msg2pdf working in order to achieve that. Alternatively, you can open the message in your web browser and save it from there as a pdf file.
    – Ajned
    Jun 23 '19 at 13:18
  • When I launch help for mu4e-msg2pdf, I get: is a variable defined in ‘mu4e-actions.el’. Its value is nil. I installed mu with brew install mu --with-emacs and running brew upgrade --with-emacs mu gives Error: invalid option: --with-emacs. How do I reinstall mu with mu4e or msg2pdf? Or how do I get the file location of the current message on disk? Jun 24 '19 at 17:09
  • As you can see from this reddit post msg2pdf is not the easiest/most reliable way of getting a pdf. I'd use the web browser shortcut instead.
    – Ajned
    Jun 26 '19 at 13:53
  • 1
    I found how to view a message in the browser here, adding to my configuration (add-to-list 'mu4e-view-actions '("ViewInBrowser" . mu4e-action-view-in-browser) t). Do you want to write an answer? Jun 26 '19 at 14:21

With wkhtmltopdf installed, here's a function that saves the PDF to your Desktop automatically:

(defun mu4e-action-save-to-pdf (msg)
  (let* ((date (mu4e-message-field msg :date))
         (infile (mu4e~write-body-to-html msg))
         (outfile (format-time-string "%Y-%m-%d%H%M%S.pdf" date)))
       (format "wkhtmltopdf %s ~/Desktop/%s" infile outfile) t))))

(add-to-list 'mu4e-view-actions '("Save to PDF" . mu4e-action-save-to-pdf) t)
  • @mmorin I replaced the call-process-shell-command function with shell-command. Can you try again. You could also replace it with print to examine the output.
    – jagrg
    Jul 1 '19 at 12:25
  • I asked this follow-up question about including message headers in the PDF. Feb 25 '20 at 12:11
  • I see the From, To, Date, and Subject header fields in the PDF. I'm not sure what the issue is.
    – jagrg
    Feb 27 '20 at 2:00
  • I included a picture of the PDF output from your code in that other thread. I have mu4e-mu-version 1.2.0, how about you? The function mu4e~write-body-to-html does not mention if headers are included. Does the body of a mu4e message include the headers? Feb 27 '20 at 11:58
  • 1
    Try the mu4e~write-body-to-html function in the master branch and see if that works for you. I'm using mu version 1.3.4 C.
    – jagrg
    Feb 27 '20 at 12:38

To get the same result, but with an additional step, I suggest to view the email in your web browser with (add-to-list 'mu4e-view-actions '("ViewInBrowser" . mu4e-action-view-in-browser) t) and to then print it to a pdf file.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.