PDF: support pagedjs-cli as pdf engine (#7838)

PagedJS is a polyfill and supports the Paged Media standards by the W3C.
<https://www.pagedjs.org/>
This commit is contained in:
Albert Krewinkel 2022-01-17 18:19:03 +01:00 committed by GitHub
parent 41476092ff
commit 7f50324ff9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View file

@ -1299,16 +1299,18 @@ header when requesting a document from a URL:
: Use the specified engine when producing PDF output. : Use the specified engine when producing PDF output.
Valid values are `pdflatex`, `lualatex`, `xelatex`, `latexmk`, Valid values are `pdflatex`, `lualatex`, `xelatex`, `latexmk`,
`tectonic`, `wkhtmltopdf`, `weasyprint`, `prince`, `context`, `tectonic`, `wkhtmltopdf`, `weasyprint`, `pagedjs-cli`,
and `pdfroff`. If the engine is not in your PATH, the full `prince`, `context`, and `pdfroff`. If the engine is not in
path of the engine may be specified here. If this option your PATH, the full path of the engine may be specified here.
is not specified, pandoc uses the following defaults If this option is not specified, pandoc uses the following
depending on the output format specified using `-t/--to`: defaults depending on the output format specified using
`-t/--to`:
- `-t latex` or none: `pdflatex` (other options: `xelatex`, `lualatex`, - `-t latex` or none: `pdflatex` (other options: `xelatex`, `lualatex`,
`tectonic`, `latexmk`) `tectonic`, `latexmk`)
- `-t context`: `context` - `-t context`: `context`
- `-t html`: `wkhtmltopdf` (other options: `prince`, `weasyprint`; - `-t html`: `wkhtmltopdf` (other options: `prince`, `weasyprint`,
`pagedjs-cli`;
see [print-css.rocks](https://print-css.rocks) for a good see [print-css.rocks](https://print-css.rocks) for a good
introduction to PDF generation from HTML/CSS.) introduction to PDF generation from HTML/CSS.)
- `-t ms`: `pdfroff` - `-t ms`: `pdfroff`

View file

@ -109,7 +109,7 @@ latexEngines :: [String]
latexEngines = ["pdflatex", "lualatex", "xelatex", "latexmk", "tectonic"] latexEngines = ["pdflatex", "lualatex", "xelatex", "latexmk", "tectonic"]
htmlEngines :: [String] htmlEngines :: [String]
htmlEngines = ["wkhtmltopdf", "weasyprint", "prince"] htmlEngines = ["pagedjs-cli", "wkhtmltopdf", "weasyprint", "prince"]
engines :: [(Text, String)] engines :: [(Text, String)]
engines = map ("html",) htmlEngines ++ engines = map ("html",) htmlEngines ++

View file

@ -70,7 +70,8 @@ changePathSeparators =
makePDF :: (PandocMonad m, MonadIO m, MonadMask m) makePDF :: (PandocMonad m, MonadIO m, MonadMask m)
=> String -- ^ pdf creator (pdflatex, lualatex, xelatex, => String -- ^ pdf creator (pdflatex, lualatex, xelatex,
-- wkhtmltopdf, weasyprint, prince, context, pdfroff, -- wkhtmltopdf, weasyprint, prince, context,
-- pdfroff, pagedjs,
-- or path to executable) -- or path to executable)
-> [String] -- ^ arguments to pass to pdf creator -> [String] -- ^ arguments to pass to pdf creator
-> (WriterOptions -> Pandoc -> m Text) -- ^ writer -> (WriterOptions -> Pandoc -> m Text) -- ^ writer
@ -80,7 +81,7 @@ makePDF :: (PandocMonad m, MonadIO m, MonadMask m)
makePDF program pdfargs writer opts doc = makePDF program pdfargs writer opts doc =
case takeBaseName program of case takeBaseName program of
"wkhtmltopdf" -> makeWithWkhtmltopdf program pdfargs writer opts doc "wkhtmltopdf" -> makeWithWkhtmltopdf program pdfargs writer opts doc
prog | prog `elem` ["weasyprint", "prince"] -> do prog | prog `elem` ["pagedjs-cli" ,"weasyprint", "prince"] -> do
source <- writer opts doc source <- writer opts doc
verbosity <- getVerbosity verbosity <- getVerbosity
liftIO $ html2pdf verbosity program pdfargs source liftIO $ html2pdf verbosity program pdfargs source
@ -434,7 +435,8 @@ html2pdf verbosity program args source =
hClose h1 hClose h1
hClose h2 hClose h2
BS.writeFile file $ UTF8.fromText source BS.writeFile file $ UTF8.fromText source
let pdfFileArgName = ["-o" | takeBaseName program == "prince"] let pdfFileArgName = ["-o" | takeBaseName program `elem`
["pagedjs-cli", "prince"]]
let programArgs = args ++ [file] ++ pdfFileArgName ++ [pdfFile] let programArgs = args ++ [file] ++ pdfFileArgName ++ [pdfFile]
env' <- getEnvironment env' <- getEnvironment
when (verbosity >= INFO) $ when (verbosity >= INFO) $