Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDFCLOUD-2823 Add upload + raw JSON Javascript samples #58

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions JavaScript/Endpoint Examples/JSON Payload/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains examples of how to call each endpoint of the
PdfRest API using Javascript. Please refer to https://pdfrest.com/documentation.html
for accepted inputs, options, and other specifics about individual endpoints.
47 changes: 47 additions & 0 deletions JavaScript/Endpoint Examples/JSON Payload/bmp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var axios = require("axios");
var FormData = require("form-data");
var fs = require("fs");

var upload_data = fs.createReadStream("/path/to/file");

var upload_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/upload",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Filename": "filename.pdf",
"Content-Type": "application/octet-stream",
},
data: upload_data, // set the data to be sent with the request
};

// send request and handle response or error
axios(upload_config)
.then(function (upload_response) {
console.log(JSON.stringify(upload_response.data));
var uploaded_id = upload_response.data.files[0].id;

var bmp_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/bmp",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Type": "application/json",
},
data: { id: uploaded_id }, // set the data to be sent with the request
};

// send request and handle response or error
axios(bmp_config)
.then(function (bmp_response) {
console.log(JSON.stringify(bmp_response.data));
})
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log(error);
});
47 changes: 47 additions & 0 deletions JavaScript/Endpoint Examples/JSON Payload/compressed-pdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var axios = require("axios");
var FormData = require("form-data");
var fs = require("fs");

var upload_data = fs.createReadStream("/path/to/file");

var upload_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/upload",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Filename": "filename.pdf",
"Content-Type": "application/octet-stream",
},
data: upload_data, // set the data to be sent with the request
};

// send request and handle response or error
axios(upload_config)
.then(function (upload_response) {
console.log(JSON.stringify(upload_response.data));
var uploaded_id = upload_response.data.files[0].id;

var compress_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/compressed-pdf",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Type": "application/json",
},
data: { id: uploaded_id, compression_level: "medium" }, // set the data to be sent with the request
};

// send request and handle response or error
axios(compress_config)
.then(function (compress_response) {
console.log(JSON.stringify(compress_response.data));
})
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log(error);
});
47 changes: 47 additions & 0 deletions JavaScript/Endpoint Examples/JSON Payload/decrypted-pdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var axios = require("axios");
var FormData = require("form-data");
var fs = require("fs");

var upload_data = fs.createReadStream("/path/to/file");

var upload_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/upload",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Filename": "filename.pdf",
"Content-Type": "application/octet-stream",
},
data: upload_data, // set the data to be sent with the request
};

// send request and handle response or error
axios(upload_config)
.then(function (upload_response) {
console.log(JSON.stringify(upload_response.data));
var uploaded_id = upload_response.data.files[0].id;

var decrypt_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/decrypted-pdf",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Type": "application/json",
},
data: { id: uploaded_id, current_open_password: "current_password" }, // set the data to be sent with the request
};

// send request and handle response or error
axios(decrypt_config)
.then(function (decrypt_response) {
console.log(JSON.stringify(decrypt_response.data));
})
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log(error);
});
47 changes: 47 additions & 0 deletions JavaScript/Endpoint Examples/JSON Payload/encrypted-pdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var axios = require("axios");
var FormData = require("form-data");
var fs = require("fs");

var upload_data = fs.createReadStream("/path/to/file");

var upload_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/upload",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Filename": "filename.pdf",
"Content-Type": "application/octet-stream",
},
data: upload_data, // set the data to be sent with the request
};

// send request and handle response or error
axios(upload_config)
.then(function (upload_response) {
console.log(JSON.stringify(upload_response.data));
var uploaded_id = upload_response.data.files[0].id;

var encrypt_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/encrypted-pdf",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Type": "application/json",
},
data: { id: uploaded_id, new_open_password: "password" }, // set the data to be sent with the request
};

// send request and handle response or error
axios(encrypt_config)
.then(function (encrypt_response) {
console.log(JSON.stringify(encrypt_response.data));
})
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log(error);
});
47 changes: 47 additions & 0 deletions JavaScript/Endpoint Examples/JSON Payload/excel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var axios = require("axios");
var FormData = require("form-data");
var fs = require("fs");

var upload_data = fs.createReadStream("/path/to/file");

var upload_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/upload",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Filename": "filename.pdf",
"Content-Type": "application/octet-stream",
},
data: upload_data, // set the data to be sent with the request
};

// send request and handle response or error
axios(upload_config)
.then(function (upload_response) {
console.log(JSON.stringify(upload_response.data));
var uploaded_id = upload_response.data.files[0].id;

var excel_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/excel",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Type": "application/json",
},
data: { id: uploaded_id }, // set the data to be sent with the request
};

// send request and handle response or error
axios(excel_config)
.then(function (excel_response) {
console.log(JSON.stringify(excel_response.data));
})
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log(error);
});
47 changes: 47 additions & 0 deletions JavaScript/Endpoint Examples/JSON Payload/exported-form-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var axios = require("axios");
var FormData = require("form-data");
var fs = require("fs");

var upload_data = fs.createReadStream("/path/to/file");

var upload_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/upload",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Filename": "filename.pdf",
"Content-Type": "application/octet-stream",
},
data: upload_data, // set the data to be sent with the request
};

// send request and handle response or error
axios(upload_config)
.then(function (upload_response) {
console.log(JSON.stringify(upload_response.data));
var uploaded_id = upload_response.data.files[0].id;

var export_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/exported-form-data",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Type": "application/json",
},
data: { id: uploaded_id, data_format: "xml" }, // set the data to be sent with the request
};

// send request and handle response or error
axios(export_config)
.then(function (export_response) {
console.log(JSON.stringify(export_response.data));
})
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log(error);
});
47 changes: 47 additions & 0 deletions JavaScript/Endpoint Examples/JSON Payload/extracted-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var axios = require("axios");
var FormData = require("form-data");
var fs = require("fs");

var upload_data = fs.createReadStream("/path/to/file");

var upload_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/upload",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Filename": "filename.pdf",
"Content-Type": "application/octet-stream",
},
data: upload_data, // set the data to be sent with the request
};

// send request and handle response or error
axios(upload_config)
.then(function (upload_response) {
console.log(JSON.stringify(upload_response.data));
var uploaded_id = upload_response.data.files[0].id;

var extract_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/extracted-text",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Type": "application/json",
},
data: { id: uploaded_id }, // set the data to be sent with the request
};

// send request and handle response or error
axios(extract_config)
.then(function (extract_response) {
console.log(JSON.stringify(extract_response.data));
})
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log(error);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var axios = require("axios");
var FormData = require("form-data");
var fs = require("fs");

var upload_data = fs.createReadStream("/path/to/file");

var upload_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/upload",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Filename": "filename.pdf",
"Content-Type": "application/octet-stream",
},
data: upload_data, // set the data to be sent with the request
};

// send request and handle response or error
axios(upload_config)
.then(function (upload_response) {
console.log(JSON.stringify(upload_response.data));
var uploaded_id = upload_response.data.files[0].id;

var flatten_config = {
method: "post",
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/flattened-annotations-pdf",
headers: {
"Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Content-Type": "application/json",
},
data: { id: uploaded_id }, // set the data to be sent with the request
};

// send request and handle response or error
axios(flatten_config)
.then(function (flatten_response) {
console.log(JSON.stringify(flatten_response.data));
})
.catch(function (error) {
console.log(error);
});
})
.catch(function (error) {
console.log(error);
});
Loading