git.iko.soy/typeable/pandoc
on master help sign in
Support svg in PDF output, converting with rsvg2pdf.

Closes #1793.

commit6b72c5e35ba9b0872704b77b2bd8793657adcaba authorJohn MacFarlane <jgm@berkeley.edu> dateWed 9 Aug 2017, 12:13 (9 years ago) parent8a4a5e5
1 file changed+12−3
src/Text/Pandoc/PDF.hs+12−3
src/Text/Pandoc/PDF.hs+12−3
@@ -162,15 +162,24 @@ convertImage tmpdir fname =
162162 Just "image/png" -> doNothing
163163 Just "image/jpeg" -> doNothing
164164 Just "application/pdf" -> doNothing
165− Just "image/svg+xml" -> return $ Left "conversion from svg not supported"
165+ Just "image/svg+xml" -> E.catch (do
166+ (exit, _) <- pipeProcess Nothing "rsvg-convert"
167+ ["-f","pdf","-a","-o",pdfOut,fname] BL.empty
168+ if exit == ExitSuccess
169+ then return $ Right pdfOut
170+ else return $ Left "conversion from SVG failed")
171+ (\(e :: E.SomeException) -> return $ Left $
172+ "check that rsvg2pdf is in path.\n" ++
173+ show e)
166174 _ -> JP.readImage fname >>= \res ->
167175 case res of
168176 Left e -> return $ Left e
169177 Right img ->
170− E.catch (Right fileOut <$ JP.savePngImage fileOut img) $
178+ E.catch (Right pngOut <$ JP.savePngImage pngOut img) $
171179 \(e :: E.SomeException) -> return (Left (show e))
172180 where
173− fileOut = replaceDirectory (replaceExtension fname ".png") tmpdir
181+ pngOut = replaceDirectory (replaceExtension fname ".png") tmpdir
182+ pdfOut = replaceDirectory (replaceExtension fname ".pdf") tmpdir
174183 mime = getMimeType fname
175184 doNothing = return (Right fname)
176185