This is a text-only version of the following page on https://raymii.org:
Title : Viewing PDF, .docx and .odt files in mutt (as text)
Author : Remy van Elst
Date : 03-03-2019
URL : https://raymii.org/s/articles/Viewing_PDF_docx_and_odt_files_in_Mutt.html
Format : Markdown/HTML
mutt is my email client at work. I like the simple interface, the speed and the
ability to customize the workflow. Email is synced with `offlineimap` and sent
via `msmtp`, addresses are in `abook`, and `calcurse` is the calendar for
meetings, no complicated setup there. One aspect I especially like is the
ability to view attachments on the command line right from mutt itself. Some
departments at work send emails with an attached `PDF` or `.docx` file that
contains the actual message, instead of just putting the text in the email
itself. Using `pandoc` and `pdftotext` in mutt, the text of the attachments is
displayed as a regular mail, no interruptions in my workflow by opening an
external program. This article explains how to set up your `.muttrc` and
`.mailcap` to use `pandoc` and `pdftotext` to view attachments as text in mutt.
I do assume you have a working mutt set up as I don't cover that here. [The Arch
Linux Wiki] on mutt is a great place to start if you haven't got mutt setup
Consider sponsoring me on Github. It means the world to me if you show you
r appreciation and you'll help pay the server costs.
ou can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days.
### Installing software
On Ubuntu both packages required are in the repository and can be installed
apt-get install pandoc poppler-utils
`pdf2text` is in `poppler-utils`.
Your `.mailcap.` file contains information for a mail client how to handle non-
In your `.muttrc` file you need to specify where this file is:
set mailcap_path = ~/.mailcap
The man page for `.mailcap` explains the purpose and format of the file:
Each mailcap entry consists of a content-type specification, a command to
execute, and (possibly) a set of optional "flag" values. For example, a
straightforward mailcap entry (which is default behavior for metamail) would
look like this:
text/plain; cat %s
The optional flags can be used to specify additional information about the mail-
handling command. For example:
text/plain; cat %s; copiousoutput
can be used to indicate that the output of the `cat` command may be voluminous,
requiring either a scrolling window, a pager, or some other appropriate coping
#### HTML mails
I use `elinks` for example to view html mails, the following line accomplishes
text/html; elinks -dump ; copiousoutput;
Combined with the following line in my `.muttrc` to auto convert HTML mails:
auto_view text/html text/calendar application/ics
You only need `text/html`, but I also have calendar and meeting invites that I
auto view due to Exchange presenting those in some weird empty email with
Now, back to the PDF and .docx files.
#### PDF & .docx
The following command will convert a .docx file to text. The to parameter states
markdown, but the output will be plain text with markdown formatting.
pandoc --from docx --to markdown My_doc_file.docx
This works for OpenOffice as well:
pandoc --from odt --to markdown My_odt_file.odt
The following command will convert a .pdf file to text:
pdftotext -layout %s
Do note that in both cases non-text items might be lost, like images. Not a big
issue since my files are mostly plain text but do keep it in mind. Tables work
quite well, which surprised me. You still can save the attachments and view them
with another program (like LibreOffice).
Putting two and two together results in the following three lines in your
application/vnd.openxmlformats-officedocument.wordprocessingml.document; pandoc --from docx --to markdown %s; copiousoutput
application/vnd.oasis.opendocument.text; pandoc --from odt --to markdown %s; copiousoutput
application/pdf; pdftotext -layout %s -; copiousoutput;
Restart mutt and open an email with an attachment you want to view. Instead of
using `s` to save the file you can now use `v` to view the file. Either
`pdftotext` or `pandoc` is invoked, and the plain text output is shown inside
> A PDF file viewed in mutt, as text
All the text on this website is free as in freedom unless stated otherwise.
This means you can use it in any way you want, you can copy it, change it
the way you like and republish it, as long as you release the (modified)
content under the same license to give others the same freedoms you've got
and place my name and a link to this site with the article as source.
This site uses Google Analytics for statistics and Google Adwords for
advertisements. You are tracked and Google knows everything about you.
Use an adblocker like ublock-origin if you don't want it.
All the code on this website is licensed under the GNU GPL v3 license
unless already licensed under a license which does not allows this form
of licensing or if another license is stated on that page / in that software:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
Just to be clear, the information on this website is for ment for educational
purposes and you use it at your own risk. I do not take responsibility if you
screw something up. Use common sense, do not rm -rf / as root for example.
If you have any questions then do not hesitate to contact me.
See https://raymii.org/s/static/About.html for details.