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

[mac] org to pdf image absolute path not work #5517

Closed
peng051410 opened this issue May 22, 2019 · 13 comments · Fixed by #5522
Closed

[mac] org to pdf image absolute path not work #5517

peng051410 opened this issue May 22, 2019 · 13 comments · Fixed by #5522

Comments

@peng051410
Copy link

  • pandoc veriosn: pandoc 2.7.2
  • os: mac 10.14.3 (18D109)
  • org version: 9.1.9

when i run command
pandoc --self-contained --pdf-engine=xelatex --template=/Users/username/soft/plugin/latex/pm-template.latex -f org -t latex apollo-config-swim.org -o test.pdf

I got warn info:
[WARNING] Could not fetch resource 'file:///Users/username/github/blog/images/apollo-home-screenshot.png': PandocHttpError "file:///Users/username/github/blog/images/apollo-home-screenshot.png" (InvalidUrlException "file:///Users/username/github/blog/images/apollo-home-screenshot.png" "Invalid scheme")

org file image content:
[[file:/Users/username/github/blog/images/apollo-home-screenshot.png]]
[[/Users/username/github/blog/images/apollo-home-screenshot.png]]

these all not work!

What should i do ?

@mb21
Copy link
Collaborator

mb21 commented May 22, 2019

You don't want to use --self-contained when outputting to PDF. Also make sure the image file is actually there.

For future questions, please use the pandoc-discuss mailing list instead of this issue tracker. Thanks!

@mb21 mb21 closed this as completed May 22, 2019
@tarleb
Copy link
Collaborator

tarleb commented May 22, 2019

I can reproduce the problem for this syntax:

[[/Users/username/github/blog/images/apollo-home-screenshot.png]]

while this works as expected for me

[[file:/Users/username/github/blog/images/apollo-home-screenshot.png]]

Reopening, both variants should work.

@tarleb
Copy link
Collaborator

tarleb commented May 22, 2019

We currently convert a link [[file:/path/to/file.jpg]] to a link with source file:///path/to/file.jpg. We then run into problems in later conversion stages.

This is not unique to org-mode. Specifying an image with schema file: leads to problems with other input formats as well:

$ echo '![my image](file:///path/to/existing/image.jpg)' | pandoc --output image-output.pdf
[WARNING] Could not fetch resource …

@mb21
Copy link
Collaborator

mb21 commented May 22, 2019

But only file:///path is a valid URL, right?

I guess this is the place to look: https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/Class.hs#L577

@jgm
Copy link
Owner

jgm commented May 22, 2019 via email

@mb21
Copy link
Collaborator

mb21 commented May 22, 2019

Ah, both file:///path and file:/path seem to be valid, according to wikipedia.

@tarleb
Copy link
Collaborator

tarleb commented May 22, 2019 via email

@peng051410
Copy link
Author

You don't want to use --self-contained when outputting to PDF. Also make sure the image file is actually there.

For future questions, please use the pandoc-discuss mailing list instead of this issue tracker. Thanks!

I remove the --self-contained option, the problem is still.

@mb21
Copy link
Collaborator

mb21 commented May 23, 2019

With echo '![](file:///foo/bar.jpg)' | pandoc --self-contained, I get

InvalidUrlException "file:///foo/bar.jpg" "Invalid scheme"

I wanted to play around with some function in Pandoc.Class, but unfortunately stack ghci seems to be broken for me currently:

<no location info>: error: [-Wmissing-home-modules, -Werror=missing-home-modules]
    Modules are not listed in command line but needed for compilation: 
        Paths_pandoc

@jgm
Copy link
Owner

jgm commented May 23, 2019

InvalidUrlException comes from Network.HTTP.Client, used by openURL.

Check out this code from Text.Pandoc.Class:

downloadOrRead :: PandocMonad m
               => String
               -> m (B.ByteString, Maybe MimeType)
downloadOrRead s = do
  sourceURL <- getsCommonState stSourceURL
  case (sourceURL >>= parseURIReference' .
                       ensureEscaped, ensureEscaped s) of
    (Just u, s') -> -- try fetching from relative path at source
       case parseURIReference' s' of
            Just u' -> openURL $ show $ u' `nonStrictRelativeTo` u
            Nothing -> openURL s' -- will throw error

If the source parses as a URI, then we use openURL, but of course this doesn't make much sense when it's a file:/ URI. So we should check the scheme.

@mb21
Copy link
Collaborator

mb21 commented May 23, 2019

@peng051410 for me the following works:

echo '[[file:/Users/myuser/myfile.jpg]]' | pandoc -f org -o foo.pdf

@peng051410
Copy link
Author

peng051410 commented May 24, 2019

It works for me, Thanks!
The content is [[file:/Users/username/github/blog/images/apollo-overall-architecture.png][file:/Users/username/github/blog/images/apollo-overall-architecture.png]]

and [[file:/Users/username/github/blog/images/apollo-overall-architecture.png][/Users/username/github/blog/images/apollo-overall-architecture.png]] not works

@mb21
Copy link
Collaborator

mb21 commented May 24, 2019

Reopening for the file:/// case...

@mb21 mb21 reopened this May 24, 2019
mb21 added a commit to mb21/pandoc that referenced this issue May 24, 2019
move up the pattern match to be reachable, closes jgm#5517
mb21 added a commit to mb21/pandoc that referenced this issue May 24, 2019
move up the pattern match to be reachable, closes jgm#5517
mb21 added a commit to mb21/pandoc that referenced this issue May 24, 2019
move up the pattern match to be reachable, closes jgm#5517
mb21 added a commit to mb21/pandoc that referenced this issue May 24, 2019
move up the pattern match to be reachable, closes jgm#5517
mb21 added a commit to mb21/pandoc that referenced this issue May 24, 2019
move up the pattern match to be reachable, closes jgm#5517
mb21 added a commit to mb21/pandoc that referenced this issue May 24, 2019
move up the pattern match to be reachable, closes jgm#5517
mb21 added a commit to mb21/pandoc that referenced this issue May 24, 2019
move up the pattern match to be reachable, closes jgm#5517
mb21 added a commit to mb21/pandoc that referenced this issue May 28, 2019
move up the pattern match to be reachable, closes jgm#5517
@jgm jgm closed this as completed in #5522 May 28, 2019
jgm pushed a commit that referenced this issue May 28, 2019
Move up the pattern match to be reachable, closes #5517.

Previously `file:/` URLs were handled wrongly and pandoc attempted
to make HTTP requests, which failed.
jgm added a commit that referenced this issue May 28, 2019
jgm added a commit that referenced this issue May 28, 2019
We need a better test that works cross-platform.
Until then, removing this.

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

Successfully merging a pull request may close this issue.

4 participants