From 0a768f1cc568722973302554265efa414d097da3 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 21 Dec 2015 17:22:12 -0800 Subject: Added preliminary support for PDF creation via wkhtmltopdf. To use this: pandoc -t html5 -o result.pdf (and add `--mathjax` if you have math.) --- pandoc.hs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'pandoc.hs') diff --git a/pandoc.hs b/pandoc.hs index cfb9adc1c..a4906382a 100644 --- a/pandoc.hs +++ b/pandoc.hs @@ -1168,6 +1168,7 @@ convertWithOpts opts args = do let laTeXOutput = "latex" `isPrefixOf` writerName' || "beamer" `isPrefixOf` writerName' let conTeXtOutput = "context" `isPrefixOf` writerName' + let html5Output = "html5" `isPrefixOf` writerName' let laTeXInput = "latex" `isPrefixOf` readerName' || "beamer" `isPrefixOf` readerName' @@ -1367,27 +1368,28 @@ convertWithOpts opts args = do IOByteStringWriter f -> f writerOptions doc' >>= writeBinary PureStringWriter f | pdfOutput -> do - -- make sure writer is latex or beamer - unless (laTeXOutput || conTeXtOutput) $ + -- make sure writer is latex or beamer or context or html5 + unless (laTeXOutput || conTeXtOutput || html5Output) $ err 47 $ "cannot produce pdf output with " ++ writerName' ++ " writer" - let texprog = if conTeXtOutput - then "context" - else latexEngine - -- check for latex program - mbLatex <- findExecutable texprog - when (isNothing mbLatex) $ - err 41 $ texprog ++ " not found. " ++ - texprog ++ " is needed for pdf output." - - res <- makePDF texprog f writerOptions doc' + let pdfprog = case () of + _ | conTeXtOutput -> "context" + _ | html5Output -> "wkhtmltopdf" + _ -> latexEngine + -- check for pdf creating program + mbPdfProg <- findExecutable pdfprog + when (isNothing mbPdfProg) $ + err 41 $ pdfprog ++ " not found. " ++ + pdfprog ++ " is needed for pdf output." + + res <- makePDF pdfprog f writerOptions doc' case res of Right pdf -> writeBinary pdf Left err' -> do B.hPutStr stderr err' B.hPut stderr $ B.pack [10] - err 43 "Error producing PDF from TeX source" + err 43 "Error producing PDF" | otherwise -> selfcontain (f writerOptions doc' ++ ['\n' | not standalone']) >>= writerFn outputFile . handleEntities -- cgit v1.2.3