英文:
File path error while converting .md to .pdf
问题
在一个Python脚本中,我试图使用subprocess和pandoc模块将.md
文件转换为.pdf
文件,代码如下:
subprocess.run(["pandoc", "--standalone", "--pdf-engine=xelatex", "/file/path/file.md", "-o", "/file/path/file.pdf"])
然而,在Markdown文件中的图像文件方面,我遇到了以下错误:
[警告] 无法获取资源 'image.png':用描述替换图像
图像文件与.md
文件位于同一个目录中,在转换为.html
文件时,相同的图像路径可以正常工作。有人能指出这里的问题是什么吗?
英文:
In a python script I'm trying to convert a .md
file to .pdf
using subprocess and pandoc module as given below
subprocess.run(["pandoc", "--standalone", "--pdf-engine=xelatex", "/file/path/file.md", "-o", "/file/path/file.pdf")
However I get the following error with image files in the markdown file
[WARNING] Could not fetch resource 'image.png': replacing image with description
The image file is in the same directory as the .md
file, and the same image path works fine when it is converted to .html
file. Can someone point out what the problem is here?
答案1
得分: 1
当你运行调用pandoc的Python脚本时,pandoc会在其他包含图片的目录中执行。可以尝试传递--resource-path参数,将其指向与你的Markdown文件相同的目录,或者将subprocess.run的'cwd'参数指向Markdown文件所在的目录。
英文:
Wild quess; when you run your python script calling pandoc, pandoc gets executed on some other directory where the images are located. Maybe pass --resource-path that points to the same directory where your markdown file is or point cwd
kwarg of subprocess.run to the same directory where the markdown file resides.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论