12
votes

I am trying to use markdown with pandoc to convert a single document into html, pdf, and docx. It's an extremely simple document containing only math-less text and a few images. The images are in PNG format. I include an image using this in markdown source:

<div style="float:center" markdown="1">

![my caption](./figures/myimage.png)

</div>

and compile it as:

# html
pandoc myarticle.md -c mystyle.css -o myarticle.html
# pdf
pandoc myarticle.md -V geometry:margin=1in -o myarticle.pdf
# docx
pandoc myarticle.md -o myarticle.docx

I noticed that some PNG images that have the same dimensions get sized differently in HTML and PDF formats. A PNG that is 250x256 px with low resolution (72 px/in) will appear in PDF as the correct size roughly on page, and appear in a reasonable size in html, but a PNG that has the same dimensions (250x256 px) but is high-res (300 px/in) get resized to be tiny on the page in the PDF output. I want to keep on set of PNG images in a size that I specify and have them appear in that size in both the HTML/PDF/DOCX formats.

I am willing to give up automatic docx support (or deal with a lot of manual formatting after) just to have PDF/HTML.

How can I tell pandoc not to resize PNGs for PDF or image, and have them appear in their correct images? thanks.

2
Why not change the metadata in the PNG to 72px/in? e.g. convert -density 72 -units pixelsperinch file.png file.pngmb21

2 Answers

22
votes

This is now included in Pandoc 1.16

You can use the new link_attributes feature e.g.

An inline ![image](foo.jpg){#id .class width=30 height=20px}

See: http://pandoc.org/README.html#images

1
votes

This is not currently possible, however there are several pull requests to add this support in Pandoc.