l2silver
l2silver

Reputation: 3439

pandoc convert html with style sheet to docx

I've been banging my head on this one for a few hours, and I'm sure the solution is quite simple, or non-existent.

I'm trying to convert an html file to docx!

<!DOCTYPE html>
<html>
<head>
<style>
body {
    background-color: #d0e4fe;
}

h1 {
    color: orange;
    text-align: center;
}

p {
    font-family: "Times New Roman";
    font-size: 20px;
}
</style>
</head>
<body>

<h1>My First CSS Example</h1>
<p>This is a paragraph.</p>

</body>
</html>

I can convert it no problem, but I can't get the styles to stick.

pandoc -s myfile.html -o test64.docx
pandoc -s -c myfile.css myfile.html -o test64.docx

Please save me.

Upvotes: 15

Views: 10779

Answers (2)

satnam
satnam

Reputation: 11494

The above answer no longer works. According to the documentation, you now produce the template using:

pandoc --print-default-data-file reference.docx > custom-reference.docx

For the full documentation of how to use the template, go to the documentation and search for "--reference-doc"

Upvotes: 9

Tony Williams
Tony Williams

Reputation: 647

In your command the "-c myfile.css" would only be used if you were writing to HTML or HTML 5. It is a writer specific option.

For docx formatting you need to create a ".docx" template.

Start by running pandoc -D docx > my_template.docx and then edit the styles in my_template.docx.

Finally run pandoc -s myfile.html --template=my_template -o test64.docx

Upvotes: 8

Related Questions