GithubHelp home page GithubHelp logo

document-builder's Introduction

Groovy Document Builder

status?branch=master

A document builder for Groovy for PDF or Word documents. This is still very much a work in progress.

Example

@Grab(group='com.craigburke.document', module='pdf', version='0.1.6')
@Grab(group='com.craigburke.document', module='word', version='0.1.6')

import com.craigburke.document.builder.PdfDocumentBuilder
import com.craigburke.document.builder.WordDocumentBuilder

def builders = [
        new PdfDocumentBuilder(new File('example.pdf')),
        new WordDocumentBuilder(new File('example.docx')),
]

def RAINBOW_COLORS = ['#FF0000', '#FF7F00', '#FFFF00', '#00FF00', '#0000FF', '#4B0082', '#8B00FF']

String GROOVY_IMAGE_URL = 'http://www.craigburke.com/images/posts/groovy-logo.png'
byte[] groovyImageData = new URL(GROOVY_IMAGE_URL).bytes

builders.each { builder ->
    builder.create {
	document(font: [family: 'Helvetica', size: 14.pt], margin: [top: 0.75.inches]) {

        paragraph "Groovy Document Builder", font: [size: 22.pt]

        paragraph {
            font.size = 42.pt
            "Hello Woooorld!!!!!".toUpperCase().eachWithIndex { letter, index ->
                font.size--
                font.color = RAINBOW_COLORS[ index % RAINBOW_COLORS.size() ]
                text letter
            }
            lineBreak()
            text "Current font size is ${font.size}pt"
        }

        paragraph "Font size is back to 14pt now with the default black font"

        paragraph(margin: [left: 1.25.inches, right: 1.inch, top: 0.25.inches, bottom: 0.25.inches]) {
            font << [family: 'Times-Roman', bold: true, italic: true, color: '#333333']
            text "A paragraph with a different font and margins"
        }

        paragraph(margin: [left: 1.inch]) {
            image(data: groovyImageData, width: 250.px, height: 125.px)
            lineBreak()
            text "Figure 1: Groovy Logo", font: [italic: true, size: 9.pt]
        }

        paragraph("Suddenly, a table...", font: [size: 22.pt], margin: [bottom: 0.25.inches])

        table(width: 5.inches) {
            row {
                cell("Cell 1", width: 1.inch)
                cell("Cell 2", width: 2.inches)
                cell(width: 2.inches) {
                    text "Cell 3"
                }
            }
        }
    }}
}

License

The core project as well as the Word document builder are available under the MPL2 license. However, because of the use of iText, the PDF document builder is currently only available under a more restrictive AGPL license.

Iโ€™m currently looking into the possibility of developing a PDF builder that uses PdfBox as a dependency and could be made available under the same MPL2 licence as the rest of the project (currently no ETA on that).

TODO

  • Implement PdfBox builder

  • Add sections/headers

  • Add links

  • Add lists

  • Proper Documentation

document-builder's People

Contributors

craigburke avatar yellowsnow avatar

Watchers

James Cloos avatar shotishu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.