Add support for large PDF templates.
Showing
1 changed file
with
13 additions
and
4 deletions
... | @@ -35,16 +35,25 @@ public class LibreOfficeRenderer { | ... | @@ -35,16 +35,25 @@ public class LibreOfficeRenderer { |
35 | context.put("Linux_X86_64", "$Linux_X86_64"); | 35 | context.put("Linux_X86_64", "$Linux_X86_64"); |
36 | context.put("Build", "$Build"); | 36 | context.put("Build", "$Build"); |
37 | 37 | ||
38 | SimpleTemplateEngine engine = new SimpleTemplateEngine(); | 38 | String output = ""; |
39 | Writable stTemplate = engine.createTemplate(template).make(context); | 39 | int idx = 0; |
40 | String output = stTemplate.toString(); | 40 | |
41 | while (idx < template.length()) { | ||
42 | int remaining = template.length() - idx; | ||
43 | int chunkLength = remaining < 64000 ? remaining : 64000; | ||
44 | String tmplChunk = template.substring(idx, idx + chunkLength); | ||
45 | SimpleTemplateEngine engine = new SimpleTemplateEngine(); | ||
46 | Writable stTemplate = engine.createTemplate(tmplChunk).make(context); | ||
47 | output += stTemplate.toString(); | ||
48 | idx += chunkLength; | ||
49 | } | ||
41 | 50 | ||
42 | File outputFile = File.createTempFile("bfdcs-", "-tmpl"); | 51 | File outputFile = File.createTempFile("bfdcs-", "-tmpl"); |
43 | UtilIO.writeString(outputFile, output); | 52 | UtilIO.writeString(outputFile, output); |
44 | 53 | ||
45 | List<String> args = Arrays.asList(new String[]{"libreoffice", "--headless", "--convert-to", "pdf", outputFile.getPath(), "--outdir", "/tmp"}); | 54 | List<String> args = Arrays.asList(new String[]{"libreoffice", "--headless", "--convert-to", "pdf", outputFile.getPath(), "--outdir", "/tmp"}); |
46 | ProcessBuilder pb = new ProcessBuilder(args); | 55 | ProcessBuilder pb = new ProcessBuilder(args); |
47 | Map env = pb.environment(); | 56 | Map<String, String> env = pb.environment(); |
48 | env.put("HOME", "/home/ofbiz"); | 57 | env.put("HOME", "/home/ofbiz"); |
49 | env.put("USERNAME", "ofbiz"); | 58 | env.put("USERNAME", "ofbiz"); |
50 | Process process = pb.start(); | 59 | Process process = pb.start(); | ... | ... |
-
Please register or sign in to post a comment