git.iko.soy/typeable/pandoc
on master help sign in
Allow pdf output to stdout.

PDF output will not be output to the terminal, but can be sent to stdout using either `-o -` or a pipe. The intermediate format will be determined based on the setting of `--pdf-engine`. Closes #5751.

commite906e5ac23177c4377591c73c8e796e764096a32 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 3 Nov 2019, 11:44 (7 years ago) parentc4ff0b5
3 files changed+19−14
MANUAL.txt+2−1 src/Text/Pandoc/App.hs+2−1 src/Text/Pandoc/App/OutputSettings.hs+15−12
MANUAL.txt+2−1
@@ -308,6 +308,7 @@ header when requesting a document from a URL:
308308 - `opml` ([OPML])
309309 - `opendocument` ([OpenDocument])
310310 - `org` ([Emacs Org mode])
311+ - `pdf` ([PDF])
311312 - `plain` (plain text),
312313 - `pptx` ([PowerPoint] slide show)
313314 - `rst` ([reStructuredText])
@@ -325,7 +326,7 @@ header when requesting a document from a URL:
325326 - the path of a custom lua writer, see [Custom writers] below
326327 :::
327328
328− Note that `odt`, `docx`, and `epub` output will not be directed
329+ Note that `odt`, `docx`, `epub`, and `pdf` output will not be directed
329330 to *stdout* unless forced with `-o -`.
330331
331332 Extensions can be individually enabled or
src/Text/Pandoc/App.hs+2−1
@@ -185,7 +185,8 @@ convertWithOpts opts = do
185185 -- force this with '-o -'. On posix systems, we detect
186186 -- when stdout is being piped and allow output to stdout
187187 -- in that case, but on Windows we can't.
188− when (not (isTextFormat format) && istty && isNothing ( optOutputFile opts)) $
188+ when ((pdfOutput || not (isTextFormat format)) &&
189+ istty && isNothing ( optOutputFile opts)) $
189190 throwError $ PandocAppError $
190191 "Cannot write " ++ format ++ " output to terminal.\n" ++
191192 "Specify an output file using the -o option, or " ++
src/Text/Pandoc/App/OutputSettings.hs+15−12
@@ -65,21 +65,26 @@ optToOutputSettings opts = do
6565 Nothing -> return Nothing
6666 Just fp -> Just <$> readUtf8File fp
6767
68− let pdfOutput = map toLower (takeExtension outputFile) == ".pdf"
68+ let pdfOutput = map toLower (takeExtension outputFile) == ".pdf" ||
69+ optTo opts == Just "pdf"
6970 (writerName, maybePdfProg) <-
7071 if pdfOutput
71− then liftIO $ pdfWriterAndProg (optTo opts) (optPdfEngine opts)
72+ then liftIO $ pdfWriterAndProg
73+ (case optTo opts of
74+ Just "pdf" -> Nothing
75+ x -> x)
76+ (optPdfEngine opts)
7277 else case optTo opts of
78+ Just f -> return (f, Nothing)
7379 Nothing
74− | outputFile == "-" -> return ("html", Nothing)
75− | otherwise ->
76− case formatFromFilePaths [outputFile] of
80+ | outputFile == "-" -> return ("html", Nothing)
81+ | otherwise ->
82+ case formatFromFilePaths [outputFile] of
7783 Nothing -> do
7884 report $ CouldNotDeduceFormat
7985 [takeExtension outputFile] "html"
8086 return ("html", Nothing)
8187 Just f -> return (f, Nothing)
82− Just f -> return (f, Nothing)
8388
8489 let format = if ".lua" `isSuffixOf` writerName
8590 then writerName
@@ -244,13 +249,10 @@ baseWriterName = takeWhile (\c -> c /= '+' && c /= '-')
244249pdfWriterAndProg :: Maybe String -- ^ user-specified writer name
245250 -> Maybe String -- ^ user-specified pdf-engine
246251 -> IO (String, Maybe String) -- ^ IO (writerName, maybePdfEngineProg)
247−pdfWriterAndProg mWriter mEngine = do
248− let panErr msg = liftIO $ E.throwIO $ PandocAppError msg
252+pdfWriterAndProg mWriter mEngine =
249253 case go mWriter mEngine of
250254 Right (writ, prog) -> return (writ, Just prog)
251− Left "pdf writer" -> liftIO $ E.throwIO $
252− PandocUnknownWriterError "pdf"
253− Left err -> panErr err
255+ Left err -> liftIO $ E.throwIO $ PandocAppError err
254256 where
255257 go Nothing Nothing = Right ("latex", "pdflatex")
256258 go (Just writer) Nothing = (writer,) <$> engineForWriter writer
@@ -273,4 +275,5 @@ pdfWriterAndProg mWriter mEngine = do
273275 "cannot produce pdf output from " ++ w
274276
275277isTextFormat :: String -> Bool
276−isTextFormat s = s `notElem` ["odt","docx","epub2","epub3","epub","pptx"]
278+isTextFormat s =
279+ s `notElem` ["odt","docx","epub2","epub3","epub","pptx","pdf"]