git.iko.soy/typeable/pandoc
on master help sign in
Support svg in PDF output, converting with rsvg2pdf.
6b72c5eJohn MacFarlane
src/Text/Pandoc/PDF.hs+12−3
@@ -162,15 +162,24 @@ convertImage tmpdir fname =
162 Just "image/png" -> doNothing
162 Just "image/png" -> doNothing
163 Just "image/jpeg" -> doNothing
163 Just "image/jpeg" -> doNothing
164 Just "application/pdf" -> doNothing
164 Just "application/pdf" -> doNothing
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
165− Just "image/svg+xml" -> return $ Left "conversion from svg not supported"
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)
166 _ -> JP.readImage fname >>= \res ->
174 _ -> JP.readImage fname >>= \res ->
167 case res of
175 case res of
168 Left e -> return $ Left e
176 Left e -> return $ Left e
169 Right img ->
177 Right img ->
170− E.catch (Right fileOut <$ JP.savePngImage fileOut img) $
178+ E.catch (Right pngOut <$ JP.savePngImage pngOut img) $
171 \(e :: E.SomeException) -> return (Left (show e))
179 \(e :: E.SomeException) -> return (Left (show e))
172 where
180 where
173− fileOut = replaceDirectory (replaceExtension fname ".png") tmpdir
181+ pngOut = replaceDirectory (replaceExtension fname ".png") tmpdir
182+ pdfOut = replaceDirectory (replaceExtension fname ".pdf") tmpdir
174 mime = getMimeType fname
183 mime = getMimeType fname
175 doNothing = return (Right fname)
184 doNothing = return (Right fname)
176
185