3

Using pandoc like:

pandoc -o output.pdf input.md 

does not give me a result with word-wrapping.

For instance, three liner input.md looks like the following:

# Introduction

Lorem ipsum dolor sit amet, scelerisque natoque, in etiam erat nibh lacus, porta quam penatibus, at metus, purus leo est. Sed faucibus odio in amet, in sapien ut sapien eu, vehicula pede vel pellentesque, ut hac lacinia mauris ridiculus rhoncus ligula. Sit congue, ac montes, lorem ligula etiam ac fusce ipsum, lacus dolor in suscipit aliquet vitae. Blandit neque aliquam, amet vel, ante nullam neque. Adipiscing nullam, neque elit, nunc non mauris libero vivamus tortor.

running the above command yields a pdf document with some content as the following:

Introduction
    Lorem ipsum dolor sit amet, scelerisque natoque, in etiam erat nibh lacus,

Is there a fast way of converting a markdown(.md) file to pdf with word-wrapping (similar to the way done in here)?

Pablo Bianchi
  • 15,657
  • Can you provide an example? – Salem Aug 21 '13 at 19:20
  • 1
    I'm really not sure what you are talking about: pandoc-generated PDFs have word wrapping for me (actually, the files are converted to LaTeX and then sent to a LaTeX engine for PDF), and your example looks like it's word wrapped... – evilsoup Aug 21 '13 at 23:11
  • @evilsoup Thanks for your comment. Could you share the method you used to generate wordwrapped documents? My problem is that; calling pandoc as above gives me a truncated result. Namely, instead of wrapping the sentence, I get a cut sentence. I hope it's a bit more clear this time :-). – pacodelumberg Aug 22 '13 at 08:32
  • 1
    Oh, I understand now... using exactly the same command as you do works perfectly well for me (on pandoc version 1.10.1, from the Ubuntu 13.04 repos). Here is a file that works for me -- run your command over it & then we can determine whether the problem is with your input files (were they written on Windows, maybe?) or pandoc/your LaTeX engine. – evilsoup Aug 22 '13 at 09:09
  • Maybe you can use templating in pandoc – cosmoscalibur Jan 03 '16 at 04:43

2 Answers2

4

Markdown to PDF

With Pandoc

On my Ubuntu 20.04:

pandoc Manual.md --latex-engine=xelatex -o Manual.pdf

If you get the error

pandoc: xelatex not found. xelatex is needed for pdf output.

install the huge (~600 MB) package

sudo apt install texlive-xetex

Markdown to HTML from/to clipboard

You can also:

thisOutputMarkdown | pandoc -s -f markdown -t html | xclip -selection clipboard -t text/html

to get formatted HTML to clipboard. If you have the Markdown text on clipboard replace thisOutputMarkdown with xsel -b.

With markdown-pdf NodeJS package

npm install -g markdown-pdf
markdown-pdf /path/to/markdown
Pablo Bianchi
  • 15,657
0

I just convert from HTML instead. This works for my needs:

https://github.com/dompdf/dompdf

I found that in general Markdown is not a good format to convert to PDF, as it doesnt have native CSS support. Here is the script I use:

<?php
require 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->getOptions()->setIsFontSubsettingEnabled(true);
$s_in = file_get_contents('index.html');
$dompdf->loadHtml($s_in);

$dompdf->render();
$s_out = $dompdf->output();
file_put_contents('index.pdf', $s_out);

This solution just needs PHP (25 MB) and DomPdf (4 MB), so quite lightweight compared to other options.

Zombo
  • 1