DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • How To Convert Common Documents to PNG Image Arrays in Java
  • How to Convert a PDF to Text (TXT) Using Java
  • How to Convert a File to PDF in Mendix
  • How to Convert a PDF to PNG or JPG in Java

Trending

  • How Developers Are Driving Supply Chain Innovation With Modern Tech
  • Building an AI Nutrition Coach With OpenAI, Gradio, and gTTS
  • 10 Predictions Shaping the Future of Web Data Extraction Services
  • Build Real-Time Analytics Applications With AWS Kinesis and Amazon Redshift

Convert Markdown to PDF, DOCX, or Anything Else With Pandoc

Markdown is a simple and quick way to format text, but isn't as portable or well-known as PDF or MS Doc(x); Pandoc can seamlessly convert among dozens of formats on many platforms.

By 
Michael Scharhag user avatar
Michael Scharhag
·
Mar. 07, 16 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
12.4K Views

Join the DZone community and get the full member experience.

Join For Free

markdown is a popular text formatting syntax among developers these days. popular sites like github and bitbucket use markdown for project documentation and various other types of user-generated content. these sites interpret markdown into html, so it can be displayed in a browser.

however, maybe you want to use markdown as a document format without using a platform that does the conversion for you. or you are in need of an output format other than html. in this case, you need a tool that can convert markdown to the desired target format. pandoc is is a document conversion tool that can be used for exactly this (and a lot of other things). with pandoc you can convert markdown documents to pdf, html, words docx or many other formats.

after installing pandoc, you can simply run it from the command line.

note: by default, pandoc uses latex to generate pdf documents. so, if you want to generate pdf documents, you need to install a latex processor first ( list of required latex packages ).

to convert a doc.md markdown file into a pdf document, the following command can be used:


pandoc -s -o doc.pdf doc.md

pandoc is able to merge multiple markdown files into a single pdf document. to generate a single pdf document out of two markdown files you can use:


pandoc -s -o doc.pdf part01.md part02.md

by default, the page margins in the resulting pdf document are quite large. you can change this by passing a margin parameter:


pandoc -s -v geometry:margin=1in -o documentation.pdf part01.md part02.md

to create html or docx documents you simply have to change the file extension of the target file:


pandoc -s -o doc.html part01.md part02.md
pandoc -s -o doc.docx part01.md part02.md

the resulting documents are well formatted. the following two screenshot show a docx and a pdf document created out of two small example markdown files:

resulting docx document:

word docx document generated by pandoc

resulting pdf document:

pdf document generated by pandoc


PDF Convert (command) Document

Published at DZone with permission of Michael Scharhag, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Convert Common Documents to PNG Image Arrays in Java
  • How to Convert a PDF to Text (TXT) Using Java
  • How to Convert a File to PDF in Mendix
  • How to Convert a PDF to PNG or JPG in Java

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: