Skip to content

Commit c62e068

Browse files
authored
Merge branch 'master' into master
2 parents d4ea74c + 4582c38 commit c62e068

File tree

15 files changed

+297
-243
lines changed

15 files changed

+297
-243
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
2-
out
2+
out
3+
/target/

GETTING-STARTED.md

Lines changed: 0 additions & 161 deletions
This file was deleted.

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Add the following dependency to your pom.xml:
1919
<dependency>
2020
<groupId>com.convertapi.client</groupId>
2121
<artifactId>convertapi</artifactId>
22-
<version>2.5</version>
22+
<version>2.9</version>
2323
</dependency>
2424
```
2525

@@ -36,7 +36,7 @@ Config.setDefaultSecret("your-api-secret");
3636
### File conversion
3737

3838
Example to convert DOCX file to PDF. All supported formats and options can be found
39-
[here](https://www.convertapi.com).
39+
[here](https://www.convertapi.com/conversions).
4040

4141
```java
4242
CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf", new Param("file", Paths.get("test.docx")));
@@ -69,7 +69,7 @@ CompletableFuture<ConversionResult> result = ConvertApi.convert("pptx", "pdf",
6969
#### Additional conversion parameters
7070

7171
ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion
72-
parameters and explanations can be found [here](https://www.convertapi.com).
72+
parameters and explanations can be found [here](https://www.convertapi.com/conversions).
7373

7474
```java
7575
CompletableFuture<ConversionResult> result = ConvertApi.convert("pdf", "jpg",
@@ -89,6 +89,14 @@ User user = ConvertApi.getUser();
8989
int secondsLeft = user.SecondsLeft;
9090
```
9191

92+
### Alternative domain
93+
94+
Create `Config` instance with the alternative domain and provide it in `convert` method. Dedicated to the region [domain list](https://www.convertapi.com/doc/servers-location).
95+
96+
```java
97+
Config config = new Config(secret, "https", "eu-v2.convertapi.com", 0, httpClientBuilder);
98+
```
99+
92100
### More examples
93101

94102
You can find more advanced examples in the [examples](https://github.com/ConvertAPI/convertapi-java/tree/master/examples/src/main/java/com/convertapi/examples) folder.

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
@@ -15,7 +15,7 @@
1515
<dependency>
1616
<groupId>com.convertapi.client</groupId>
1717
<artifactId>convertapi</artifactId>
18-
<version>2.4</version>
18+
<version>2.9</version>
1919
</dependency>
2020
</dependencies>
2121

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.convertapi.examples;
2+
3+
import com.convertapi.client.Config;
4+
import com.convertapi.client.ConversionResult;
5+
import com.convertapi.client.ConvertApi;
6+
import com.convertapi.client.Param;
7+
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.io.InputStream;
11+
import java.nio.file.Files;
12+
import java.nio.file.Path;
13+
import java.nio.file.Paths;
14+
import java.util.concurrent.CompletableFuture;
15+
import java.util.concurrent.ExecutionException;
16+
17+
import static java.lang.System.getenv;
18+
19+
/**
20+
* Example of the file conversion when data is passed as a stream.
21+
*/
22+
public class ConvertStream {
23+
24+
public static void main(String[] args) throws ExecutionException, InterruptedException, IOException {
25+
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
26+
27+
// Creating file data stream
28+
InputStream stream = Files.newInputStream(new File("src/main/resources/test.docx").toPath());
29+
30+
System.out.println("Converting stream of DOCX data to PDF");
31+
CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf",
32+
new Param("file", stream, "test.docx")
33+
);
34+
35+
Path pdfFile = Paths.get(System.getProperty("java.io.tmpdir") + "/myfile.pdf");
36+
result.get().saveFile(pdfFile).get();
37+
38+
System.out.println("PDF file saved to: " + pdfFile.toString());
39+
}
40+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.convertapi.examples;
2+
3+
import com.convertapi.client.Config;
4+
import com.convertapi.client.ConvertApi;
5+
6+
import static java.lang.System.getenv;
7+
8+
/**
9+
* Most simple conversion example with token authentication
10+
*/
11+
public class TokenAuthentication {
12+
13+
public static void main(String[] args) {
14+
Config.setDefaultToken(getenv("CONVERTAPI_TOKEN")); // Generate your token: https://www.convertapi.com/doc/auth
15+
Config.setDefaultApiKey(getenv("CONVERTAPI_APIKEY")); // Get your api key: https://www.convertapi.com/a
16+
String resourcePath = "files/test.docx";
17+
String tmpDir = System.getProperty("java.io.tmpdir") + "/";
18+
19+
// Simplified file to file conversion example
20+
ConvertApi.convertFile(resourcePath, tmpDir + "/result.pdf");
21+
22+
System.out.println("PDF file saved to: " + tmpDir + "result.pdf");
23+
}
24+
}

pom.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<artifactId>convertapi</artifactId>
55
<packaging>jar</packaging>
66

7-
<version>2.7-SNAPSHOT</version>
7+
<version>2.10-SNAPSHOT</version>
88
<name>ConvertAPI Java Client</name>
99
<description>
1010
The ConvertAPI helps converting various file formats.
@@ -71,12 +71,12 @@
7171
<dependency>
7272
<groupId>com.google.code.gson</groupId>
7373
<artifactId>gson</artifactId>
74-
<version>2.8.5</version>
74+
<version>2.8.9</version>
7575
</dependency>
7676
<dependency>
7777
<groupId>com.squareup.okhttp3</groupId>
7878
<artifactId>okhttp</artifactId>
79-
<version>3.10.0</version>
79+
<version>4.9.2</version>
8080
</dependency>
8181
</dependencies>
8282

@@ -92,6 +92,19 @@
9292
</resources>
9393

9494
<plugins>
95+
<plugin>
96+
<groupId>org.apache.maven.plugins</groupId>
97+
<artifactId>maven-jar-plugin</artifactId>
98+
<version>2.1</version>
99+
<configuration>
100+
<archive>
101+
<manifest>
102+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
103+
</manifest>
104+
</archive>
105+
</configuration>
106+
</plugin>
107+
95108
<plugin>
96109
<artifactId>maven-deploy-plugin</artifactId>
97110
<version>2.8.2</version>

0 commit comments

Comments
 (0)