pypandoc: Windows html to docx fails to embed images in the docx file
I have an html file which links to an image in the same folder, when converting from html to docx on windows it throws the error [WARNING] Could not fetch resource test.png: PandocResourceNotFound "test.png"
pypandoc-binary==1.10
html file:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<body>
<h1 class="section">Test Heading</h1>
<div class="row">
<img src="test.png" alt="test alt" />
</div>
</body>
</html>
python script
import pypandoc
pypandoc.convert_file(
'index.html',
to='docx',
format='html',
outputfile='test.docx',
)
output of python test.py:
[WARNING] Could not fetch resource test.png: PandocResourceNotFound "test.png"
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (10 by maintainers)
Commits related to this issue
- Added test logic for issue #316 (that's not working as expected yet) — committed to JessicaTegner/pypandoc by JessicaTegner 4 years ago
@JessicaTegner thanks for the prompt response. While I’m no expert on the implications of the options you provided, I don’t think it’s unreasonable to have
sandbox=Falseby default as this would replicate the pandoc CLI usage more closely and avoid confusion.Namely, when using pandoc directly one would have to explicitly provide
--sandboxas a parameter in order to run in a sandbox mode, so the same can be true forpypandocby explicitly requiring users to specifysandbox=Trueto get the sandbox effect. This way, if the users “go out of their way” to override the default value of thesandboxparameter, then they would have presumably readpandoc’s documentation and know that they need to useembed_data_filesoption along with it (e.g. for conversion to docx), which should hopefully avoid errors such as the one in this issue.In either case, more thorough documentation is needed, especially if we keep
sandbox=Trueby default.I had the same issue and passing
sandbox=False(default is True) fixed it for me. So in your case it’d be@JessicaTegner It seems setting
sandbox=Falseis not recommended in most cases, based on the docstring:param bool sandbox: Run pandoc in pandocs own sandbox mode, limiting IO operations in readers and writers to reading the files specified on the command line. Anyone using pandoc on untrusted user input should use this option. Note: This only does something, on pandoc >= 2.15. Do you have suggestions on how to avoid having to setsandboxto False and still have images working as expected?