File path error while converting .md to .pdf 将 .md 转换为 .pdf 时出现文件路径错误。

huangapple go评论78阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月10日 17:23:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76216802.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定