diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-08-09 12:13:49 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-08-09 12:13:49 -0700 |
commit | 6b72c5e35ba9b0872704b77b2bd8793657adcaba (patch) | |
tree | 1ef014380618199c47aaf2b1d4a58d6313a847d3 /src/Text/Pandoc | |
parent | 8a4a5e506d3596f34e9b88cc22388ca8ca5afb6e (diff) | |
download | pandoc-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.hs | 15 |
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) |