|
| 1 | +# ConvertAPI Java Client |
| 2 | +## Convert your files with our online file conversion API |
| 3 | + |
| 4 | +The ConvertAPI helps converting various file formats. |
| 5 | +Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages or raw HTML codes. |
| 6 | +Merge, Encrypt, Split, Repair and Decrypt PDF files. |
| 7 | +And many others files manipulations. |
| 8 | +In just few minutes you can integrate it into your application and use it easily. |
| 9 | + |
| 10 | +The ConvertAPI-Java library makes it easier to use the Convert API from your Java 8 projects without having to build your own API calls. |
| 11 | +You can get your free API secret at https://www.convertapi.com/a |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +Download [latest JAR file](https://www.convertapi.com) and place it in your project library directory. |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +### Configuration |
| 20 | + |
| 21 | +You can get your secret at https://www.convertapi.com/a |
| 22 | + |
| 23 | +```java |
| 24 | +Config.setDefaultSecret("YOUR API SECRET"); |
| 25 | +``` |
| 26 | + |
| 27 | +### File conversion |
| 28 | + |
| 29 | +Example to convert file to PDF. All supported formats and options can be found |
| 30 | +[here](https://www.convertapi.com). |
| 31 | + |
| 32 | +```java |
| 33 | +CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf", new Param[]{ |
| 34 | + new Param("file", Paths.get("test-files/test.docx")) |
| 35 | +}); |
| 36 | + |
| 37 | +// save to file |
| 38 | +result.get().saveFile(Paths.get("/tmp/my_file.pdf")); |
| 39 | +``` |
| 40 | + |
| 41 | +Other result operations: |
| 42 | + |
| 43 | +```java |
| 44 | +// save all result files to folder |
| 45 | +result.get().saveFiles(Paths.get("/tmp")); |
| 46 | + |
| 47 | +// get result file |
| 48 | +ConversionResultFile file = result.get().getFile(0); |
| 49 | + |
| 50 | +// get conversion cost |
| 51 | +Integer cost = result.get().conversionCost(); |
| 52 | +``` |
| 53 | + |
| 54 | +#### Convert file url |
| 55 | + |
| 56 | +```java |
| 57 | +CompletableFuture<ConversionResult> result = ConvertApi.convert("pptx", "pdf", new Param[]{ |
| 58 | + new Param("file", "https://cdn.convertapi.com/cara/testfiles/presentation.pptx") |
| 59 | +}); |
| 60 | +``` |
| 61 | + |
| 62 | +#### Additional conversion parameters |
| 63 | + |
| 64 | +ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion |
| 65 | +parameters and explanations can be found [here](https://www.convertapi.com). |
| 66 | + |
| 67 | +```java |
| 68 | +CompletableFuture<ConversionResult> result = ConvertApi.convert("pdf", "jpg", new Param[]{ |
| 69 | + new Param("file", Paths.get("test-files/test.pdf")), |
| 70 | + new Param("scaleimage", "true"), |
| 71 | + new Param("scaleproportions", "true"), |
| 72 | + new Param("imageheight", 300) |
| 73 | +}); |
| 74 | +``` |
| 75 | + |
| 76 | +### User information |
| 77 | + |
| 78 | +You can always check remaining seconds amount by fetching [user information](https://www.convertapi.com/doc/user). |
| 79 | + |
| 80 | +```java |
| 81 | +User user = ConvertApi.getUser(); |
| 82 | +int secondsLeft = user.SecondsLeft; |
| 83 | +``` |
| 84 | + |
| 85 | +### More examples |
| 86 | + |
| 87 | +You can find more advanced examples in the [examples](https://github.com/ConvertAPI/convertapi-java/tree/master/src/main/java/com/convertapi/examples) folder. |
| 88 | + |
| 89 | +#### Converting your first file, full example: |
| 90 | + |
| 91 | +ConvertAPI is designed to make converting file super easy, the following snippet shows how easy it is to get started. Let's convert WORD DOCX file to PDF: |
| 92 | + |
| 93 | +```java |
| 94 | +package com.convertapi.examples; |
| 95 | + |
| 96 | +import com.convertapi.ConvertApi; |
| 97 | + |
| 98 | +public class SimpleConversion { |
| 99 | + public static void main(String[] args) { |
| 100 | + ConvertApi.convert("test-files/test.docx", "result.pdf", "YOUR API SECRET"); |
| 101 | + } |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +This is the bare-minimum to convert a file using the ConvertAPI client, but you can do a great deal more with the ConvertAPI Java library. |
| 106 | +Take special note that you should replace `YOUR API SECRET` with the secret you obtained in item two of the pre-requisites. |
| 107 | + |
| 108 | +### Issues & Comments |
| 109 | +Please leave all comments, bugs, requests, and issues on the Issues page. We'll respond to your request ASAP! |
| 110 | + |
| 111 | +### License |
| 112 | +The ConvertAPI Java Library is licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php "Read more about the MIT license form") license. |
| 113 | +Refere to the [LICENSE](https://github.com/ConvertAPI/convertapi-java/blob/master/LICENSE) file for more information. |
0 commit comments