-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
449 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
package me.hcl.seekin.Util | |||
|
|||
import groovy.text.SimpleTemplateEngine | |||
import org.xhtmlrenderer.pdf.ITextRenderer; | |||
import javax.xml.parsers.DocumentBuilder | |||
import javax.xml.parsers.DocumentBuilderFactory | |||
import org.w3c.dom.Document | |||
|
|||
|
|||
class PdfService { | |||
|
|||
boolean transactional = false | |||
|
|||
def buildPdf(file, model, response, url) | |||
{ | |||
|
|||
def reader = file.newReader('UTF-8') | |||
|
|||
SimpleTemplateEngine ste = new SimpleTemplateEngine() | |||
|
|||
def template = ste.createTemplate( reader ) | |||
ByteArrayOutputStream temp = new ByteArrayOutputStream() | |||
temp << template.make( model ) | |||
def content = temp.toString() | |||
|
|||
InputStream stream = new ByteArrayInputStream(content.getBytes("UTF-8")) | |||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance() | |||
documentBuilderFactory.setFeature ("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) | |||
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); | |||
Document doc = builder.parse(stream) | |||
|
|||
|
|||
ITextRenderer renderer = new ITextRenderer() | |||
renderer.setDocument(doc, url) | |||
renderer.layout() | |||
|
|||
renderer.createPDF response.outputStream | |||
|
|||
} | |||
|
|||
def removeSpecialCharacters(str) | |||
{ | |||
return str.replaceAll("[^a-zA-Z]+", ""); | |||
} | |||
} |
This file contains 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
package me.hcl.seekin.Util | |||
|
|||
import grails.test.* | |||
|
|||
class PdfServiceTests extends GrailsUnitTestCase { | |||
protected void setUp() { | |||
super.setUp() | |||
} | |||
|
|||
protected void tearDown() { | |||
super.tearDown() | |||
} | |||
|
|||
void testSomething() { | |||
|
|||
} | |||
} |
Oops, something went wrong.