Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

images provided as links #7

Open
Try2Code opened this issue Mar 17, 2022 · 1 comment
Open

images provided as links #7

Try2Code opened this issue Mar 17, 2022 · 1 comment

Comments

@Try2Code
Copy link

hi!

I would like to know if there is a way to convert markdown to pdf with inline images like

![compilation process](https://miro.medium.com/max/1036/1*wHKe6W4opLmk6pb7sxZz6w.png)

At the moment the converter seems to assume local files

gems/kramdown-converter-pdf-1.0.5/lib/kramdown/converter/pdf.rb:158:in `initialize': No such file or directory @ rb_sysopen - ./https://miro.medium.com/max/1036/1*wHKe6W4opLmk6pb7sxZz6w.png (Errno::ENOENT)
@Try2Code Try2Code changed the title images as provided as links images provided as links Mar 17, 2022
@gmfvpereira
Copy link

This gems does work well with URL. But there's a rescue and retry that would hide the first error, which is the one you're probably trying to fix @Try2Code .

See the code:

img_dirs = @options.fetch(:image_directories, []) + ["."]
path_or_url = img.attr["src"]
begin
  image_obj, image_info = @pdf.build_image_object(open(path_or_url))
rescue StandardError => e
  puts "ERROR: #{e}"
  raise if img_dirs.empty?
  path_or_url = File.join(img_dirs.shift, img.attr["src"])
  retry
end

On the first try your open call is likely failing. Then it rescue the error, change the path_or_url variable joining the img_dirs content and try again. Given that img_dirs will always have a "." it sounds like the error is related to the fact that ConverterPdf is looking locally for a URL, but that's false. Looking locally by joining the img_dirs is just a fallback in case the URL fails.

I had the same problem, and adding a little bit of extra logging I could figure out what was my issue. In my case, the external image was returning a 404.

begin
  image_obj, image_info = @pdf.build_image_object(open(path_or_url))
rescue StandardError => e
  puts "ERROR: #{e}"  # Extra logging
  raise if img_dirs.empty?
  path_or_url = File.join(img_dirs.shift, img.attr["src"])
  retry
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants