Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<directory>files</directory>
<includes>
<include>test.docx</include>
<include>test.pdf</include>
Expand Down
3 changes: 1 addition & 2 deletions examples/src/main/java/com/convertapi/examples/Advanced.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.convertapi.client.ConvertApi;
import com.convertapi.client.Param;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.nio.file.Path;
Expand All @@ -21,7 +20,7 @@
*/
public class Advanced {

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

// Advanced HTTP client setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.convertapi.client.ConvertApi;
import com.convertapi.client.Param;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -20,18 +19,18 @@
* https://www.convertapi.com/docx-to-pdf
* https://www.convertapi.com/docx-to-png
*/

public class AlternativeConverter {

public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));

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

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

System.out.println("PDF file saved to: " + pdfResult.get().saveFile(tempDir).get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.convertapi.client.ConvertApi;
import com.convertapi.client.Param;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -15,16 +14,17 @@
import static java.lang.System.getenv;

/**
* Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed
* Short example of conversions chaining, the PDF pages extracted and saved as
* separated JPGs and then ZIP'ed
* https://www.convertapi.com/doc/chaining
*/

public class ConversionChaining {

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

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

CompletableFuture<ConversionResult> zipResult = ConvertApi.convert("jpg", "zip", new Param("files", jpgResult));
Expand All @@ -38,4 +38,4 @@ public static void main(String[] args) throws IOException, ExecutionException, I
System.out.println("JPG -> ZIP conversion cost: " + zipResult.get().conversionCost());
System.out.println("ZIP file saved to: " + path.get().toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
import static java.lang.System.getenv;

/**
* Example of conversion remote file. Converting file must be accessible from the internet.
* Example of conversion remote file. Converting file must be accessible from
* the internet.
*/

public class ConvertRemoteFile {
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {

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

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

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

System.out.println("PDF file saved to: " + pdfFile.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
/**
* Example of converting Web Page URL to PDF file
* https://www.convertapi.com/web-to-pdf
*/

*/
public class ConvertWebToPdf {
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {

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

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

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

System.out.println("PDF file saved to: " + pdfFile.get().toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.convertapi.client.ConvertApi;
import com.convertapi.client.Param;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -21,24 +20,24 @@
* https://www.convertapi.com/docx-to-pdf
* https://www.convertapi.com/docx-to-png
*/

public class ConvertWordToPdfAndPng {

public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));

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

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

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

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

List<CompletableFuture<Path>> jpgPaths = jpgResult.get().saveFiles(tempDir);
for (CompletableFuture<Path> path: jpgPaths) {
for (CompletableFuture<Path> path : jpgPaths) {
System.out.println("JPG file saved to: " + path.get().toString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.convertapi.client.ConvertApi;
import com.convertapi.client.Param;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -19,26 +18,26 @@
* https://www.convertapi.com/pdf-to-extract
* https://www.convertapi.com/pdf-to-jpg
*/

public class CreatePdfThumbnail {

public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));

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

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

CompletableFuture<ConversionResult> thumbnailResult = ConvertApi.convert("pdf", "jpg",
new Param("file", pdfFirstPageResult),
new Param("scaleimage", "true"),
new Param("scaleproportions", "true"),
new Param("imageheight", 300)
new Param("file", pdfFirstPageResult),
new Param("scaleimage", "true"),
new Param("scaleproportions", "true"),
new Param("imageheight", 300)
);

System.out.println("JPG thumbnail file saved to: " + thumbnailResult.get().saveFile(tempDir).get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import com.convertapi.client.Config;
import com.convertapi.client.ConvertApi;

import java.io.File;
import java.io.IOException;
import static java.lang.System.getenv;

/**
* Most simple conversion example
*/
public class SimpleConversion {
public static void main(String[] args) throws IOException {
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET"));
String resourcePath = new File(AlternativeConverter.class.getClassLoader().getResource("test.docx").getFile()).getCanonicalPath();

public static void main(String[] args) {
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
String resourcePath = "files/test.docx";
String tmpDir = System.getProperty("java.io.tmpdir") + "/";

// Simplified file to file conversion example
ConvertApi.convertFile(resourcePath, tmpDir + "/result.pdf");

System.out.println("PDF file saved to: " + tmpDir + "result.pdf");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.convertapi.client.ConversionResult;
import com.convertapi.client.ConvertApi;
import com.convertapi.client.Param;
import java.io.File;

import java.io.IOException;
import java.nio.file.Path;
Expand All @@ -19,23 +18,23 @@
* https://www.convertapi.com/pdf-to-extract
* https://www.convertapi.com/pdf-to-merge
*/

public class SplitAndMergePdf {

public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));

System.out.println("Creating PDF with the first and the last pages");

CompletableFuture<ConversionResult> splitResult = ConvertApi.convert("pdf", "split",
new Param("file", new File(AlternativeConverter.class.getClassLoader().getResource("test.pdf").getFile()).toPath())
new Param("file", Paths.get("files/test.pdf"))
);

CompletableFuture<ConversionResult> mergeResult = ConvertApi.convert("pdf", "merge",
new Param("files", splitResult, 0),
new Param("files", splitResult, -1)
new Param("files", splitResult, 0),
new Param("files", splitResult, -1)
);

System.out.println("PDF file saved to: " + mergeResult.get().saveFile(tempDir).get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
import com.convertapi.client.ConvertApi;
import com.convertapi.client.model.User;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import static java.lang.System.getenv;

/**
* Retrieve user information
* https://www.convertapi.com/doc/user
*/

public class UserInformation {
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {

public static void main(String[] args) {
Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a
User user = ConvertApi.getUser();

Expand All @@ -27,4 +24,4 @@ public static void main(String[] args) throws IOException, ExecutionException, I
System.out.println("Active: " + user.Active);
System.out.println("Seconds left: " + user.SecondsLeft);
}
}
}