Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library.If you need to convert files from one markup format into another, pandoc is your swiss-army knife
In this article, we will show you how to install and use pandoc in Fedora/Centos.
Install pandoc
pandoc package is avaliable in the standard Fedora/CentOS software repository. To install it run the following command:
sudo dnf install pandoc
Once you have it installed, you can verify it by typing with a simple version check command:
pandoc --version
The output should look something like this:
pandoc 1.9.4.1
Compiled with citeproc-hs 0.3.4, texmath 0.6.0.6, highlighting-kate 0.5.1.
......
That’s it! pandoc has been installed on you Fedora/CentOS system, and you can start using it .
Using pandoc
Before going into how to use the pandoc command,let’s start by reviewing the basic syntax.
pandoc [options] [input-file]…
Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.
If no input-files are specified, input is read from stdin. Output goes to stdout by default. For output to a file, use the -o
option:
pandoc -o output.html input.txt
By default, pandoc produces a document fragment. To produce a standalone document (e.g. a valid HTML file including <head>
and <body>
), use the -s
or --standalone
flag:
pandoc -s -o output.html input.txt
Instead of an input file, an absolute URI may be given. In this case pandoc will fetch the content using HTTP:
pandoc -f html -t markdown https://www.fsf.org
It is possible to supply a custom User-Agent string or other header when requesting a document from a URL:
pandoc -f html -t markdown --request-header User-Agent:"Mozilla/5.0" \
https://www.fsf.org
Here’s a example to convert from a .docx
file to .odt
:
pandoc test.docx -o test.odt
To produce a PDF, specify an output file with a .pdf
extension:
pandoc test.docx -o test.pdf
To convert test.html
from HTML to Markdown:
pandoc -f html -t markdown test.html
To convert test.txt
from Markdown to LaTeX
pandoc -f markdown -t latex test.txt
Conclusion
Pandoc is a powerhouse for anyone who needs to convert document formats.
By now you should have a good understanding of how to install and use the pandoc command. For more information about the pandoc
command, see the Pandoc User’s Guide .