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. – Andre 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? – miguelmorin 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. – Andre 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? – miguelmorin 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. – miguelmorin 13 hours ago

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.