@@ -46,10 +46,13 @@ import Control.Monad (unless, when, (<=<))
4646import qualified Control.Exception as E
4747import Data.List (isInfixOf)
4848import Data.Maybe (fromMaybe)
49+import qualified Data.Map as M
4950import qualified Text.Pandoc.UTF8 as UTF8
5051import Text.Pandoc.Definition
5152import Text.Pandoc.Walk (walkM)
52−import Text.Pandoc.Shared (fetchItem', warn, withTempDir, inDirectory)
53+import Text.Pandoc.Shared (fetchItem', warn, withTempDir, inDirectory,
54+ stringify)
55+import Text.Pandoc.Writers.Shared (getField, metaToJSON)
5356import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..))
5457import Text.Pandoc.MIME (extensionFromMimeType, getMimeType)
5558import Text.Pandoc.Process (pipeProcess)
@@ -70,14 +73,20 @@ makePDF :: String -- ^ pdf creator (pdflatex, lualatex,
7073 -> WriterOptions -- ^ options
7174 -> Pandoc -- ^ document
7275 -> IO (Either ByteString ByteString)
73−makePDF "wkhtmltopdf" writer opts doc =
74− wkhtml2pdf (writerVerbose opts) args source
75− where args = case writerHTMLMathMethod opts of
76− -- with MathJax, wait til all math is rendered:
76+makePDF "wkhtmltopdf" writer opts doc@(Pandoc meta _) = do
77+ let mathArgs = case writerHTMLMathMethod opts of
78+ -- with MathJax, wait til all math is rendered:
7779 MathJax _ -> ["--run-script", "MathJax.Hub.Register.StartupHook('End Typeset', function() { window.status = 'mathjax_loaded' });",
7880 "--window-status", "mathjax_loaded"]
7981 _ -> []
80− source = writer opts doc
82+ meta' <- metaToJSON opts (return . stringify) (return . stringify) meta
83+ let toArgs (f, d) = maybe (maybe [] (\x -> ['-':'-':f, x]) d)
84+ (\x -> ['-':'-':f, x]) $ getField f meta'
85+ let args = mathArgs ++
86+ concatMap toArgs [("page-size", Just "letter")
87+ ,("title", Nothing)]
88+ let source = writer opts doc
89+ html2pdf (writerVerbose opts) args source
8190makePDF program writer opts doc = withTempDir "tex2pdf." $ \tmpdir -> do
8291 doc' <- handleImages opts tmpdir doc
8392 let source = writer opts doc'
@@ -247,13 +256,13 @@ runTeXProgram verbose program args runNumber numRuns tmpDir source = do
247256 else return Nothing
248257 return (exit, out <> err, pdf)
249258
250−wkhtml2pdf :: Bool -- ^ Verbose output
251− -> [String] -- ^ Args to wkhtmltopdf
252− -> String -- ^ HTML5 source
253− -> IO (Either ByteString ByteString)
254−wkhtml2pdf verbose args source = do
255− file <- withTempFile "." "wkhtml2pdf.html" $ \fp _ -> return fp
256− pdfFile <- withTempFile "." "wkhtml2pdf.pdf" $ \fp _ -> return fp
259+html2pdf :: Bool -- ^ Verbose output
260+ -> [String] -- ^ Args to wkhtmltopdf
261+ -> String -- ^ HTML5 source
262+ -> IO (Either ByteString ByteString)
263+html2pdf verbose args source = do
264+ file <- withTempFile "." "html2pdf.html" $ \fp _ -> return fp
265+ pdfFile <- withTempFile "." "html2pdf.pdf" $ \fp _ -> return fp
257266 UTF8.writeFile file source
258267 let programArgs = args ++ [file, pdfFile]
259268 env' <- getEnvironment