-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleRender.java
More file actions
66 lines (53 loc) · 2.37 KB
/
SimpleRender.java
File metadata and controls
66 lines (53 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.io.File;
import com.docmosis.SystemManager;
import com.docmosis.document.DocumentProcessor;
import com.docmosis.template.population.DataProviderBuilder;
import com.docmosis.util.Configuration;
/**
* A simple example showing Docmosis creating a PDF with dynamic data from a
* DOC template.
*/
public class SimpleRender
{
public static void main(String[] args)
{
String key = new String("XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-X-XXXX");
String site = new String("Free Trial License");
String officePath = new String("C:/Program Files/LibreOffice 5");
if (key.startsWith("XXXX")) {
System.err.println("\nPlease set your license key");
System.exit(1);
}
if (!new File(officePath).isDirectory() || !new File(officePath).canRead()) {
System.err.println("\nPlease check \"officePath\" is set to the " +
"install dir for OpenOffice or LibreOffice");
System.exit(1);
}
// Create the initialisation configuration
Configuration config = new Configuration(key, site, officePath);
// Tell Docmosis to use one embedded converter
config.setConverterPoolConfiguration("1");
// Use the DataProviderBuilder to build the data provider from a String array.
DataProviderBuilder dpb = new DataProviderBuilder();
dpb.add("date", "28Feb 2018");
dpb.add("message", "This Docmosis document engine is working!");
try {
// Initialise the system based on configuration
SystemManager.initialise(config);
File templateFile = new File("WelcomeTemplate.doc");
File outputFile = new File("newDocument.pdf");
if (!templateFile.canRead()) {
System.err.println("\nCannot find '" + templateFile + "' in: " + new File("").getCanonicalPath());
} else {
// Create the document
DocumentProcessor.renderDoc(templateFile, outputFile, dpb.getDataProvider());
System.out.println("\nCreated: " + outputFile.getCanonicalPath());
}
} catch (Exception e){
System.err.println("\nPlease check the following: " + e.getMessage());
} finally {
// shutdown the system
SystemManager.release();
}
}
}