|
1 |
| -# compdfkit-pdf-api-java |
| 1 | +## compdfkit-pdf-api-java |
| 2 | + |
| 3 | +This is the compdfkit-pdf-api Java SDK for the [ComPDFKit](https://api.compdf.com/api/docs/introduction) API. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Add the following dependency to your pom.xml: |
| 8 | + |
| 9 | +``` |
| 10 | +<dependency> |
| 11 | + <groupId>com.compdfkit</groupId> |
| 12 | + <artifactId>compdfkit-pdf-api-java</artifactId> |
| 13 | + <version>1.0.0</version> |
| 14 | +</dependency> |
| 15 | +``` |
| 16 | + |
| 17 | +## Create API Client |
| 18 | + |
| 19 | +You can use your **publicKey** and **secretKey** to complete the authentication |
| 20 | + |
| 21 | +Project public Key :You can find the public key in [Management Panel](https://api-dashboard.compdf.com/api/keys). |
| 22 | + |
| 23 | +Project secret Key : You can find the secret Key in [Management Panel](https://api-dashboard.compdf.com/api/keys). |
| 24 | + |
| 25 | +```java |
| 26 | +ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>); |
| 27 | +``` |
| 28 | + |
| 29 | +## Create Task |
| 30 | + |
| 31 | +A task ID is automatically generated for you based on the type of PDF tool you choose. You can provide the callback notification URL. After the task processing is completed, we will notify you of the task result through the callback interface. You can perform other operations according to the task result, such as downloading the result file. |
| 32 | + |
| 33 | +```java |
| 34 | +// Create a client |
| 35 | +ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>); |
| 36 | + |
| 37 | +// Create an example of a PDF TO EXCEL task |
| 38 | +CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_EXCEL.getValue()); |
| 39 | + |
| 40 | +//Get a task id |
| 41 | +String jobId = result.getTaskId(); |
| 42 | +``` |
| 43 | + |
| 44 | +## Upload Files |
| 45 | + |
| 46 | +Upload the original file and bind the file to the task ID. The field parameter is used to pass the JSON string to set the processing parameters for the file. Each file will generate automatically a unique filekey. Please note that a maximum of five files can be uploaded for a task ID and no files can be uploaded for that task after it has started. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +```java |
| 51 | +// Create a client |
| 52 | +ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>); |
| 53 | + |
| 54 | +// Create a task |
| 55 | +// Create an example of a PDF TO EXCEL task |
| 56 | +CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_EXCEL.getValue()); |
| 57 | + |
| 58 | +// Get a task id |
| 59 | +String jobId = result.getTaskId(); |
| 60 | + |
| 61 | +// Upload files |
| 62 | + |
| 63 | +// 1.Setting the file parameters |
| 64 | + |
| 65 | +// The parameter field only sets the processing parameters for the currently supported functions. If no parameters are set, the default value is used. The JSON format and field explanation corresponding to different function types are shown in PDF file transfer tool guide. |
| 66 | +PDFToExcelParameter parameter = FileParameterFactory.getFileParameterByType(PDFToOfficeEnum.PDF_TO_EXCEL); |
| 67 | +parameter.setContentOptions("1"); |
| 68 | + |
| 69 | +// 2.Upload file |
| 70 | +client.uploadFile(<convertFile>, jobId); |
| 71 | +``` |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +## Execute the task |
| 76 | + |
| 77 | +After the file upload is completed, call this interface with the task ID to process file. |
| 78 | + |
| 79 | +```java |
| 80 | +// Create a client |
| 81 | +ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>); |
| 82 | + |
| 83 | +// Create a task |
| 84 | +// Create an example of a PDF TO EXCEL task |
| 85 | +CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_EXCEL.getValue()); |
| 86 | + |
| 87 | +// Get a task id |
| 88 | +String jobId = result.getTaskId(); |
| 89 | + |
| 90 | +// Upload files |
| 91 | + |
| 92 | +// 1.Setting the file parameters |
| 93 | + |
| 94 | +// The parameter field only sets the processing parameters for the currently supported functions. If no parameters are set, the default value is used. The JSON format and field explanation corresponding to different function types are shown in PDF file transfer tool guide. |
| 95 | +PDFToExcelParameter parameter = FileParameterFactory.getFileParameterByType(PDFToOfficeEnum.PDF_TO_EXCEL); |
| 96 | +parameter.setContentOptions("1"); |
| 97 | + |
| 98 | +// 2.Upload file |
| 99 | +client.uploadFile(<convertFile>, jobId); |
| 100 | + |
| 101 | +// execute Task |
| 102 | +client.executeTask(jobId); |
| 103 | +``` |
| 104 | + |
| 105 | +## Get TaskInfo |
| 106 | + |
| 107 | +Request task status and file-related metadata based on the task ID. |
| 108 | + |
| 109 | +```java |
| 110 | +// Create a client |
| 111 | +ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>); |
| 112 | + |
| 113 | +// Create a task |
| 114 | +// Create an example of a PDF TO EXCEL task |
| 115 | +CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_EXCEL.getValue()); |
| 116 | + |
| 117 | +// Get a task id |
| 118 | +String jobId = result.getTaskId(); |
| 119 | + |
| 120 | +// Upload files |
| 121 | + |
| 122 | +// 1.Setting the file parameters |
| 123 | + |
| 124 | +// The parameter field only sets the processing parameters for the currently supported functions. If no parameters are set, the default value is used. The JSON format and field explanation corresponding to different function types are shown in PDF file transfer tool guide. |
| 125 | +PDFToExcelParameter parameter = FileParameterFactory.getFileParameterByType(PDFToOfficeEnum.PDF_TO_EXCEL); |
| 126 | +parameter.setContentOptions("1"); |
| 127 | + |
| 128 | +// 2.Upload file |
| 129 | +client.uploadFile(<convertFile>, jobId); |
| 130 | + |
| 131 | +// execute Task |
| 132 | +client.executeTask(jobId); |
| 133 | + |
| 134 | +// query TaskInfo |
| 135 | +QueryTaskInfoResult taskInfo = client.queryTaskInfo(jobId) |
| 136 | +``` |
| 137 | + |
| 138 | +## Resources |
| 139 | + |
| 140 | +* [ComPDFKit API Documentation](https://api.compdf.com/api/docs/introduction) |
0 commit comments