pandoc convert html with style sheet to docx

℡╲_俬逩灬. 提交于 2019-12-20 19:36:14

问题


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.


回答1:


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




回答2:


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"



来源:https://stackoverflow.com/questions/29483060/pandoc-convert-html-with-style-sheet-to-docx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!