Skip to content

Commit 4492165

Browse files
committed
update Version1.2.4
1 parent c42733a commit 4492165

File tree

102 files changed

+6243
-967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+6243
-967
lines changed

README.md

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ This is the compdfkit-pdf-api Java SDK for the [ComPDFKit](https://api.compdf.c
66

77
JAVA JDK 1.8 and later.
88

9-
Maven 3.6 and later.
10-
11-
Springboot 2.3.0.RELEASE and later.
9+
Maven.
1210

1311
## Installation
1412

@@ -18,20 +16,20 @@ Add the following dependency to your pom.xml:
1816
<dependency>
1917
<groupId>com.compdf</groupId>
2018
<artifactId>compdfkit-pdf-api-java</artifactId>
21-
<version>1.2.2</version>
19+
<version>1.2.4</version>
2220
</dependency>
2321
```
2422

2523
## Create API Client
2624

2725
You can use your **publicKey** and **secretKey** to complete the authentication
2826

29-
Project public Key You can find the public key in [Management Panel](https://api-dashboard.compdf.com/api/keys).
27+
Project public Key : You can find the public key in [Management Panel](https://api-dashboard.compdf.com/api/keys).
3028

31-
Project secret Key You can find the secret Key in [Management Panel](https://api-dashboard.compdf.com/api/keys).
29+
Project secret Key : You can find the secret Key in [Management Panel](https://api-dashboard.compdf.com/api/keys).
3230

3331
```java
34-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
32+
ComPDFKitClient client = new ComPDFKitClient(<publicKey>, <secretKey>);
3533
```
3634

3735
## Create Task
@@ -40,13 +38,14 @@ A task ID is automatically generated for you based on the type of PDF tool you c
4038

4139
```java
4240
// Create a client
43-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
41+
ComPDFKitClient client = new ComPDFKitClient(<publicKey>, <secretKey>);
4442

43+
// Create a task
4544
// Create an example of a PDF TO WORD task
46-
CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_WORD.getValue());
45+
CCreateTaskResult result = client.createTask(CPDFToOfficeEnum.PDF_TO_WORD.getValue());
4746

48-
//Get a task id
49-
String jobId = result.getTaskId();
47+
// Get a task id
48+
String taskId = result.getTaskId();
5049
```
5150

5251
## Upload Files
@@ -57,17 +56,17 @@ Upload the original file and bind the file to the task ID. The field parameter i
5756

5857
```java
5958
// Create a client
60-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
59+
ComPDFKitClient client = new ComPDFKitClient(<publicKey>, <secretKey>);
6160

6261
// Create a task
6362
// Create an example of a PDF TO WORD task
64-
CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_WORD.getValue());
63+
CCreateTaskResult result = client.createTask(CPDFToOfficeEnum.PDF_TO_WORD.getValue());
6564

6665
// Get a task id
67-
String jobId = result.getTaskId();
66+
String taskId = result.getTaskId();
6867

69-
// Upload file
70-
client.uploadFile(<convertFile>, jobId);
68+
// Upload files
69+
client.uploadFile(<convertFile>, taskId);
7170
```
7271

7372

@@ -78,20 +77,20 @@ After the file upload is completed, call this interface with the task ID to proc
7877

7978
```java
8079
// Create a client
81-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
80+
ComPDFKitClient client = new ComPDFKitClient(<publicKey>, <secretKey>);
8281

8382
// Create a task
84-
// Create an example of a PDF TO EXCEL task
85-
CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_WORD.getValue());
83+
// Create an example of a PDF TO WORD task
84+
CCreateTaskResult result = client.createTask(CPDFToOfficeEnum.PDF_TO_WORD.getValue());
8685

8786
// Get a task id
88-
String jobId = result.getTaskId();
87+
String taskId = result.getTaskId();
8988

9089
// Upload files
91-
client.uploadFile(<convertFile>, jobId);
90+
client.uploadFile(<convertFile>, taskId);
9291

9392
// execute Task
94-
client.executeTask(jobId);
93+
client.executeTask(taskId);
9594
```
9695

9796
## Get TaskInfo
@@ -100,23 +99,23 @@ Request task status and file-related metadata based on the task ID.
10099

101100
```java
102101
// Create a client
103-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
102+
ComPDFKitClient client = new ComPDFKitClient(<publicKey>, <secretKey>);
104103

105104
// Create a task
106105
// Create an example of a PDF TO WORD task
107-
CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_WORD.getValue());
106+
CCreateTaskResult result = client.createTask(CPDFToOfficeEnum.PDF_TO_WORD.getValue());
108107

109108
// Get a task id
110-
String jobId = result.getTaskId();
109+
String taskId = result.getTaskId();
111110

112111
// Upload files
113-
client.uploadFile(<convertFile>, jobId);
112+
client.uploadFile(<convertFile>, taskId);
114113

