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

4
routes
View File

@ -54,8 +54,8 @@
!/users/functionary-invite AdminFunctionaryInviteR GET POST
!/users/add AdminUserAddR GET POST
/admin AdminR GET
/admin/test AdminTestR GET POST
/admin/test/pdf AdminTestPdfR GET
/admin/test AdminTestR GET POST
/admin/test/pdf AdminTestPdfR GET
/admin/errMsg AdminErrMsgR GET POST
/admin/tokens AdminTokensR GET POST
/admin/crontab AdminCrontabR GET

View File

@ -15,8 +15,9 @@ import qualified Data.ByteString.Lazy as L
import qualified Data.Set as Set
import qualified Data.Map as Map
import qualified Text.Pandoc as P
import qualified Text.Pandoc.PDF as P
import qualified Text.Pandoc as P
import qualified Text.Pandoc.PDF as P
-- import qualified Text.Pandoc.Builder as P
import Handler.Admin.Test.Download (testDownload)
@ -275,7 +276,7 @@ postAdminTestR = do
getAdminTestPdfR :: Handler TypedContent
getAdminTestPdfR = do
-- let typePDF = "application/pdf" :: ContentType
let -- typePDF = "application/pdf" :: ContentType
-- typePDF = Settings.Mime.mimeLookup "pdfdemo.pdf"
content <- liftIO . P.runIO $ do
tmpl <- P.compileDefaultTemplate "latex"
@ -284,13 +285,12 @@ getAdminTestPdfR = do
texopts = []
writeropts = def { P.writerTemplate = Just tmpl }
doc <- P.readMarkdown def md
res <- P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc
case res of
Right bs -> return bs
Left err -> return err
P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc
case content of
Right bs -> do
-- sendResponse (typePDF, toContent bs) -- works too
Right (Right bs) -> do
liftIO $ L.writeFile "generated.pdf" bs
now <- liftIO getCurrentTime
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>
Some icons: ^{isVisible False} ^{hasComment True}
<section>
<h2>Download a generated PDF
Here is a
<a href=@{AdminTestPdfR}>Download-Link