Skip to content

Instantly share code, notes, and snippets.

@reite
Created May 1, 2014 12:48
Show Gist options
  • Save reite/33c9527daf8088ebb0bf to your computer and use it in GitHub Desktop.
Save reite/33c9527daf8088ebb0bf to your computer and use it in GitHub Desktop.
import System.Process
import GHC.IO.Handle
import Text.Blaze.Html (Html)
import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
convertHtml :: Html -> IO B.ByteString
convertHtml html = do
(Just stdin, Just stdout, _, _) <- createProcess $
(wkhtmltopdf ["-", "-"]) { std_out = CreatePipe
, std_in = CreatePipe
}
BL.hPutStr stdin (renderHtml html) >> hClose stdin
B.hGetContents stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment