TypeScript client for the PDF Extract API.
npm install pdf-extract-api-client
First, import the ApiClient
class and create an instance:
import { ApiClient, OcrRequest } from 'pdf-extract-api-client';
const apiClient = new ApiClient('https://api.example.com');
To upload a file, create a FormData
object and use the uploadFile
method:
const formData = new FormData();
formData.append('file', fileInput.files[0]);
apiClient.uploadFile(formData).then(response => {
console.log(response);
});
To request OCR processing, create an OcrRequest
object and use the requestOcr
method:
const ocrRequest: OcrRequest = {
strategy: 'default',
model: 'ocr-model',
file: 'base64-encoded-file-content',
ocr_cache: true,
};
apiClient.requestOcr(ocrRequest).then(response => {
console.log(response);
});
To get the result of an OCR task, use the getResult
method with the task ID:
const taskId = 'your-task-id';
apiClient.getResult(taskId).then(result => {
console.log(result);
});
To clear the OCR cache, use the clearCache
method:
apiClient.clearCache().then(response => {
console.log(response);
});
To list files in storage, use the listFiles
method:
apiClient.listFiles().then(files => {
console.log(files);
});
To load a file from storage, use the loadFile
method:
const fileName = 'your-file-name';
apiClient.loadFile(fileName).then(file => {
console.log(file);
});
To delete a file from storage, use the deleteFile
method:
const fileName = 'your-file-name';
apiClient.deleteFile(fileName).then(response => {
console.log(response);
});