This tip is about the how to Convert Files on Linux Command Line using Pandoc. So read this free guide, How to Convert Files on Linux Command Line using Pandoc step by step. If you have query related to same article you may contact us.
How to Convert Files on Linux Command Line using Pandoc – Guide
Pandoc can convert .docx files to .pdf and .html, but you might be thinking, “Word can also export files to .pdf and .html. What do I need Pandoc for?” You would have a good argument, but since Pandoc can convert so many formats, it can become your tool for all your conversion tasks. For example, many of us know that Markdown editors can export their Markdown files to .html. Pandoc can also be used to convert Markdown files to many other formats.
How to Use pandoc to convert files on Linux command line
Let’s install Pandoc on your Linux based operating system. In our case, we will use Ubuntu as the operating system.
Command to install Pandoc on various Linux-based operating systems,
Ubuntu: sudo apt-get install pandoc
Fedora: sudo dnf install pandoc
Manjaro: sudo pacman -Syu pandoc
After successful installation, you can check the Pandoc version using below command,
Command: pandoc –version
Use Pandoc without any files
You can use Pandoc to write text-based documents.
You can tell Pandoc that you are done writing by pressing Ctrl+D.
The only format Pandoc understands is Markdown. It would be better if you learned the Markdown format before starting to use Pandoc. In this tutorial we will guide you through the basic concepts of the Markdown language.
The output is usually in HTML format to Markdown format.
Open the terminal and type “pandoc” to open the pandoc command line recorder.
Enter some entries in Markdown format as mentioned below,
Press CTRL+D to generate the output in HTML format as mentioned below,
Basics of Markdown
Note: Markdown files extension: .md
H3 header -> ### Blockquoted header ->
Under the paragraph tag -> This is the blockquote text. ->
This is block citation text.
Emphasis format: Italic -> *italic* or _italic_ -> Italic
Strong format: **bold** or __bold__ -> bold
Horizontal rule: 3 or more hyphens, asterisks or underscores on a single line. Example: * * * or *** or ***** ->
Line return: Forcing a line breakss -> Forcing a line break
Links: a link (http://example.com/) -> A link here
Lists: Unordered list -> more, hyphens or asterisks as list bullets
+ One– Two* Three Output:
Create a Markdown file
Before starting, create and populate a Markdown file first using the steps below in an Ubuntu environment,
Create a markdown file with .md extension using below command in a terminal using vi editor,
Command: vi sample.md
The vi editor will open the file in a terminal based text editor and fill it with some markup as mentioned below,
Save the file using the command “:wq” followed by Enter.
Let’s convert the Markdown formatted file to HTML format using the command below, Command: pandoc -o sample.html sample.md
After the conversion is complete, you will be able to see a new file in the folder called “sample.html”.
You can double-click this file to check the Markdown contents in a browser.
If you don’t have a browser, you can use Lynx using this command,
sudo apt install lynx -> lynx sample.html
Specifying file formats
Pandoc allows you to specify the required file formats during conversion. Although not mandatory, sometimes you need to specify the format when both file formats use the same extension, such as “TeX” and “LaTeX” both use the “.tex” extension. Command: pandoc -f markdown -t latex -s -o sample.tex sample.mdDecode the syntax:
-f: from the extension
-t: for extension
-s: standalone option to generate all the Latex preamble needed to complete the document.
Pandoc makes use of the LatTeX pdf engine to generate pdfs. It is recommended to install a LatTeX editor to satisfy all dependencies correctly. The easy-to-use editor is “Texmaker.” Command to install Pandoc on various Linux based operating systems, Ubuntu: sudo apt-get install texmakerFedora: sudo dnf install texmakerManjaro: sudo pacman -Syu texmaker
Generate Office document file (in odt) from Markdown file using below command, Command: pandoc -o sample.odt –reference-doc=odt-template.odt sample.md
Open the document in LibreOffice writer and save it as a pdf.
I hope you like the guide How to Convert Files on Linux Command Line using Pandoc. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.