115114
// execute Task
116-
client.executeTask(jobId);
115+
client.executeTask(taskId);
117116

118117
// query TaskInfo
119-
QueryTaskInfoResult taskInfo = client.queryTaskInfo(jobId)
118+
CTaskInfoResult taskInfo = client.getTaskInfo(taskId);
120119
```
121120

122121
## Resources

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
5+
<packaging>pom</packaging>
56
<parent>
67
<groupId>org.springframework.boot</groupId>
78
<artifactId>spring-boot-starter-parent</artifactId>
@@ -43,7 +44,7 @@
4344

4445
<groupId>com.compdf</groupId>
4546
<artifactId>compdfkit-pdf-api-java</artifactId>
46-
<version>1.2.2</version>
47+
<version>0.0.1</version>
4748

4849
<name>compdfkit-pdf-api-java</name>
4950
<description>compdfkit-pdf-api-java</description>

sample/pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.3.0.RELEASE</version>
9+
<relativePath/>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>sample</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.compdf</groupId>
18+
<artifactId>compdfkit-pdf-api-java</artifactId>
19+
<version>0.0.1</version>
20+
</dependency>
21+
</dependencies>
22+
23+
</project>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
2+
//
3+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
4+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
5+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
6+
// This notice may not be removed from this file.
7+
8+
package cn.kdan.compdfkit;
9+
10+
11+
import cn.kdan.compdfkit.client.ComPDFKitClient;
12+
import cn.kdan.compdfkit.constant.ComPDFKitConstant;
13+
import cn.kdan.compdfkit.enums.CPDFServerEnum;
14+
import cn.kdan.compdfkit.param.CAddWatermarkParameter;
15+
import cn.kdan.compdfkit.param.CPageSplitParameter;
16+
import cn.kdan.compdfkit.pojo.comPdfKit.CCreateTaskResult;
17+
import cn.kdan.compdfkit.pojo.comPdfKit.CFileInfo;
18+
import cn.kdan.compdfkit.pojo.comPdfKit.CTaskInfoResult;
19+
import cn.kdan.compdfkit.pojo.comPdfKit.CUploadFileResult;
20+
21+
import java.io.File;
22+
import java.io.FileInputStream;
23+
import java.io.FileNotFoundException;
24+
import java.util.Arrays;
25+
import java.util.concurrent.Executors;
26+
import java.util.concurrent.ScheduledExecutorService;
27+
import java.util.concurrent.ScheduledFuture;
28+
import java.util.concurrent.TimeUnit;
29+
import java.util.concurrent.atomic.AtomicReference;
30+
31+
public class CAddWatermark {
32+
33+
private static final String publicKit = "";
34+
private static final String secretKey = "";
35+
private static final ComPDFKitClient comPDFKitClient = new ComPDFKitClient(publicKit,secretKey);
36+
37+
public static void main(String[] args) throws FileNotFoundException {
38+
CAddWatermark.addWatermark();
39+
}
40+
41+
public static void addWatermark() throws FileNotFoundException {
42+
// create Task
43+
CCreateTaskResult CCreateTaskResult = comPDFKitClient.createTask(CPDFServerEnum.ADD_WATERMARK);
44+
// taskId
45+
String taskId = CCreateTaskResult.getTaskId();
46+
// upload File
47+
File file = new File("sample/test.pdf");
48+
String filePassword = "";
49+
CAddWatermarkParameter fileParameter = new CAddWatermarkParameter();
50+
fileParameter.setType("text");
51+
fileParameter.setScale("1");
52+
fileParameter.setOpacity("0.5");
53+
fileParameter.setRotation("0.785");
54+
fileParameter.setTargetPages("1-2");
55+
fileParameter.setVertalign("center");
56+
fileParameter.setHorizalign("left");
57+
fileParameter.setXoffset("100");
58+
fileParameter.setYoffset("100");
59+
fileParameter.setContent("test");
60+
fileParameter.setTextColor("#59c5bb");
61+
fileParameter.setFullScreen("111");
62+
fileParameter.setHorizontalSpace("10");
63+
fileParameter.setVerticalSpace("10");
64+
CUploadFileResult CUploadFileResult = comPDFKitClient.uploadFile(new FileInputStream(file),taskId,filePassword,fileParameter,file.getName());
65+
String fileKey = CUploadFileResult.getFileKey();
66+
// perform tasks
67+
comPDFKitClient.executeTask(taskId);
68+
// create a ScheduledExecutorService with a fixed thread pool
69+
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
70+
// create an AtomicReference to hold the future
71+
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
72+
// schedule a task to check the task status at a fixed rate
73+
futureRef.set(executor.scheduleAtFixedRate(() -> {
74+
// get task processing information
75+
CTaskInfoResult taskInfo = comPDFKitClient.getTaskInfo(taskId);
76+
// determine whether the task status is "TaskFinish"
77+
if (taskInfo.getTaskStatus().equals(ComPDFKitConstant.TASK_FINISH)) {
78+
System.out.println(taskInfo);
79+
// get the final file processing information
80+
CFileInfo fileInfo = comPDFKitClient.getFileInfo(fileKey);
81+
System.out.println(fileInfo);
82+
// if the task is finished, cancel the scheduled task
83+
futureRef.get().cancel(false);
84+
}
85+
}, 0, 5, TimeUnit.SECONDS));
86+
// schedule a task to cancel the scheduled task after 15 minutes
87+
executor.schedule(() -> {
88+
futureRef.get().cancel(false);
89+
}, 15, TimeUnit.MINUTES);
90+
// shutdown the executor
91+
executor.shutdown();
92+
}
93+
94+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
2+
//
3+
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
4+
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
5+
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
6+
// This notice may not be removed from this file.
7+
8+
package cn.kdan.compdfkit;
9+
10+
11+
import cn.kdan.compdfkit.client.ComPDFKitClient;
12+
import cn.kdan.compdfkit.constant.ComPDFKitConstant;
13+
import cn.kdan.compdfkit.enums.COfficeToPDFEnum;
14+
import cn.kdan.compdfkit.param.CCsvToPDFParameter;
15+
import cn.kdan.compdfkit.param.CPngToPDFParameter;
16+
import cn.kdan.compdfkit.pojo.comPdfKit.CCreateTaskResult;
17+
import cn.kdan.compdfkit.pojo.comPdfKit.CFileInfo;
18+
import cn.kdan.compdfkit.pojo.comPdfKit.CTaskInfoResult;
19+
import cn.kdan.compdfkit.pojo.comPdfKit.CUploadFileResult;
20+
21+
import java.io.File;
22+
import java.io.FileInputStream;
23+
import java.io.FileNotFoundException;
24+
import java.util.concurrent.Executors;
25+
import java.util.concurrent.ScheduledExecutorService;
26+
import java.util.concurrent.ScheduledFuture;
27+
import java.util.concurrent.TimeUnit;
28+
import java.util.concurrent.atomic.AtomicReference;
29+
30+
public class CCsvToPDF {
31+
32+
private static final String publicKit = "";
33+
private static final String secretKey = "";
34+
private static final ComPDFKitClient comPDFKitClient = new ComPDFKitClient(publicKit,secretKey);
35+
36+
public static void main(String[] args) throws FileNotFoundException {
37+
CCsvToPDF.csvToPDF();
38+
}
39+
40+
public static void csvToPDF() throws FileNotFoundException {
41+
// create Task
42+
CCreateTaskResult CCreateTaskResult = comPDFKitClient.createTask(COfficeToPDFEnum.CSV_TO_PDF);
43+
// taskId
44+
String taskId = CCreateTaskResult.getTaskId();
45+
// upload File
46+
File file = new File("sample/test.csv");
47+
String filePassword = "";
48+
CCsvToPDFParameter fileParameter = new CCsvToPDFParameter();
49+
CUploadFileResult CUploadFileResult = comPDFKitClient.uploadFile(new FileInputStream(file),taskId,filePassword,fileParameter,file.getName());
50+
String fileKey = CUploadFileResult.getFileKey();
51+
// perform tasks
52+
comPDFKitClient.executeTask(taskId);
53+
// create a ScheduledExecutorService with a fixed thread pool
54+
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
55+
// create an AtomicReference to hold the future
56+
AtomicReference<ScheduledFuture<?>> futureRef = new AtomicReference<>();
57+
// schedule a task to check the task status at a fixed rate
58+
futureRef.set(executor.scheduleAtFixedRate(() -> {
59+
// get task processing information
60+
CTaskInfoResult taskInfo = comPDFKitClient.getTaskInfo(taskId);
61+
// determine whether the task status is "TaskFinish"
62+
if (taskInfo.getTaskStatus().equals(ComPDFKitConstant.TASK_FINISH)) {
63+
System.out.println(taskInfo);
64+
// get the final file processing information
65+
CFileInfo fileInfo = comPDFKitClient.getFileInfo(fileKey);
66+
System.out.println(fileInfo);
67+
// if the task is finished, cancel the scheduled task
68+
futureRef.get().cancel(false);
69+
}
70+
}, 0, 5, TimeUnit.SECONDS));
71+
// schedule a task to cancel the scheduled task after 15 minutes
72+
executor.schedule(() -> {
73+
futureRef.get().cancel(false);
74+
}, 15, TimeUnit.MINUTES);
75+
// shutdown the executor
76+
executor.shutdown();
77+
}
78+
79+
}

0 commit comments

Comments
 (0)