Skip to content

Commit 35d622e

Browse files
committed
Initial commit
0 parents  commit 35d622e

File tree

91 files changed

+4522
-0
lines changed

Some content is hidden

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

91 files changed

+4522
-0
lines changed

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2014-2023 PDF Technologies, Inc. All Rights Reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
## ComPDFKit API in C#.NET
2+
3+
[ComPDFKit](https://api.compdf.com/api/docs/introduction) API provides a variety of C# 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+
5+
6+
7+
## Requirements
8+
9+
Programming Environment: .NET Framework 4.6.1 or higher. Or .NET Core 1.0 or higher.
10+
11+
Dependencies: Nuget.
12+
13+
14+
15+
## Installation
16+
17+
You can install the ComPDFKit API in C# via NuGet Package Manager, or run the following command in the Package Manager Console:
18+
``` shell script
19+
Install-Package ComPDFKit.Api.CSharp
20+
```
21+
Alternatively, you can add the package ***"ComPDFKit.Api.CSharp"***, choose the package version you want to your ***".csproj"*** file, and then run.
22+
23+
24+
25+
## Create API Client
26+
27+
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.
28+
29+
- Project public Key: You can find the public key in the **API Keys** section of your ComPDFKit API account.
30+
31+
- Project secret Key: You can find the secret Key in the **API Keys** section of your ComPDFKit API account.
32+
33+
```csharp
34+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
35+
```
36+
37+
38+
39+
## Create Task
40+
41+
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.
42+
43+
```csharp
44+
// Create a client
45+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
46+
47+
// Create a task
48+
// Create an example task to convert a PDF tO a Word
49+
CPDFCreateTaskResult result = client.CreateTask(CPDFConversionEnum.PDF_TO_WORD);
50+
51+
// Get a task id
52+
string taskId = result.TaskId;
53+
```
54+
55+
56+
57+
## Upload Files
58+
59+
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.
60+
61+
```csharp
62+
// Create a client
63+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
64+
65+
// Create a task
66+
// Create an example task to convert a PDF tO a Word
67+
CPDFCreateTaskResult result = client.CreateTask(CPDFConversionEnum.PDF_TO_WORD);
68+
69+
// Get a task id
70+
string taskId = result.TaskId;
71+
72+
// Upload files
73+
client.UploadFile(<convertFile>, taskId);
74+
```
75+
76+
77+
78+
## Execute the Task
79+
80+
After the file upload is completed, call this interface with the task ID to process the files.
81+
82+
```csharp
83+
// Create a client
84+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
85+
86+
// Create a task
87+
// Create an example task to convert a PDF tO a Word
88+
CPDFCreateTaskResult result = client.CreateTask(CPDFConversionEnum.PDF_TO_WORD);
89+
90+
// Get a task id
91+
string taskId = result.TaskId;
92+
93+
// Upload files
94+
client.UploadFile(<convertFile>, taskId);
95+
96+
// Execute the task
97+
client.ExecuteTask(taskId, CPDFLanguageConstant.English);
98+
```
99+
100+
101+
102+
## Get Task Info
103+
104+
Request task status and file-related meta data based on the task ID.
105+
106+
```csharp
107+
// Create a client
108+
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
109+
110+
// Create a task
111+
// Create an example task to convert a PDF tO a Word
112+
CPDFCreateTaskResult result = client.CreateTask(CPDFConversionEnum.PDF_TO_WORD);
113+
114+
// Get a task id
115+
string taskId = result.TaskId;
116+
117+
// Upload files
118+
client.UploadFile(<convertFile>, taskId);
119+
120+
// execute Task
121+
client.ExecuteTask(taskId, CPDFLanguageConstant.English);
122+
123+
// Query TaskInfo
124+
CPDFTaskInfoResult taskInfo = client.GetTaskInfo(taskId);
125+
```
126+
127+
128+
129+
## Samples
130+
131+
See ***"Samples"*** folder in this folder.
132+
133+
134+
135+
## Resources
136+
137+
* [Guides of ComPDFKit API Libraries](https://api.compdf.com/api-libraries/overview)

sample/src/AddWatermark.cs

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
using System;
2+
using System.IO;
3+
using ComPDFKit;
4+
using ComPDFKit.client;
5+
using ComPDFKit.constant;
6+
using ComPDFKit.enums;
7+
using ComPDFKit.exception;
8+
using ComPDFKit.param;
9+
using ComPDFKit.pojo.comPdfKit;
10+
11+
namespace Samples
12+
{
13+
public class AddWatermark
14+
{
15+
private const string publicKey = "";
16+
private const string secretKey = "";
17+
private static CPDFClient client;
18+
19+
public static void Main(string[] args)
20+
{
21+
AddWatermarkTextFunc();
22+
// AddWatermarkImageFunc();
23+
}
24+
25+
public static void AddWatermarkTextFunc()
26+
{
27+
try
28+
{
29+
// Initialize Client
30+
client = new CPDFClient(publicKey, secretKey);
31+
// Create Task
32+
CPDFCreateTaskResult createTaskResult =client.CreateTask(CPDFDocumentEditorEnum.ADD_WATERMARK, CPDFLanguageConstant.English);
33+
// TaskId
34+
string taskId = createTaskResult.TaskId;
35+
// Upload File
36+
FileInfo file = new FileInfo("sample/test.pdf");
37+
string filePassword = "";
38+
CPDFAddWatermarkParameter fileParameter = new CPDFAddWatermarkParameter
39+
{
40+
Type = "text",
41+
Scale = "1",
42+
Opacity = "0.5",
43+
Rotation = "0.785",
44+
TargetPages = "1-2",
45+
VertAlign = "center",
46+
HorizAlign = "left",
47+
XOffset = "100",
48+
YOffset = "100",
49+
Content = "test",
50+
TextColor = "#59c5bb",
51+
FullScreen = "1",
52+
HorizontalSpace = "10",
53+
VerticalSpace = "10",
54+
Front = "1"
55+
};
56+
CPDFUploadFileResult uploadFileResult = client.UploadFile(file, taskId, fileParameter, filePassword);
57+
string fileKey = uploadFileResult.FileKey;
58+
// Perform Tasks
59+
client.ExecuteTask(taskId);
60+
// Get Task Processing Information
61+
CPDFTaskInfoResult taskInfo = client.GetTaskInfo(taskId);
62+
// Determine whether the task status is "TaskFinish"
63+
if (taskInfo.TaskStatus == CPDFConstant.TASK_FINISH)
64+
{
65+
Console.WriteLine(taskInfo);
66+
// Get the final file processing information
67+
CPDFFileInfo fileInfo = client.GetFileInfo(fileKey);
68+
Console.WriteLine(fileInfo);
69+
// If the task is finished, cancel the scheduled task
70+
}
71+
else
72+
{
73+
Console.WriteLine("Task incomplete processing");
74+
}
75+
}
76+
catch (CPDFException e)
77+
{
78+
Console.WriteLine(e.GetCode() + ": " + e.Message);
79+
}
80+
}
81+
82+
public static void AddWatermarkImageFunc()
83+
{
84+
try
85+
{
86+
// Initialize Client
87+
client = new CPDFClient(publicKey, secretKey);
88+
// Create Task
89+
CPDFCreateTaskResult createTaskResult = client.CreateTask(CPDFDocumentEditorEnum.ADD_WATERMARK);
90+
// TaskId
91+
string taskId = createTaskResult.TaskId;
92+
// Upload File
93+
FileInfo file = new FileInfo("sample/test.pdf");
94+
string filePassword = "";
95+
CPDFAddWatermarkParameter fileParameter = new CPDFAddWatermarkParameter
96+
{
97+
Type = "image",
98+
Scale = "0.5",
99+
Opacity = "0.5",
100+
Rotation = "45",
101+
TargetPages = "1-2",
102+
VertAlign = "center",
103+
HorizAlign = "left",
104+
XOffset = "50",
105+
YOffset = "50",
106+
FullScreen = "1",
107+
HorizontalSpace = "100",
108+
VerticalSpace = "100",
109+
Front = "1"
110+
};
111+
CPDFUploadFileResult uploadFileResult =
112+
client.UploadFile(file, new FileInfo("sample/test.jpg"), taskId, fileParameter, filePassword);
113+
string fileKey = uploadFileResult.FileKey;
114+
// Perform Tasks
115+
client.ExecuteTask(taskId);
116+
// Get Task Processing Information
117+
CPDFTaskInfoResult taskInfo = client.GetTaskInfo(taskId);
118+
// Determine whether the task status is "TaskFinish"
119+
if (taskInfo.TaskStatus == CPDFConstant.TASK_FINISH)
120+
{
121+
Console.WriteLine(taskInfo);
122+
// Get the final file processing information
123+
CPDFFileInfo fileInfo = client.GetFileInfo(fileKey);
124+
Console.WriteLine(fileInfo);
125+
// If the task is finished, cancel the scheduled task
126+
}
127+
else
128+
{
129+
Console.WriteLine("Task incomplete processing");
130+
}
131+
}
132+
catch (CPDFException e)
133+
{
134+
Console.WriteLine(e.GetCode() + ": " + e.Message);
135+
}
136+
}
137+
}
138+
}

sample/src/CSVToPDF.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.IO;
3+
using ComPDFKit.client;
4+
using ComPDFKit.constant;
5+
using ComPDFKit.enums;
6+
using ComPDFKit.exception;
7+
using ComPDFKit.param;
8+
using ComPDFKit.pojo.comPdfKit;
9+
10+
namespace Samples
11+
{
12+
class CSVToPDF
13+
{
14+
private const string publicKey = "";
15+
private const string secretKey = "";
16+
private static CPDFClient client;
17+
18+
static void Main(string[] args)
19+
{
20+
CSVToPDFFunc();
21+
}
22+
23+
static void CSVToPDFFunc()
24+
{
25+
try
26+
{
27+
// Initialize Client
28+
client = new CPDFClient(publicKey, secretKey);
29+
// Create Task
30+
CPDFCreateTaskResult createTaskResult = client.CreateTask(CPDFConversionEnum.CSV_TO_PDF);
31+
// TaskId
32+
string taskId = createTaskResult.TaskId;
33+
// Upload File
34+
FileInfo file = new FileInfo("sample/test.csv");
35+
string filePassword = "";
36+
CCSVToPDFParameter fileParameter = new CCSVToPDFParameter();
37+
CPDFUploadFileResult uploadFileResult = client.UploadFile(file, taskId, fileParameter, filePassword);
38+
string fileKey = uploadFileResult.FileKey;
39+
// Perform tasks
40+
client.ExecuteTask(taskId);
41+
// Get task processing information
42+
CPDFTaskInfoResult taskInfo = client.GetTaskInfo(taskId);
43+
// Determine whether the task status is "TaskFinish"
44+
if (taskInfo.TaskStatus.Equals(CPDFConstant.TASK_FINISH))
45+
{
46+
Console.WriteLine(taskInfo);
47+
// Get the final file processing information
48+
CPDFFileInfo fileInfo = client.GetFileInfo(fileKey);
49+
Console.WriteLine(fileInfo);
50+
// If the task is finished, cancel the scheduled task
51+
}
52+
else
53+
{
54+
Console.WriteLine("Task incomplete processing");
55+
}
56+
}
57+
catch (CPDFException e)
58+
{
59+
Console.WriteLine(e.GetCode() + ": " + e.Message);
60+
}
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)