0

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?

4
  • 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
    Commented Jun 23, 2019 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?
    – emonigma
    Commented Jun 24, 2019 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
    Commented Jun 26, 2019 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?
    – emonigma
    Commented Jun 26, 2019 at 14:21

2 Answers 2

2

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)))
    (with-temp-buffer
      (shell-command
       (format "wkhtmltopdf %s ~/Desktop/%s" infile outfile) t))))

(add-to-list 'mu4e-view-actions '("Save to PDF" . mu4e-action-save-to-pdf) t)
5
  • @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
    Commented Jul 1, 2019 at 12:25
  • I asked this follow-up question about including message headers in the PDF.
    – emonigma
    Commented Feb 25, 2020 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
    Commented Feb 27, 2020 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?
    – emonigma
    Commented Feb 27, 2020 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
    Commented Feb 27, 2020 at 12:38
1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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