summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/PDF.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-08-15 21:17:20 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-08-15 21:17:20 -0700
commitf8b6a224aec780785baf3112f24c44f6c424e6ba (patch)
tree734dafad19e1386f3338c7be95e8b9f7d95340ee /src/Text/Pandoc/PDF.hs
parent97fe6c35b5c8c5e3e076f712e841f1db13c5a0bd (diff)
Remove initial check for pdf creating program.
Instead, just try running it and raise the exception if it isn't found at that point. This improves things for users of Cygwin on Windows, where the executable won't be found by `findExecutable` unless `.exe` is added. The same exception is raised as before, but at a later point. Closes #3819.
Diffstat (limited to 'src/Text/Pandoc/PDF.hs')
-rw-r--r--src/Text/Pandoc/PDF.hs32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index ef6a4099c..65d546482 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -50,7 +50,9 @@ import System.Exit (ExitCode (..))
import System.FilePath
import System.IO (stdout)
import System.IO.Temp (withTempDirectory, withTempFile)
+import System.IO.Error (IOError, isDoesNotExistError)
import Text.Pandoc.Definition
+import Text.Pandoc.Error (PandocError(PandocPDFProgramNotFoundError))
import Text.Pandoc.MediaBag
import Text.Pandoc.MIME (getMimeType)
import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..))
@@ -193,7 +195,12 @@ tex2pdf' verbosity args tmpDir program source = do
let numruns = if "\\tableofcontents" `T.isInfixOf` source
then 3 -- to get page numbers
else 2 -- 1 run won't give you PDF bookmarks
- (exit, log', mbPdf) <- runTeXProgram verbosity program args 1 numruns tmpDir source
+ (exit, log', mbPdf) <- E.catch
+ (runTeXProgram verbosity program args 1 numruns tmpDir source)
+ (\(e :: IOError) -> if isDoesNotExistError e
+ then E.throwIO $
+ PandocPDFProgramNotFoundError program
+ else E.throwIO e)
case (exit, mbPdf) of
(ExitFailure _, _) -> do
let logmsg = extractMsg log'
@@ -321,8 +328,13 @@ ms2pdf verbosity args source = do
putStrLn $ "[makePDF] Contents:\n"
putStr $ T.unpack source
putStr "\n"
- (exit, out) <- pipeProcess (Just env') "pdfroff" args
- (BL.fromStrict $ UTF8.fromText source)
+ (exit, out) <- E.catch
+ (pipeProcess (Just env') "pdfroff" args
+ (BL.fromStrict $ UTF8.fromText source))
+ (\(e :: IOError) -> if isDoesNotExistError e
+ then E.throwIO $
+ PandocPDFProgramNotFoundError "pdfroff"
+ else E.throwIO e)
when (verbosity >= INFO) $ do
BL.hPutStr stdout out
putStr "\n"
@@ -350,7 +362,12 @@ html2pdf verbosity args source = do
putStrLn $ "[makePDF] Contents of " ++ file ++ ":"
BL.readFile file >>= BL.putStr
putStr "\n"
- (exit, out) <- pipeProcess (Just env') "wkhtmltopdf" programArgs BL.empty
+ (exit, out) <- E.catch
+ (pipeProcess (Just env') "wkhtmltopdf" programArgs BL.empty)
+ (\(e :: IOError) -> if isDoesNotExistError e
+ then E.throwIO $
+ PandocPDFProgramNotFoundError "wkhtml2pdf"
+ else E.throwIO e)
removeFile file
when (verbosity >= INFO) $ do
BL.hPutStr stdout out
@@ -397,7 +414,12 @@ context2pdf verbosity tmpDir source = inDirectory tmpDir $ do
putStrLn $ "[makePDF] Contents of " ++ file ++ ":"
BL.readFile file >>= BL.putStr
putStr "\n"
- (exit, out) <- pipeProcess (Just env') "context" programArgs BL.empty
+ (exit, out) <- E.catch
+ (pipeProcess (Just env') "context" programArgs BL.empty)
+ (\(e :: IOError) -> if isDoesNotExistError e
+ then E.throwIO $
+ PandocPDFProgramNotFoundError "context"
+ else E.throwIO e)
when (verbosity >= INFO) $ do
BL.hPutStr stdout out
putStr "\n"