chore(pdf): pdf generation demo working

This commit is contained in:
Steffen Jost 2022-05-31 18:03:46 +02:00
parent e3aa6aede0
commit 33df8e6fdc
3 changed files with 17 additions and 12 deletions

View File

@ -15,8 +15,9 @@ import qualified Data.ByteString.Lazy as L
import qualified Data.Set as Set import qualified Data.Set as Set
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Text.Pandoc as P import qualified Text.Pandoc as P
import qualified Text.Pandoc.PDF as P import qualified Text.Pandoc.PDF as P
-- import qualified Text.Pandoc.Builder as P
import Handler.Admin.Test.Download (testDownload) import Handler.Admin.Test.Download (testDownload)
@ -275,7 +276,7 @@ postAdminTestR = do
getAdminTestPdfR :: Handler TypedContent getAdminTestPdfR :: Handler TypedContent
getAdminTestPdfR = do getAdminTestPdfR = do
-- let typePDF = "application/pdf" :: ContentType let -- typePDF = "application/pdf" :: ContentType
-- typePDF = Settings.Mime.mimeLookup "pdfdemo.pdf" -- typePDF = Settings.Mime.mimeLookup "pdfdemo.pdf"
content <- liftIO . P.runIO $ do content <- liftIO . P.runIO $ do
tmpl <- P.compileDefaultTemplate "latex" tmpl <- P.compileDefaultTemplate "latex"
@ -284,13 +285,12 @@ getAdminTestPdfR = do
texopts = [] texopts = []
writeropts = def { P.writerTemplate = Just tmpl } writeropts = def { P.writerTemplate = Just tmpl }
doc <- P.readMarkdown def md doc <- P.readMarkdown def md
res <- P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc
case res of
Right bs -> return bs
Left err -> return err
case content of case content of
Right bs -> do Right (Right bs) -> do
-- sendResponse (typePDF, toContent bs) -- works too liftIO $ L.writeFile "generated.pdf" bs
now <- liftIO getCurrentTime now <- liftIO getCurrentTime
sendByteStringAsFile "demoPDF.pdf" (L.toStrict bs) now sendByteStringAsFile "demoPDF.pdf" (L.toStrict bs) now
Left err -> return $ toTypedContent $ tshow err -- sendResponse (typePDF, toContent bs)
Right (Left err) -> sendResponseStatus internalServerError500 $ tshow err
Left err -> sendResponseStatus internalServerError500 $ P.renderError err

View File

@ -64,3 +64,8 @@
<li>^{modal "Email-Test" (Right emailWidget')} <li>^{modal "Email-Test" (Right emailWidget')}
<li> <li>
Some icons: ^{isVisible False} ^{hasComment True} Some icons: ^{isVisible False} ^{hasComment True}
<section>
<h2>Download a generated PDF
Here is a
<a href=@{AdminTestPdfR}>Download-Link