diff --git a/examples/src/main/resources/test.docx b/examples/files/test.docx similarity index 100% rename from examples/src/main/resources/test.docx rename to examples/files/test.docx diff --git a/examples/src/main/resources/test.pdf b/examples/files/test.pdf similarity index 100% rename from examples/src/main/resources/test.pdf rename to examples/files/test.pdf diff --git a/examples/pom.xml b/examples/pom.xml index 14a6b8c..3dbf358 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -22,7 +22,7 @@ - src/main/resources + files test.docx test.pdf diff --git a/examples/src/main/java/com/convertapi/examples/Advanced.java b/examples/src/main/java/com/convertapi/examples/Advanced.java index e4f06d2..fee55d1 100644 --- a/examples/src/main/java/com/convertapi/examples/Advanced.java +++ b/examples/src/main/java/com/convertapi/examples/Advanced.java @@ -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; @@ -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 diff --git a/examples/src/main/java/com/convertapi/examples/AlternativeConverter.java b/examples/src/main/java/com/convertapi/examples/AlternativeConverter.java index 0ce2dde..625ac43 100644 --- a/examples/src/main/java/com/convertapi/examples/AlternativeConverter.java +++ b/examples/src/main/java/com/convertapi/examples/AlternativeConverter.java @@ -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; @@ -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 pdfResult = ConvertApi.convert("docx", "pdf", docxFileParam, converterParam); System.out.println("PDF file saved to: " + pdfResult.get().saveFile(tempDir).get()); } -} \ No newline at end of file +} diff --git a/examples/src/main/java/com/convertapi/examples/ConversionChaining.java b/examples/src/main/java/com/convertapi/examples/ConversionChaining.java index 7e21d96..33aa2c2 100644 --- a/examples/src/main/java/com/convertapi/examples/ConversionChaining.java +++ b/examples/src/main/java/com/convertapi/examples/ConversionChaining.java @@ -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; @@ -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 jpgResult = ConvertApi.convert("docx", "jpg", new Param("file", new File(AlternativeConverter.class.getClassLoader().getResource("test.docx").getFile()).toPath())); + CompletableFuture 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 zipResult = ConvertApi.convert("jpg", "zip", new Param("files", jpgResult)); @@ -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()); } -} \ No newline at end of file +} diff --git a/examples/src/main/java/com/convertapi/examples/ConvertRemoteFile.java b/examples/src/main/java/com/convertapi/examples/ConvertRemoteFile.java index 32f2a63..ee5b52b 100644 --- a/examples/src/main/java/com/convertapi/examples/ConvertRemoteFile.java +++ b/examples/src/main/java/com/convertapi/examples/ConvertRemoteFile.java @@ -14,16 +14,17 @@ 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 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"); @@ -31,4 +32,4 @@ public static void main(String[] args) throws IOException, ExecutionException, I System.out.println("PDF file saved to: " + pdfFile.toString()); } -} \ No newline at end of file +} diff --git a/examples/src/main/java/com/convertapi/examples/ConvertWebToPdf.java b/examples/src/main/java/com/convertapi/examples/ConvertWebToPdf.java index 1646e2f..681c941 100644 --- a/examples/src/main/java/com/convertapi/examples/ConvertWebToPdf.java +++ b/examples/src/main/java/com/convertapi/examples/ConvertWebToPdf.java @@ -16,16 +16,16 @@ /** * 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 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")); @@ -33,4 +33,4 @@ public static void main(String[] args) throws IOException, ExecutionException, I System.out.println("PDF file saved to: " + pdfFile.get().toString()); } -} \ No newline at end of file +} diff --git a/examples/src/main/java/com/convertapi/examples/ConvertWordToPdfAndPng.java b/examples/src/main/java/com/convertapi/examples/ConvertWordToPdfAndPng.java index 03feaf2..c49f7ab 100644 --- a/examples/src/main/java/com/convertapi/examples/ConvertWordToPdfAndPng.java +++ b/examples/src/main/java/com/convertapi/examples/ConvertWordToPdfAndPng.java @@ -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; @@ -21,15 +20,15 @@ * 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 pdfResult = ConvertApi.convert("docx", "pdf", docxFileParam); CompletableFuture jpgResult = ConvertApi.convert("docx", "jpg", docxFileParam); @@ -37,8 +36,8 @@ public static void main(String[] args) throws IOException, ExecutionException, I System.out.println("PDF file saved to: " + pdfResult.get().saveFile(tempDir).get()); List> jpgPaths = jpgResult.get().saveFiles(tempDir); - for (CompletableFuture path: jpgPaths) { + for (CompletableFuture path : jpgPaths) { System.out.println("JPG file saved to: " + path.get().toString()); } } -} \ No newline at end of file +} diff --git a/examples/src/main/java/com/convertapi/examples/CreatePdfThumbnail.java b/examples/src/main/java/com/convertapi/examples/CreatePdfThumbnail.java index c4c5b70..c5faeef 100644 --- a/examples/src/main/java/com/convertapi/examples/CreatePdfThumbnail.java +++ b/examples/src/main/java/com/convertapi/examples/CreatePdfThumbnail.java @@ -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; @@ -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 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 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()); } -} \ No newline at end of file +} diff --git a/examples/src/main/java/com/convertapi/examples/SimpleConversion.java b/examples/src/main/java/com/convertapi/examples/SimpleConversion.java index 65d272f..8a378ac 100644 --- a/examples/src/main/java/com/convertapi/examples/SimpleConversion.java +++ b/examples/src/main/java/com/convertapi/examples/SimpleConversion.java @@ -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"); } } diff --git a/examples/src/main/java/com/convertapi/examples/SplitAndMergePdf.java b/examples/src/main/java/com/convertapi/examples/SplitAndMergePdf.java index 77af049..716fa66 100644 --- a/examples/src/main/java/com/convertapi/examples/SplitAndMergePdf.java +++ b/examples/src/main/java/com/convertapi/examples/SplitAndMergePdf.java @@ -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; @@ -19,8 +18,8 @@ * 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")); @@ -28,14 +27,14 @@ public static void main(String[] args) throws IOException, ExecutionException, I System.out.println("Creating PDF with the first and the last pages"); CompletableFuture 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 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()); } -} \ No newline at end of file +} diff --git a/examples/src/main/java/com/convertapi/examples/UserInformation.java b/examples/src/main/java/com/convertapi/examples/UserInformation.java index bbab7cd..96a0568 100644 --- a/examples/src/main/java/com/convertapi/examples/UserInformation.java +++ b/examples/src/main/java/com/convertapi/examples/UserInformation.java @@ -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(); @@ -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); } -} \ No newline at end of file +}