· 9 years ago · Jan 19, 2017, 09:56 AM
1public class Main {
2 public static final String TEST_BUCKET = "";
3 public static final String ACCESS_KEY = "";
4 public static final String SECRET_KEY = "";
5
6 public static void main(String[] args) throws Exception {
7
8
9 com.groupdocs.viewer.licensing.License lic = new com.groupdocs.viewer.licensing.License();
10 lic.setLicense("D:/GroupDocs.Total.Java.lic");
11
12 Program program = new Program(".docx"); // Input file extensions
13 program.execute("files/", ".html", new Program.IDoIt() { // Output file extension
14 public void doIt(String inPath, String baseOutPath, String extension, String outPath, int fileIndex) throws Exception {
15
16 final String guid = new File(inPath).getName();
17
18 ViewerConfig config = new ViewerConfig();
19 config.setStoragePath(new File(inPath).getParentFile().getAbsolutePath());
20 config.setUseCache(true);
21
22 // Create html handler
23 final AmazonS3Client amazonS3Client = new AmazonS3Client(new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY));
24
25 createBucket(amazonS3Client, inPath);
26
27 ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config, null, new S3CacheHandler(amazonS3Client), new S3DataStore(amazonS3Client));
28
29 List<PageHtml> pages = htmlHandler.getPages(guid);
30
31 for (PageHtml page : pages) {
32 FileUtils.writeStringToFile(new File(outPath), page.getHtmlContent(), Charset.forName("UTF-8"));
33 }
34 }
35 });
36 }
37
38
39 private static void createBucket(AmazonS3Client amazonS3Client, String inPath) {
40 final List<Bucket> buckets = amazonS3Client.listBuckets();
41 for (Bucket bucket : buckets) {
42 if (TEST_BUCKET.equals(bucket.getName())) {
43 return;
44 }
45 }
46 final Bucket bucket = amazonS3Client.createBucket(TEST_BUCKET);
47 if (bucket != null) {
48 amazonS3Client.putObject(new PutObjectRequest(TEST_BUCKET, ACCESS_KEY, new File(inPath)));
49 }
50 }
51}