Template

Inheritance: java.lang.Object

All Implemented Interfaces: java.lang.Iterable

public class Template implements Iterable<TemplateItem>

Provides the document template. It consists of TemplateItem objects which represent the items of the template such as text field and table definitions.

Learn more:

Constructors

Constructor Description
Template(Iterable<? extends TemplateItem> items) Initializes a new instance of the Template class.
Template(Iterable<? extends TemplateItem> items, TemplateOptions options) Initializes a new instance of the Template class.

Methods

Method Description
getCount() Gets the total number of template items.
get(int index) Gets the template item by an index.
getOptions() Gets the template options.
iterator()
load(String filePath) Loads a template from a file.
load(InputStream stream) Loads a template from a stream.
save(String filePath) Saves a template to a file.
save(OutputStream stream) Saves a template to a stream.

Template(Iterable<? extends TemplateItem> items)

public Template(Iterable<? extends TemplateItem> items)

Initializes a new instance of the Template class.

Usage:

// Create an array of template fields
 TemplateItem[] fields = new TemplateItem[]
 {
     new TemplateField(new TemplateRegexPosition("From"), "From", 0),
     new TemplateField(
         new TemplateLinkedPosition("From", new Size(100, 10), new TemplateLinkedPositionEdges(false, false, false, true)),
         "FromCompany",
         0),
     new TemplateField(
         new TemplateLinkedPosition("FromCompany", new Size(100, 30), new TemplateLinkedPositionEdges(false, false, false, true)),
         "FromAddress",
         0)
 };
 // Create a document template
 Template template = new Template(java.util.Arrays.asList(fields));
 

Parameters:

Parameter Type Description
items java.lang.Iterable<? extends com.groupdocs.parser.templates.TemplateItem> The collection of TemplateItem objects.

Template(Iterable<? extends TemplateItem> items, TemplateOptions options)

public Template(Iterable<? extends TemplateItem> items, TemplateOptions options)

Initializes a new instance of the Template class.

Parameters:

Parameter Type Description
items java.lang.Iterable<? extends com.groupdocs.parser.templates.TemplateItem> The collection of TemplateItem objects.
options TemplateOptions The template options.

getCount()

public int getCount()

Gets the total number of template items.

Returns: int - An integer that represents the total number of template items.

get(int index)

public TemplateItem get(int index)

Gets the template item by an index.

Parameters:

Parameter Type Description
index int The zero-based index of the template item.

Returns: TemplateItem - An instance of TemplateItem class.

getOptions()

public TemplateOptions getOptions()

Gets the template options.

Returns: TemplateOptions - An instance of TemplateOptions class.

iterator()

public Iterator<TemplateItem> iterator()

Returns: java.util.Iterator<com.groupdocs.parser.templates.TemplateItem>

load(String filePath)

public static Template load(String filePath)

Loads a template from a file.

Parameters:

Parameter Type Description
filePath java.lang.String The path to the file.

Returns: Template - An instance of Template class with loaded template.

load(InputStream stream)

public static Template load(InputStream stream)

Loads a template from a stream.

Parameters:

Parameter Type Description
stream java.io.InputStream The input stream.

Returns: Template - An instance of Template class with loaded template.

save(String filePath)

public void save(String filePath)

Saves a template to a file.

Parameters:

Parameter Type Description
filePath java.lang.String The path to the file.

save(OutputStream stream)

public void save(OutputStream stream)

Saves a template to a stream.

Parameters:

Parameter Type Description
stream java.io.OutputStream The output stream.