Skip to content

Commit aea0813

Browse files
committed
Simplify examples
1 parent bbbaebc commit aea0813

File tree

13 files changed

+48
-53
lines changed

13 files changed

+48
-53
lines changed

examples/files/test.docx

32 KB
Binary file not shown.

examples/files/test.pdf

1.04 MB
Binary file not shown.

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<build>
2323
<resources>
2424
<resource>
25-
<directory>src/main/resources</directory>
25+
<directory>files</directory>
2626
<includes>
2727
<include>test.docx</include>
2828
<include>test.pdf</include>

examples/src/main/java/com/convertapi/examples/Advanced.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.convertapi.client.ConvertApi;
66
import com.convertapi.client.Param;
77

8-
import java.io.IOException;
98
import java.net.InetSocketAddress;
109
import java.net.Proxy;
1110
import java.nio.file.Path;
@@ -21,7 +20,7 @@
2120
*/
2221
public class Advanced {
2322

24-
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
23+
public static void main(String[] args) throws ExecutionException, InterruptedException {
2524
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
2625

2726
// Advanced HTTP client setup

examples/src/main/java/com/convertapi/examples/AlternativeConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.convertapi.client.ConvertApi;
66
import com.convertapi.client.Param;
77

8-
import java.io.File;
98
import java.io.IOException;
109
import java.nio.file.Path;
1110
import java.nio.file.Paths;
@@ -21,12 +20,13 @@
2120
* https://www.convertapi.com/docx-to-png
2221
*/
2322
public class AlternativeConverter {
23+
2424
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
2525
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
2626
Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
2727

2828
System.out.println("Converting DOCX to PDF with OpenOffice converter");
29-
Param docxFileParam = new Param("file", new File(AlternativeConverter.class.getClassLoader().getResource("test.docx").getFile()).toPath());
29+
Param docxFileParam = new Param("file", Paths.get("files/test.docx"));
3030
Param converterParam = new Param("converter", "openoffice");
3131

3232
CompletableFuture<ConversionResult> pdfResult = ConvertApi.convert("docx", "pdf", docxFileParam, converterParam);

examples/src/main/java/com/convertapi/examples/ConversionChaining.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.convertapi.client.ConvertApi;
66
import com.convertapi.client.Param;
77

8-
import java.io.File;
98
import java.io.IOException;
109
import java.nio.file.Path;
1110
import java.nio.file.Paths;
@@ -15,16 +14,17 @@
1514
import static java.lang.System.getenv;
1615

1716
/**
18-
* Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed
17+
* Short example of conversions chaining, the PDF pages extracted and saved as
18+
* separated JPGs and then ZIP'ed
1919
* https://www.convertapi.com/doc/chaining
2020
*/
21-
2221
public class ConversionChaining {
22+
2323
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
2424
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
2525

2626
System.out.println("Converting PDF to JPG and compressing result files with ZIP");
27-
CompletableFuture<ConversionResult> jpgResult = ConvertApi.convert("docx", "jpg", new Param("file", new File(AlternativeConverter.class.getClassLoader().getResource("test.docx").getFile()).toPath()));
27+
CompletableFuture<ConversionResult> jpgResult = ConvertApi.convert("docx", "jpg", new Param("file", Paths.get("files/test.docx")));
2828
System.out.println("ConvertApi.convert is not blocking method, proceeding to ZIP conversion");
2929

3030
CompletableFuture<ConversionResult> zipResult = ConvertApi.convert("jpg", "zip", new Param("files", jpgResult));
@@ -38,4 +38,4 @@ public static void main(String[] args) throws IOException, ExecutionException, I
3838
System.out.println("JPG -> ZIP conversion cost: " + zipResult.get().conversionCost());
3939
System.out.println("ZIP file saved to: " + path.get().toString());
4040
}
41-
}
41+
}

examples/src/main/java/com/convertapi/examples/ConvertRemoteFile.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
import static java.lang.System.getenv;
1515

1616
/**
17-
* Example of conversion remote file. Converting file must be accessible from the internet.
17+
* Example of conversion remote file. Converting file must be accessible from
18+
* the internet.
1819
*/
19-
2020
public class ConvertRemoteFile {
21-
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
21+
22+
public static void main(String[] args) throws ExecutionException, InterruptedException {
2223
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
2324

2425
System.out.println("Converting remote PPTX to PDF");
2526
CompletableFuture<ConversionResult> result = ConvertApi.convert("pptx", "pdf",
26-
new Param("file", "https://cdn.convertapi.com/cara/testfiles/presentation.pptx")
27+
new Param("file", "https://cdn.convertapi.com/cara/testfiles/presentation.pptx")
2728
);
2829

2930
Path pdfFile = Paths.get(System.getProperty("java.io.tmpdir") + "/myfile.pdf");
3031
result.get().saveFile(pdfFile).get();
3132

3233
System.out.println("PDF file saved to: " + pdfFile.toString());
3334
}
34-
}
35+
}

