packages feed

orchid-0.0.6: src/Network/Orchid/Format/Pdf.hs

module Network.Orchid.Format.Pdf (fPdf) where

import Control.Monad (liftM)
import Data.ByteString.Lazy hiding (writeFile)
import Prelude hiding (readFile)
import System.Process (waitForProcess, runProcess)

import Text.Document.Document
import Network.Protocol.Uri
import Network.Orchid.Core.Backend
import Network.Orchid.Core.Format

fPdf = WikiFormat "pdf" "application/pdf" pdf

-- TODO: write to _cache dir, not /tmp
pdf :: Backend -> FilePath -> URI -> String -> IO Output
pdf _ _ _ src = do
  writeFile "/tmp/tex-to-pdf.tex"
    $ either show toLaTeX
    $ fromWiki src
  runProcess "pdflatex" ["-interaction=batchmode", "/tmp/tex-to-pdf.tex"]
    (Just "/tmp") Nothing Nothing Nothing Nothing
    >>= waitForProcess
  liftM BinaryOutput $ readFile "/tmp/tex-to-pdf.pdf"

{-  runProcess "latexmk" [
      "-pdf", "-silent", "-f", "-g"
    ] (Just "/tmp") Nothing Nothing Nothing Nothing
    >>= waitForProcess-}