Pandoc and html5 exporting pdf's with huge margins
Asked Answered
S

2

8

So I'm trying Pandoc for the first time. Everything seems great but when exporting via html5 (wkhtmltopdf) my pdf output is saved with huge margins on all sides.

pandoc -t html5 -s example.md -o output.pdf

output.pdf (content output highlighted in red)

What I've tried:

  • Reinstalling pdflatex
  • Reinstalling wkhtmltopdf
  • Including CSS to remove the margins

Am I missing something?

What I want: Write a markdown document using Typora -> Use Pandoc to apply TOC and page numbering -> Use html5 to export pdf with custom styling.

Saleratus answered 4/9, 2017 at 16:12 Comment(1)
if you use -t html, you don't need pdflatex. so don't bother reinstalling it. to change the styling, modify your HTML template then: see pandoc.org/MANUAL.html#templatesSheepfold
R
13

These pass through vars for wkhtmltopdf worked for me (ubuntu 18.10 pandoc 2.6) : https://pandoc.org/MANUAL.html#variables-for-wkhtmltopdf

pandoc -t html5 -V margin-top=3 -V margin-left=3 -V margin-right=3 -V margin-bottom=3 -V papersize=letter -s example.md -o output.pdf

(Oddly wkhtmltopdf required all margins be the same.)

Reactant answered 8/2, 2019 at 0:34 Comment(3)
This worked (on my Mac.) But using -V margins=0.75in, for example, didn't. I needed all four options.Geoponics
I was using a css file (with pandoc and wkhtmltopdf) and the css margins were having no effect until I set -V margin-top=0 etc for all the margins. Now I can set them all with CSS.Vitreous
@Vitreous setting margin only in CSS doesn't work for multiple pages, CSS is not aware of page breaksSpent
S
1

To answer my own question, the issue is caused by wkhtmltopdf (0.12.4) on macOS and supposedly Debian. I solved it by using only wkhtmltopdf (without Pandoc) and trying different parameters such as --zoom --dpi and --disable-smart-shrinking.

See:

wkhtmltopdf generates tiny output on Mac

https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3241

Saleratus answered 8/9, 2017 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.