obsidian-pandoc icon indicating copy to clipboard operation
obsidian-pandoc copied to clipboard

[BUG] Pandoc cannot find image file unless full relative path is used

Open wychwitch opened this issue 2 years ago • 10 comments

Hello! I was trying to convert one of my files to PDF, I received the following error

Obsidian_H4jAWcObZZ

The thing is, that picture isn't in the root folder, it's in a nested folder called __Assets.

The full path is C:\Users\Username\Documents\[[Obsidian]]\Folks and Tales\Ash In The Snow\PCs\__Assets

If the full relative path (Ash In The Snow/PCs/__Assets/Axiom.png) is specified, then works. The only way to do this in obsidian (that I know of?) is by having multiple files by the same name, which forces obsidian to have a full relative link to that exact file.

Is there any way to work around this issue? I can provide any files or my exact file structure if needed.

wychwitch avatar Nov 02 '21 17:11 wychwitch

Came here to report the same issue. Hope it can be solved!

luckman212 avatar Nov 08 '21 13:11 luckman212

subscribing to this one. when in Obsidain Options, Files and Links, I have defined a subfolder name for images, "attachments" for example, all pictures are in /attachments folder. Obsidian sees them and displays render them correctly. Pandoc plugin cannot see them and complains those binaries do not exist.

Alkaceq avatar Nov 14 '21 10:11 Alkaceq

I had a similar problem on Macos. Hope my solution translates to Windows... I tried to specify the image folder by using the parameter in the plugin settings:

--resource-path='[abs_path_name_containing_spaces]'

but it failed with the (no such file or directory) error. Even when I escaped the spaces. Using the same parameter on commandline with pandoc it did work. The problems seems to be that parameters cannot contain spaces when you specify them in the settings for this plugin. The path to the Obsidianvault when placed in iCloud allways contains at least one space. So removing the spaces in the path is impossible. I discovered a pandoc parameter so worked around it by specifying instead:

--defaults=[path_to_yaml_file_no_spaces]

I put an .pandoc-obs.yaml file (you can use any filename withoud spaces) in my homedir (no spaces in the path there). And the yaml-file contains the parameter in YAML syntax:

resource-path: ["/Users/ncdegroot/Library/Mobile Documents/iCloud~md~obsidian/Documents/Notes/00-Meta/03-Attachments"] That worked. At least after I changed the ![[image_file_name_no_path]] links to the more MD standard !()[image_filename_no_path] to get the image to appear in the generated .docx file. To create .PDF I still need to install some more latex stuff, but thats another story.

Hope its helps!

ndegroot avatar Jan 14 '22 22:01 ndegroot

Your solution works on Windows, thank you! Here's what we did:

  • Converted ![[Obsidian image links]] to ![Markdown image links](/path/to/image.png)
  • Created C:/Users/Joshu/pandoc-defaults.yaml, containing this line: resource-path: ["C:/Users/Joshu/OneDrive - DIU/Josh Stuff/Obsidian/Attachment Folder"]
  • Added this line to "Extra Pandoc Arguments" in the Pandoc plugin settings: --defaults=C:/Users/Joshu/pandoc-defaults.yaml

After following these steps, Pandoc was able to export Markdown files into .docx. Only image links that specified a size at the end (image.png|300) wouldn't work; we'll just clean those out manually.

Thanks for your help with this workaround!

DawnPaladin avatar Jan 15 '22 18:01 DawnPaladin

While Obsidian is currently not able to copy images from a note, I am currently using this Pandoc plugin to export the images from a note so I am able to publish it on a different platform, in my case Confluence.

A recent extension was added to Pandoc to be able look files relative to the note. To implement this on this plugin I modified line 11286 in main.js file file: inputFile, format: 'markdown', to file: inputFile, format: 'markdown+rebase_relative_paths',. Next, all new links format are set to "Absolute path in vault". This is a very rough workaround. If someone familiar concatenating the links in this plugin to avoid messing with the new links format setting please add it to this plugin. Thanks.

mistune avatar Feb 20 '22 09:02 mistune

Adding --from markdown+rebase_relative_paths to the "Extra Pandoc arguments", and setting "Export files from HTML or markdown?" to markdown as (implicitly) suggested by @ZeroCommits, solved it for me!

FynnFreyer avatar Jan 19 '23 11:01 FynnFreyer

I have completely left behind ObsidianPandoc specifically because of this issue, and because it is way beyond my level of knowledge, and I simply don't have the time to learn it for this issue alone.

As an alternative workaround, I am now using ObsidianHTML to compile a standard markdown file from a note. This I then convert to R-Markdown (just changing file type to .rmd), use my own (windows-only) script to convert the image src's created by ObsidianHTML to valid knitr-compatible image-embeds for RMarkdown and optionally auto-knit it to the desired output formats.*

It's an arguably weird workaround, but I can now ditch ObsidianPandoc completely with minimal overhead (exporting to standard md can take a few seconds, running the script can take a few seconds) and have the side-advantage of being able to leverage R in my manuscripts - which I regularly have to do anyways.


*Not completely done with the project yet sadly, a few niceties are left on the list.

Gewerd-Strauss avatar Jan 19 '23 15:01 Gewerd-Strauss

I have a latex hack (to be added in yaml) for compiling from various folders, I often using includes for figures and move files, you need to adjust it to your paths accordingly, you can add as many path variations as you want, you could also experiment with relative folders using dots notation

header-includes: |
  \graphicspath{{figures}{chapters/figures}{../figures}{chapters}}

danieltomasz avatar Aug 18 '23 09:08 danieltomasz

I had a similar problem on Macos. Hope my solution translates to Windows... I tried to specify the image folder by using the parameter in the plugin settings:

--resource-path='[abs_path_name_containing_spaces]'

but it failed with the (no such file or directory) error. Even when I escaped the spaces. Using the same parameter on commandline with pandoc it did work. The problems seems to be that parameters cannot contain spaces when you specify them in the settings for this plugin. The path to the Obsidianvault when placed in iCloud allways contains at least one space. So removing the spaces in the path is impossible. I discovered a pandoc parameter so worked around it by specifying instead:

--defaults=[path_to_yaml_file_no_spaces]

I put an .pandoc-obs.yaml file (you can use any filename withoud spaces) in my homedir (no spaces in the path there). And the yaml-file contains the parameter in YAML syntax:

resource-path: ["/Users/ncdegroot/Library/Mobile Documents/iCloud~md~obsidian/Documents/Notes/00-Meta/03-Attachments"] That worked. At least after I changed the ![[image_file_name_no_path]] links to the more MD standard !()[image_filename_no_path] to get the image to appear in the generated .docx file. To create .PDF I still need to install some more latex stuff, but thats another story.

Hope its helps!

Also MacOS, but these method does not work for me.

museloki avatar Dec 22 '23 03:12 museloki

Works without this yaml too. only convert links to relative pathes. (![[../../../Extra/Attachments/Pasted image 20240228172709.png]]) With the plugin "Link Converter" can help here. oneclick on your file, to set all links to realtive path... perfect.

Sa1ToBob avatar Mar 02 '24 08:03 Sa1ToBob