Created
May 12, 2014 06:47
-
-
Save TomTriple/c9cf62b4de634d1b2d1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sendPdf(htmlContent: String, filename: String) = { | |
val os = new java.io.ByteArrayOutputStream | |
val renderer = new ITextRenderer | |
renderer.setDocumentFromString(htmlContent) | |
renderer.layout | |
renderer.createPDF(os) | |
val bytes = os.toByteArray() | |
os.flush() | |
val enum = Enumerator.fromStream(new ByteArrayInputStream(bytes)) | |
SimpleResult( | |
header = ResponseHeader(200, Map( | |
CONTENT_TYPE -> "application/pdf", | |
CONTENT_DISPOSITION -> s"attachment; filename=$filename.pdf", | |
CONTENT_TRANSFER_ENCODING -> "binary")), | |
body = enum | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment