jgm / pandoc

Universal markup converter
https://pandoc.org
Other
33.87k stars 3.34k forks source link

“pagedjs-cli not found” on Windows #8061

Open qbit86 opened 2 years ago

qbit86 commented 2 years ago

Explain the problem.

Include the exact command line you used...

pandoc -d defaults.yaml

...and all inputs necessary to reproduce the issue.

defaults.yaml:

from: commonmark_x
input-file: ${.}/input.md
metadata: { lang: en-US }
output-file: ${.}/output.pdf
pdf-engine: pagedjs-cli
self-contained: true
to: html5
variables: { document-css: false }

Please create as minimal an example as possible, to help the maintainers isolate the problem.

input.md can be any trivial markdown file.

Explain the output you received...

PS D:\...> pandoc -d defaults.yaml
pagedjs-cli not found. Please select a different --pdf-engine or install pagedjs-cli

...and how it differs from what you expected.

Expected behavior was generating output.pdf since all required dependencies are installed:

PS C:\...> Set-ExecutionPolicy Bypass -Scope Process
PS C:\...> pagedjs-cli --version
0.1.6
PS C:\...> npm --version
8.9.0
PS C:\...> node --version
v16.15.0

Pandoc version?

What version of pandoc are you using, on what OS?

pandoc-2.18-windows-x86_64.msi:

PS C:\...> pandoc --version
pandoc.exe 2.18
Compiled with pandoc-types 1.22.2, texmath 0.12.5, skylighting 0.12.3,
citeproc 0.7, ipynb 0.2, hslua 2.2.0
Scripting engine: Lua 5.4
jgm commented 2 years ago

Did you install pagedjs-cli? This does not come with pandoc. Is it in your path? Can you run it directly from the command line using pagedjs-cli?

qbit86 commented 2 years ago

Did you install pagedjs-cli?.. Is it in your path?

Yes, as I mentioned.

Can you run it directly from the command line using pagedjs-cli?

I can run it in both PowerShell and in cmd. And in Git-Bash too. These are three different scripts, as far as I see in %APPDATA%/npm.

C:\Users\...> pagedjs-cli -i input.html -o output.pdf
✔ Loaded
✔ Rendering 1 pages took 17.899999999906868 milliseconds.
✔ Generated
✔ Processed
✔ Saved to C:\Users\...\output.pdf
jgm commented 2 years ago

Sorry, I missed the info in your orginal report. I don't know what could be causing this. It could be a subtlety of Windows paths; maybe you're setting the path in a way that doesn't extend to subprocesses? Do other pdf engines work for you?

qbit86 commented 2 years ago

It could be a subtlety of Windows paths; maybe you're setting the path in a way that doesn't extend to subprocesses?

Maybe; I didn't set the paths explicitly. I installed node.js with installer (not nvm-windows), and installed pagedjs-cli globally with npm:

npm install -g pagedjs-cli

This resulted in adding C:\Users\...\AppData\Roaming\npm to user's PATH (not system PATH).

Do other pdf engines work for you?

Default wkhtmltopdf does work. But the resulting PDF is of poor quality, so I had to switch to another engine.

jgm commented 2 years ago

Can you try passing in an absolute path?

qbit86 commented 2 years ago

Well, when I pass absolute path into pdf-engine option it does sucessfully work...

Then, is there any way to pass the path relative to %APPDATA%? I've tried in my defaults.yaml:

pdf-engine: '%APPDATA%/npm/pagedjs-cli.cmd'

But this results in «%APPDATA%/npm/pagedjs-cli.cmd not found.» ${APPDATA} doesn't work either.

jgm commented 2 years ago

I would have thought that ${APPDATA} would work; this is the syntax for interpolating environment variables. But it turns out pdf-engine is not one of the options we do interpolation on. That's an oversight, I think, since you can pass in a path here. I can fix it.

qbit86 commented 2 years ago

I can fix it.

That would be nice, thanks. Also, please consider making pagedjs-cli the default engine instead of obsolete wkhtmltopdf.

Regarding the original issue. Now I've tried the same on three different Windows machines — everywhere result is the same: pagedjs-cli works fine when I invoke it directly (even without specifying the path), but it fails to be found when I call it via Pandoc (pdf-engine: pagedjs-cli). Maybe spawned pagedjs-cli process indeed doesn't have access to the PATH variable of the current user.

jgm commented 2 years ago

Unfortunately I'm an ignoramus when it comes to Windows, and I don't even have a Windows box to mess around with. Hopefully someone else can figure out what is going on here. The change to pdf-engine handling has been made, now; you can try a nightly.

lunarcloud commented 1 year ago

Experiencing the same issue. Unfortunately, passing in an absolute path --pdf-engine="%ProgramFiles%\nodejs\pagedjs-cli.cmd" seems to work, but then it just HANGS at "Processed" whereas running pagedjs-cli standalone on a pandoc-generated html doesn't hang.

pandoc --standalone --embed-resources --defaults=../doc2/definition.yaml -f markdown-smart --pdf-engine="%ProgramFiles%\nodejs\pagedjs-cli.cmd" --output="../out/document2-pagedjs.pdf"

vs

pandoc --standalone --embed-resources --defaults=definition.yaml -f markdown-smart --output="%~dp0/../out/document2.html"
pagedjs-cli --media print -i "..\out\document2.html" -o "..\out\document2-pagedjs.pdf"
del "%~dp0/../out/document2.html"