Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use pandoc to embed images into a docx file that are in a HTML

Tags:

pandoc

Is it possible to embed images into a docx file that are embedded in a HTML file?

I am trying and it's not working for me, and perhaps I am not adding some extra parameter when I am running pandoc.

pandoc -f html -t docx -o testdoc.docx image.html

Thank you very much!

like image 663
César Rodríguez Avatar asked Feb 03 '14 12:02

César Rodríguez


People also ask

What is Pandoc used for?

Pandoc is a command-line tool for converting files from one markup language to another. Markup languages use tags to annotate sections of a document. Commonly used markup languages include Markdown, ReStructuredText, HTML, LaTex, ePub, and Microsoft Word DOCX.

Can Pandoc convert HTML to Markdown?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.

How do you use extensions in Pandoc?

An extensions can be enabled by adding +EXTENSION to the format name and disabled by adding -EXTENSION . For example, markdown_strict+footnotes is strict Markdown with footnotes enabled, while markdown-footnotes-pipe_tables is pandoc's Markdown without footnotes or pipe tables.


1 Answers

I managed to solved this by executing the following command:

pandoc -s file_name.html -o file_name.docx;

There are actually 2 important ponits that you need to consider:

  1. The quality of the output file is pretty much related to how pandoc interpret your HTML file, so that if the source was pretty complex then you wouldn't really expect a pretty good quality output, for instance the <hr/> tag is not recognized by pandoc, while the <p> tag is.
  2. The path of the image is not an HTTP path but instead it is a full desk path, meaning:

This is NO good:

<img src="http://www.example.com/images/img.jpg" />

And This is what pandoc can really read:

<img src="/var/www/example.com/images/img.jpg" />

HTH

like image 77
Ma'moon Al-Akash Avatar answered Oct 19 '22 20:10

Ma'moon Al-Akash