Skip to content

rusakovichma/DocsReporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Documents generation system in docx, odt, pdf, xhtml and pptx formats based on templates.
Supported template formats: .docx, .odt and .pptx

Usage

  1. Add repository in pom.xml:

    <repository>
        <id>DocsReporter-mvn-repo</id>
        <url>https://raw.github.com/creepid/DocsReporter/mvn-repo/</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
  2. Add dependency:

    <dependency>
    	<groupId>by.creepid</groupId>
    	<artifactId>docsreporter</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    </dependency>
  3. Then add in context of a Spring application:

    <import resource="classpath*:META-INF/spring/docsreporter-context.xml" />
  4. Create report template and map object fields to the model via Mergefields: DocxProjectWithVelocity.docx document template

  5. Define reportTemplate bean instance in Spring context:

    <bean id="reportTemplate" parent="reportTemplateBase">
        <property name="templatePath">
            <value>/pathto/template/DocxProjectWithVelocity.docx</value>
        </property>
        <property name="modelClass">
            <value>by.creepid.docsreporter.model.Project</value>
        </property> 
        <property name="modelName" value="project"/>
    </bean>

    templatePath - path a template (only .docx, .odt and .pptx is supported)
    modelClass - model class (deep hierarchy is possible)
    modelName - context of the model in the template

  6. In source code generate the document based on the given template:

@Autowire
private ReportTemplate reportTemplate;

Fill the model and generate the document:

Project project = new Project();
...//fill the object

//If we have any dynamic images in our template define ImageExtractObserver instance:
ImageExtractObserver observer = new ImageExtractObserver() {
    public void getImage(byte[] content, String path) {
    //process image extraction event, maybe saving the image in some folder
    }
};

//choosing output document format (.docx, .odt, .pptx, .pdf, .xhtml available)
DocFormat outFormat = DocFormat.PDF;

//receive the resulting document content and save it to file, response wrapper, etc.
OutputStream out = reportTemplate.generateReport(outFormat, project, observer);

About

Documents generation system in docx, odt, pdf, xhtml and pptx formats based on templates

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published