Skip to content

Commit

Permalink
Support svg in PDF output, converting with rsvg2pdf.
Browse files Browse the repository at this point in the history
Closes #1793.
  • Loading branch information
jgm committed Aug 9, 2017
1 parent 8a4a5e5 commit 6b72c5e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Text/Pandoc/PDF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6b72c5e

Please sign in to comment.