examples/src/main/java/com/convertapi/examples/ConvertWebToPdf.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
/**
1717
* Example of converting Web Page URL to PDF file
1818
* https://www.convertapi.com/web-to-pdf
19-
*/
20-
19+
*/
2120
public class ConvertWebToPdf {
22-
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
21+
22+
public static void main(String[] args) throws ExecutionException, InterruptedException {
2323
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
2424

2525
System.out.println("Converting WEB to PDF");
2626
CompletableFuture<ConversionResult> result = ConvertApi.convert("web", "pdf",
27-
new Param("url", "https://en.wikipedia.org/wiki/Data_conversion"),
28-
new Param("filename", "web-example")
27+
new Param("url", "https://en.wikipedia.org/wiki/Data_conversion"),
28+
new Param("filename", "web-example")
2929
);
3030

3131
Path tmpDir = Paths.get(System.getProperty("java.io.tmpdir"));
3232
CompletableFuture<Path> pdfFile = result.get().saveFile(tmpDir);
3333

3434
System.out.println("PDF file saved to: " + pdfFile.get().toString());
3535
}
36-
}
36+
}

examples/src/main/java/com/convertapi/examples/ConvertWordToPdfAndPng.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.convertapi.client.ConvertApi;
66
import com.convertapi.client.Param;
77

8-
import java.io.File;
98
import java.io.IOException;
109
import java.nio.file.Path;
1110
import java.nio.file.Paths;
@@ -21,24 +20,24 @@
2120
* https://www.convertapi.com/docx-to-pdf
2221
* https://www.convertapi.com/docx-to-png
2322
*/
24-
2523
public class ConvertWordToPdfAndPng {
24+
2625
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
2726
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
2827
Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
2928

3029
System.out.println("Converting DOCX to PDF and JPG in parallel");
3130

32-
Param docxFileParam = new Param("file", new File(AlternativeConverter.class.getClassLoader().getResource("test.docx").getFile()).toPath());
31+
Param docxFileParam = new Param("file", Paths.get("files/test.docx"));
3332

3433
CompletableFuture<ConversionResult> pdfResult = ConvertApi.convert("docx", "pdf", docxFileParam);
3534
CompletableFuture<ConversionResult> jpgResult = ConvertApi.convert("docx", "jpg", docxFileParam);
3635

3736
System.out.println("PDF file saved to: " + pdfResult.get().saveFile(tempDir).get());
3837

3938
List<CompletableFuture<Path>> jpgPaths = jpgResult.get().saveFiles(tempDir);
40-
for (CompletableFuture<Path> path: jpgPaths) {
39+
for (CompletableFuture<Path> path : jpgPaths) {
4140
System.out.println("JPG file saved to: " + path.get().toString());
4241
}
4342
}
44-
}
43+
}

examples/src/main/java/com/convertapi/examples/CreatePdfThumbnail.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.convertapi.client.ConvertApi;
66
import com.convertapi.client.Param;
77

8-
import java.io.File;
98
import java.io.IOException;
109
import java.nio.file.Path;
1110
import java.nio.file.Paths;
@@ -19,26 +18,26 @@
1918
* https://www.convertapi.com/pdf-to-extract
2019
* https://www.convertapi.com/pdf-to-jpg
2120
*/
22-
2321
public class CreatePdfThumbnail {
22+
2423
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
25-
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
24+
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
2625
Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
2726

2827
System.out.println("Creating PDF thumbnail");
2928

3029
CompletableFuture<ConversionResult> pdfFirstPageResult = ConvertApi.convert("pdf", "extract",
31-
new Param("file", new File(AlternativeConverter.class.getClassLoader().getResource("test.pdf").getFile()).toPath()),
32-
new Param("pagerange", "1")
30+
new Param("file", Paths.get("files/test.pdf")),
31+
new Param("pagerange", "1")
3332
);
3433

3534
CompletableFuture<ConversionResult> thumbnailResult = ConvertApi.convert("pdf", "jpg",
36-
new Param("file", pdfFirstPageResult),
37-
new Param("scaleimage", "true"),
38-
new Param("scaleproportions", "true"),
39-
new Param("imageheight", 300)
35+
new Param("file", pdfFirstPageResult),
36+
new Param("scaleimage", "true"),
37+
new Param("scaleproportions", "true"),
38+
new Param("imageheight", 300)
4039
);
4140

4241
System.out.println("JPG thumbnail file saved to: " + thumbnailResult.get().saveFile(tempDir).get());
4342
}
44-
}
43+
}

0 commit comments

Comments
 (0)