Skip to content

Commit 839f366

Browse files
committed
Merge branch 'beta1.2.4'
2 parents e11661a + 6348248 commit 839f366

File tree

102 files changed

+5169
-1067
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

+5169
-1067
lines changed

README.md

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,141 @@
1-
## compdfkit-pdf-api-java
1+
## ComPDFKit API in Java
2+
3+
[ComPDFKit](https://api.compdf.com/api/docs/introduction) API provides a variety of Java API tools that allow you to create an efficient document processing workflow in a single API call. Try our various APIs for free — no credit card required.
4+
25

3-
This is the compdfkit-pdf-api Java SDK for the [ComPDFKit](https://api.compdf.com/api/docs/introduction) API.
46

57
## Requirements
68

7-
JAVA JDK 1.8 and later.
9+
Programming Environment: Java JDK 1.8 and higher.
10+
11+
Dependencies: Maven.
812

9-
Maven 3.6 and later.
1013

11-
Springboot 2.3.0.RELEASE and later.
1214

1315
## Installation
1416

15-
Add the following dependency to your pom.xml:
17+
Add the following dependency to your ***"pom.xml"***:
1618

1719
```
1820
<dependency>
1921
<groupId>com.compdf</groupId>
20-
<artifactId>compdfkit-pdf-api-java</artifactId>
21-
<version>1.2.2</version>
22+
<artifactId>compdfkit-api-java</artifactId>
23+
<version>1.2.4</version>
2224
</dependency>
2325
```
2426

27+
28+
2529
## Create API Client
2630

27-
You can use your **publicKey** and **secretKey** to complete the authentication
31+
You can use your **publicKey** and **secretKey** to complete the authentication. You need to [sign in](https://api.compdf.com/login) your ComPDFKit API account to get your **publicKey** and **secretKey** at the [dashboard](https://api-dashboard.compdf.com/api/keys). If you are new to ComPDFKit, click here to [sign up](https://api.compdf.com/signup) for a free trial.
2832

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

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

3337
```java
34-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
38+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
3539
```
3640

41+
42+
3743
## Create Task
3844

39-
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.
45+
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 request result, such as checking the status of the task, uploading files, starting the task, or downloading the result file.
4046

4147
```java
4248
// Create a client
43-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
49+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
4450

51+
// Create a task
4552
// Create an example of a PDF TO WORD task
46-
CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_WORD.getValue());
53+
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_WORD.getValue());
4754

48-
//Get a task id
49-
String jobId = result.getTaskId();
55+
// Get a task id
56+
String taskId = result.getTaskId();
5057
```
5158

52-
## Upload Files
5359

54-
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.
5560

61+
## Upload Files
5662

63+
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.
5764

5865
```java
5966
// Create a client
60-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
67+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
6168

6269
// Create a task
6370
// Create an example of a PDF TO WORD task
64-
CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_WORD.getValue());
71+
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_WORD.getValue());
6572

6673
// Get a task id
67-
String jobId = result.getTaskId();
74+
String taskId = result.getTaskId();
6875

69-
// Upload file
70-
client.uploadFile(<convertFile>, jobId);
76+
// Upload files
77+
client.uploadFile(<convertFile>, taskId);
7178
```
7279

7380

7481

7582
## Execute the task
7683

77-
After the file upload is completed, call this interface with the task ID to process file.
84+
After the file upload is completed, call this interface with the task ID to process the files.
7885

7986
```java
8087
// Create a client
81-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
88+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
8289

8390
// Create a task
84-
// Create an example of a PDF TO EXCEL task
85-
CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_WORD.getValue());
91+
// Create an example of a PDF TO WORD task
92+
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_WORD.getValue());
8693

8794
// Get a task id
88-
String jobId = result.getTaskId();
95+
String taskId = result.getTaskId();
8996

9097
// Upload files
91-
client.uploadFile(<convertFile>, jobId);
98+
client.uploadFile(<convertFile>, taskId);
9299

93100
// execute Task
94-
client.executeTask(jobId);
101+
client.executeTask(taskId);
95102
```
96103

97-
## Get TaskInfo
98104

99-
Request task status and file-related metadata based on the task ID.
105+
106+
## Get Task Info
107+
108+
Request task status and file-related meta data based on the task ID.
100109

101110
```java
102111
// Create a client
103-
ComPdfKitClient client = new ComPdfKitClient(<publicKey>, <secretKey>);
112+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
104113

105114
// Create a task
106115
// Create an example of a PDF TO WORD task
107-
CreateTaskResult result = client.createTask(PDFToOfficeEnum.PDF_TO_WORD.getValue());
116+
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_WORD.getValue());
108117

109118
// Get a task id
110-
String jobId = result.getTaskId();
119+
String taskId = result.getTaskId();
111120

112121
// Upload files
113-
client.uploadFile(<convertFile>, jobId);
122+
client.uploadFile(<convertFile>, taskId);
114123

115-
// execute Task
116-
client.executeTask(jobId);
124+
// Execute Task
125+
client.executeTask(taskId);
117126

118-
// query TaskInfo
119-
QueryTaskInfoResult taskInfo = client.queryTaskInfo(jobId)
127+
// Query TaskInfo
128+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
120129
```
121130

131+
132+
133+
## Samples
134+
135+
See ***"Samples"*** folder in this folder.
136+
137+
138+
122139
## Resources
123140

124141
* [ComPDFKit API Documentation](https://api.compdf.com/api/docs/introduction)

pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242

4343

4444
<groupId>com.compdf</groupId>
45-
<artifactId>compdfkit-pdf-api-java</artifactId>
46-
<version>1.2.2</version>
45+
<artifactId>compdfkit-api-java</artifactId>
46+
<version>1.2.4</version>
4747

48-
<name>compdfkit-pdf-api-java</name>
49-
<description>compdfkit-pdf-api-java</description>
50-
<url>https://github.com/ComPDFKit/compdfkit-pdf-api-java</url>
48+
<name>compdfkit-api-java</name>
49+
<description>compdfkit-api-java</description>
50+
<url>https://github.com/ComPDFKit/compdfkit-api-java</url>
5151

5252
<licenses>
5353
<license>
@@ -70,9 +70,9 @@
7070
</developers>
7171

7272
<scm>
73-
<connection>https://github.com/ComPDFKit/compdfkit-pdf-api-java.git</connection>
74-
<developerConnection>scm:git:ssh://git@github.com:ComPDFKit/compdfkit-pdf-api-java.git</developerConnection>
75-
<url>https://github.com/ComPDFKit/compdfkit-pdf-api-java</url>
73+
<connection>https://github.com/ComPDFKit/compdfkit-api-java.git</connection>
74+
<developerConnection>scm:git:ssh://git@github.com:ComPDFKit/compdfkit-api-java.git</developerConnection>
75+
<url>https://github.com/ComPDFKit/compdfkit-api-java</url>
7676
</scm>
7777

7878

@@ -82,7 +82,7 @@
8282

8383
<profiles>
8484
<profile>
85-
<id>ossrh</id>
85+
<id>release</id>
8686
<activation>
8787
<activeByDefault>true</activeByDefault>
8888
</activation>
@@ -165,7 +165,7 @@
165165

166166
</profiles>
167167
<build>
168-
<finalName>compdfkit-pdf-api-java</finalName>
168+
<finalName>compdfkit-api-java</finalName>
169169
</build>
170170

171171
</project>

samples/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>samples</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.compdf</groupId>
18+
<artifactId>compdfkit-api-java</artifactId>
19+
<version>1.2.4</version>
20+
</dependency>
21+
</dependencies>
22+
23+
</project>
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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 com.compdfkit;
9+
10+
11+
import com.compdfkit.client.CPDFClient;
12+
import com.compdfkit.constant.CPDFConstant;
13+
import com.compdfkit.enums.CPDFDocumentEditorEnum;
14+
import com.compdfkit.param.CPDFAddWatermarkParameter;
15+
import com.compdfkit.pojo.comPdfKit.CPDFCreateTaskResult;
16+
import com.compdfkit.pojo.comPdfKit.CPDFFileInfo;
17+
import com.compdfkit.pojo.comPdfKit.CPDFTaskInfoResult;
18+
import com.compdfkit.pojo.comPdfKit.CPDFUploadFileResult;
19+
20+
import java.io.File;
21+
import java.io.FileInputStream;
22+
import java.io.FileNotFoundException;
23+
import java.io.IOException;
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 AddWatermark {
31+
32+
private static final String publicKey = "";
33+
private static final String secretKey = "";
34+
private static final CPDFClient client = new CPDFClient(publicKey,secretKey);
35+
36+
public static void main(String[] args) throws FileNotFoundException {
37+
AddWatermark.addWatermarkText();
38+
// AddWatermark.addWatermarkImage();
39+
}
40+
41+
public static void addWatermarkText() throws FileNotFoundException {
42+
// create Task
43+
CPDFCreateTaskResult createTaskResult = client.createTask(CPDFDocumentEditorEnum.ADD_WATERMARK);
44+
// taskId
45+
String taskId = createTaskResult.getTaskId();
46+
// upload File
47+
File file = new File("sample/test.pdf");
48+
String filePassword = "";
49+
CPDFAddWatermarkParameter fileParameter = new CPDFAddWatermarkParameter();
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("1");
62+
fileParameter.setHorizontalSpace("10");
63+
fileParameter.setVerticalSpace("10");
64+
CPDFUploadFileResult uploadFileResult = client.uploadFile(new FileInputStream(file),taskId,filePassword,fileParameter,file.getName());
65+
String fileKey = uploadFileResult.getFileKey();
66+
// perform tasks
67+
client.executeTask(taskId);
68+
// get task processing information
69+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
70+
// determine whether the task status is "TaskFinish"
71+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
72+
System.out.println(taskInfo);
73+
// get the final file processing information
74+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
75+
System.out.println(fileInfo);
76+
// if the task is finished, cancel the scheduled task
77+
}else {
78+
System.out.println("Task incomplete processing");
79+
}
80+
}
81+
82+
public static void addWatermarkImage() throws IOException {
83+
// create Task
84+
CPDFCreateTaskResult createTaskResult = client.createTask(CPDFDocumentEditorEnum.ADD_WATERMARK);
85+
// taskId
86+
String taskId = createTaskResult.getTaskId();
87+
// upload File
88+
File file = new File("sample/test.pdf");
89+
String filePassword = "";
90+
CPDFAddWatermarkParameter fileParameter = new CPDFAddWatermarkParameter();
91+
fileParameter.setType("image");
92+
fileParameter.setScale("0.5");
93+
fileParameter.setOpacity("0.5");
94+
fileParameter.setRotation("45");
95+
fileParameter.setTargetPages("1-2");
96+
fileParameter.setVertalign("center");
97+
fileParameter.setHorizalign("left");
98+
fileParameter.setXoffset("50");
99+
fileParameter.setYoffset("50");
100+
fileParameter.setFullScreen("1");
101+
fileParameter.setHorizontalSpace("100");
102+
fileParameter.setVerticalSpace("100");
103+
fileParameter.setFront("1");
104+
CPDFUploadFileResult uploadFileResult = client.uploadFile(file,taskId,fileParameter,new File("sample/test.jpg"));
105+
String fileKey = uploadFileResult.getFileKey();
106+
// perform tasks
107+
client.executeTask(taskId);
108+
// get task processing information
109+
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
110+
// determine whether the task status is "TaskFinish"
111+
if (taskInfo.getTaskStatus().equals(CPDFConstant.TASK_FINISH)) {
112+
System.out.println(taskInfo);
113+
// get the final file processing information
114+
CPDFFileInfo fileInfo = client.getFileInfo(fileKey);
115+
System.out.println(fileInfo);
116+
// if the task is finished, cancel the scheduled task
117+
}else {
118+
System.out.println("Task incomplete processing");
119+
}
120+
}
121+
122+
}

0 commit comments

Comments
 (0)