aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-08-09 12:13:49 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-08-09 12:13:49 -0700
commit6b72c5e35ba9b0872704b77b2bd8793657adcaba (patch)
tree1ef014380618199c47aaf2b1d4a58d6313a847d3 /src/Text/Pandoc
parent8a4a5e506d3596f34e9b88cc22388ca8ca5afb6e (diff)
downloadpandoc-6b72c5e35ba9b0872704b77b2bd8793657adcaba.tar.gz
Support svg in PDF output, converting with rsvg2pdf.
Closes #1793.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/PDF.hs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index 25a94972a..ef6a4099c 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -162,15 +162,24 @@ convertImage tmpdir fname =
Just "image/png" -> doNothing
Just "image/jpeg" -> doNothing
Just "application/pdf" -> doNothing
- Just "image/svg+xml" -> return $ Left "conversion from svg not supported"
+ Just "image/svg+xml" -> E.catch (do
+ (exit, _) <- pipeProcess Nothing "rsvg-convert"
+ ["-f","pdf","-a","-o",pdfOut,fname] BL.empty
+ if exit == ExitSuccess
+ then return $ Right pdfOut
+ else return $ Left "conversion from SVG failed")
+ (\(e :: E.SomeException) -> return $ Left $
+ "check that rsvg2pdf is in path.\n" ++
+ show e)
_ -> JP.readImage fname >>= \res ->
case res of
Left e -> return $ Left e
Right img ->
- E.catch (Right fileOut <$ JP.savePngImage fileOut img) $
+ E.catch (Right pngOut <$ JP.savePngImage pngOut img) $
\(e :: E.SomeException) -> return (Left (show e))
where
- fileOut = replaceDirectory (replaceExtension fname ".png") tmpdir
+ pngOut = replaceDirectory (replaceExtension fname ".png") tmpdir
+ pdfOut = replaceDirectory (replaceExtension fname ".pdf") tmpdir
mime = getMimeType fname
doNothing = return (Right fname)