This tutorial will guide you through the process of integrating the ComPDFKit PDF API Library into your Java-based applications. The ComPDFKit API Libraries are organized around the REST standard, providing you with a comprehensive set of PDF features in various programming languages, including PHP, Java, Python, .NET (Core & Framework). The ComPDFKit PDF API Library offers a wide range of functionalities, such as PDF Viewing, PDF Editing, PDF Annotation, PDF Signing, PDF OCR (Optical Character Recognition), PDF Compression, etc.
Before you begin the integration process, you'll need to register for a ComPDFKit account. This account will provide you with a free plan that allows you to process up to 1,000 files within a 30-day validity period. In the following sections, we'll go through the step-by-step process of integrating the ComPDFKit PDF API Library into your Java project, covering topics such as authentication, Java PDF API library downloading, PDF API requests making , etc.
Requirements Before Java PDF API Calling
- Programming Environment: Java JDK 1.8 and higher.
- Dependencies: Maven.
Step 1. Register and Get a License
- Register ComPDFKit Account as a developer
- Check the Project ID, Public Key, and Secret Key from the API Keys section of the console
Step 2. Install Java PDF API Library
Add the following dependency to your pom.xml file.
<dependency>
<groupId>com.compdf</groupId>
<artifactId>compdfkit-api-java</artifactId>
<version>1.3.2.0</version>
</dependency>
Step 3. Authentication the License
ComPDFKit API uses JSON Web Tokens for secure authentication. You can authenticate your project easily:
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
For more information about this method and how we use it, take a look at the ComPDFKit API Reference Authentication section of our API reference.
Step 4. Make API Requests
1. Request Workflow for PDF API Library Java
Making a PDF API request is straightforward with just the following 4 steps:
- Create a task
- Pload a file
- Execute a task
- Download the result file.
Note:
- Creating a task is the step to decide which PDF Features you need to call with the corresponding PDF API.
- Pay attention to the file formats you upload. Most ComPDFKit PDF APIs process PDF files, but some Conversion PDF APIs may accept different formats, such as HTML for the HTML to PDF API.
2. PDF API Library Integration Guides: PDF to Word Java PDF API Library Example
Pass the Public Key and Secret Key before your requests like the code example below:
// Create a client
CPDFClient client = new CPDFClient(publicKey,secretKey);
// Create a task
// Create an example of a PDF tO Word task
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_WORD);
// Get a task id
String taskId = result.getTaskId();
// File handling parameter settings
CPDFToWordParameter fileParameter = new CPDFToWordParameter();
fileParameter.setIsContainAnnot("1");
fileParameter.setIsContainImg("1");
fileParameter.setIsFlowLayout("1");
// Upload files
client.uploadFile(new File("test.pdf"), taskId, fileParameter);
// Execute task
client.executeTask(taskId);
// Query TaskInfo
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
By integrating a Java PDF API like ComPDFKit, enterprises can streamline their PDF-related workflows, improve productivity, maintain data security, and deliver a better user experience for their employees and customers.
Final Words
ComPDFKit provides a comprehensive suite of free PDF API libraries and support for various programming languages:
- PDF API of Supported PDF Features Include PDF conversion API, PDF Page Edit API, OCR API, etc.
- PDF API Languages Include Java, PHP, Python, C#.NET, Swift, etc.
The corresponding PDF API Integration guides can be found on the ComPDFKit's PDF API library documentation page.
These free PDF API libraries offer 1000 free file processing, making them accessible for developers to integrate into their projects. If you encounter any issues or have questions, you can reach out to the ComPDFKit support team for an immediate response.