-
-
Save Arakade/932bd8c9d3b359fe30a3 to your computer and use it in GitHub Desktop.
Updated 2014/07/05 for newer repositories syntax and missing Xalan dependency (needed on Windows)
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
import com.petebevin.markdown.MarkdownProcessor | |
import org.xhtmlrenderer.pdf.ITextRenderer | |
import org.ccil.cowan.tagsoup.Parser | |
import org.apache.xalan.xsltc.trax.SAX2DOM | |
import org.xml.sax.InputSource | |
buildscript{ | |
repositories { | |
mavenCentral() // i.e. http://repo1.maven.org/maven2 | |
maven { url "https://oss.sonatype.org/content/groups/scala-tools" } | |
maven { url "https://oss.sonatype.org/content/repositories/snapshots/org/markdownj/markdownj" } | |
maven { url "http://download.java.net/maven/2/" } | |
} | |
dependencies { | |
classpath "org.markdownj:markdownj:0.3.0-1.0.2b4" | |
classpath "org.ccil.cowan.tagsoup:tagsoup:1.2" | |
classpath "org.xhtmlrenderer:core-renderer:R8" | |
classpath "xalan:xalan:2.7.1" | |
} | |
} | |
task run <<{ | |
def source = "resume.markdown" | |
def target = "resume.pdf" | |
//Convert from markdown to html | |
def mp = new MarkdownProcessor() | |
def html = "<html><body>${mp.markdown((new File(source).text))}</body></html>" | |
//Convert from html to w3c document | |
def parser = new Parser() | |
def sax2dom = new SAX2DOM() | |
parser.setContentHandler(sax2dom); | |
parser.setFeature(Parser.namespacesFeature, false); | |
parser.parse(new InputSource(new ByteArrayInputStream(html.getBytes()))); | |
//Use Document to create pdf | |
ITextRenderer renderer = new ITextRenderer(); | |
renderer.setDocument(sax2dom.getDOM(), null); | |
renderer.layout(); | |
renderer.createPDF((new File(target).newOutputStream())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment