Salesforce - Salesforce
PDF Create Fillable PDF Forms sample in Salesforce demonstrating ‘Salesforce’
AddPDFOperations.cls
public class AddPDFOperations {
String API_KEY = '******************';
String endPointUrl = 'https://api.pdf.co/v1/pdf/edit/add';
public void addOperations() {
try {
String jsonBody = '{ "async": false, "inline": true, "name": "newDocument", "url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-edit/sample.pdf", "annotations": [ { "text": "sample prefilled text", "x": 10, "y": 30, "size": 12, "pages": "0-", "type": "TextField", "id": "textfield1" }, { "x": 100, "y": 150, "size": 12, "pages": "0-", "type": "Checkbox", "id": "checkbox2" }, { "x": 100, "y": 170, "size": 12, "pages": "0-", "link": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-edit/logo.png", "type": "CheckboxChecked", "id": "checkbox3" } ], "images": [ { "url": "pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-edit/logo.png", "x": 200, "y": 250, "pages": "0", "link": "www.pdf.co" } ] }';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setHeader('x-api-key', API_KEY);
request.setEndpoint(endPointUrl);
request.setHeader('Content-Type', 'application/json');
request.setMethod('POST');
request.setBody(jsonBody);
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200) {
System.debug('PDF edit result: ' + response.getBody());
} else {
System.debug('Error Response ' + response.getBody());
System.Debug(' Status ' + response.getStatus());
System.Debug(' Status Code' + response.getStatusCode());
System.Debug(' Response String' + response.toString());
}
} catch (Exception ex) {
String errorBody = 'Message: ' + ex.getMessage() + ' -- Cause: ' + ex.getCause() + ' -- Stacktrace: ' + ex.getStackTraceString();
System.Debug(errorBody);
}
}
}
AddPDFOperationsTest.cls
@isTest
private class AddPDFOperationsTest {
static testMethod void testAddPDFOperations() {
Test.startTest();
Test.setMock(HttpCalloutMock.class, new AddPDFOperationsTest.AddPDFOperationsMock());
AddPDFOperations addPDFOperations = new AddPDFOperations();
addPDFOperations.addOperations();
Test.stopTest();
}
public class AddPDFOperationsMock implements HttpCalloutMock {
public HttpResponse respond(HTTPRequest req) {
HttpResponse res = new HttpResponse();
String testBody = '{"success":true,"message":"PDF updated successfully","url":"https://pdf-temp-files.s3.us-west-2.amazonaws.com/xxxxxxxxxxxxxxxxxxxxxx","pagescount":1,"error":false,"status":200}';
res.setHeader('Content-Type', 'application/json');
res.setBody(testBody);
res.setStatusCode(200);
return res;
}
}
}
PDF.co Web API: the Web API with a set of tools for documents manipulation, data conversion, data extraction, splitting and merging of documents. Includes image recognition, built-in OCR, barcode generation and barcode decoders to decode bar codes from scans, pictures and pdf.
Download Source Code (.zip)
return to the previous page explore PDF Create Fillable PDF Forms endpoint
Copyright © 2016 - 2024 PDF.co