1+ package com .convertapi .examples ;
2+
3+ import com .convertapi .Config ;
4+ import com .convertapi .ConversionResult ;
5+ import com .convertapi .ConvertApi ;
6+ import com .convertapi .Param ;
7+
8+ import java .io .IOException ;
9+ import java .nio .file .Path ;
10+ import java .nio .file .Paths ;
11+ import java .util .List ;
12+ import java .util .concurrent .CompletableFuture ;
13+ import java .util .concurrent .ExecutionException ;
14+
15+ import static java .lang .System .getenv ;
16+
17+ /**
18+ * Example of saving Word docx to PDF using alternative OpenOffice converter
19+ * Conversion is made by using same file parameter and processing two conversions simultaneously
20+ * https://www.convertapi.com/docx-to-pdf
21+ * https://www.convertapi.com/docx-to-png
22+ */
23+
24+ public class AlternativeConverter {
25+ public static void main (String [] args ) throws IOException , ExecutionException , InterruptedException {
26+ Config .setDefaultSecret (getenv ("CONVERTAPI_SECRET" )); //Get your secret at https://www.convertapi.com/a
27+ Path tempDir = Paths .get (System .getProperty ("java.io.tmpdir" ));
28+
29+ System .out .println ("Converting DOCX to PDF with OpenOffice converter" );
30+
31+ Param docxFileParam = new Param ("file" , Paths .get ("test-files/test.docx" ));
32+ Param converterParam = new Param ("converter" , "openofficetopdf" );
33+
34+ CompletableFuture <ConversionResult > pdfResult = ConvertApi .convert ("docx" , "pdf" , docxFileParam , converterParam );
35+
36+ System .out .println ("PDF file saved to: " + pdfResult .get ().saveFile (tempDir ).get ());
37+ }
38+ }
0 commit comments