Skip to content

Commit da94d79

Browse files
authored
Merge pull request #98 from aspose-pdf-cloud/use-cases-attachments-images
implemented_attachments_images
2 parents d3e463b + dc78487 commit da94d79

File tree

8 files changed

+264
-0
lines changed

8 files changed

+264
-0
lines changed

UsesCases/Attachments/add/add.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2+
// 2. Create an object to connect to the Pdf.Cloud API
3+
// 3. Create an AttachmentInfo object, which maust be inserted into Pdf file
4+
// 4. Perform append attachment into Pdf document using postAddDocumentAttachment() function and AttachmentImfo object
5+
// 5. Check result and perform some actions with result.body object
6+
// All values of variables starting with "YOUR_****" should be replaced by real user values
7+
8+
var PdfApi = require('asposepdfcloud');
9+
10+
var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json');
11+
12+
var AppSID = configProps.app_sid;
13+
var AppKey = configProps.api_key;
14+
var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true };
15+
16+
var pdfApi = new PdfApi(config);
17+
18+
const attachment = new AttachmentInfo();
19+
attachment.name = "YOUR_ATTACHMENT_NAME";
20+
attachment.path = "YOUR_ATTACHMENT_PATH";
21+
attachment.description = "YOUR_ATTACHMENT_DESCRIPTION";
22+
attachment.mimeType = "type/YOUR_SUBTYPE";
23+
24+
let result = await pdfApi.postAddDocumentAttachment ("YOUR_PDF_FILE_NAME.pdf", attachment, null, null);
25+
26+
console.log(result.response);
27+
28+
console.log(result.body);

UsesCases/Attachments/get/get.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2+
// 2. Create a Storage API object for uploading Pdf file
3+
// 3. Create an object to connect to the Pdf.Cloud API
4+
// 4. Upload your document file using PutCreate() function of the Storage API object
5+
// 5. To extract attachments from a PDF document, using getDocumentAttachments() function
6+
// 6. Check result and perform some actions with result.body object
7+
// All values of variables starting with "YOUR_****" should be replaced by real user values
8+
9+
var fs = require('fs');
10+
var PdfApi = require('asposepdfcloud');
11+
var StorageApi = require('asposestoragecloud');
12+
13+
var configProps = require('YOUR_CONFIG_FOLDER/YOUR_CONFIG.json');
14+
15+
var data_path = 'YOUR_DATA_FOLDER_WITH_PATH/';
16+
17+
var AppSID = configProps.app_sid;
18+
var AppKey = configProps.api_key;
19+
var outFolder = configProps.out_folder;
20+
var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true };
21+
22+
var storageApi = new StorageApi(config);
23+
24+
var pdfApi = new PdfApi(config);
25+
26+
var fileName = "YOUR_ATTACHMENT_FILE_NAME";
27+
var name = fileName + ".pdf";
28+
var attachmentIndex = 1;
29+
30+
31+
storageApi.PutCreate(name, null, null, data_path + name , async function(responseMessage) {
32+
33+
assert.equal(responseMessage.status, 'OK');
34+
35+
let result = await pdfApi.getDocumentAttachments(name, attachmentIndex, null, null);
36+
37+
console.log(result.response);
38+
39+
console.log(result.body);
40+
});

UsesCases/Attachments/get_download.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2+
// 2. Create a Storage API object for uploading Pdf file
3+
// 3. Create an object to connect to the Pdf.Cloud API
4+
// 4. Upload your document file using PutCreate() function of the Storage API object
5+
// 5. To extract attachments from a PDF document, using getDocumentAttachmentByIndex() function
6+
// 6. Download the result if need it
7+
// All values of variables starting with "YOUR_****" should be replaced by real user values
8+
9+
var fs = require('fs');
10+
var PdfApi = require('asposepdfcloud');
11+
var StorageApi = require('asposestoragecloud');
12+
13+
var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json');
14+
15+
var data_path = 'YOUR_DATA_FOLDER_WITH_PATH/';
16+
17+
var AppSID = configProps.app_sid;
18+
var AppKey = configProps.api_key;
19+
var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true };
20+
21+
var storageApi = new StorageApi(config);
22+
23+
var pdfApi = new PdfApi(config);
24+
25+
var fileName = "YOUR_ATTACHMENT_FILE_NAME";
26+
var name = fileName + ".pdf";
27+
var attachmentIndex = 1;
28+
29+
storageApi.PutCreate(name, null, null, data_path + name , async function(responseMessage)
30+
{
31+
32+
let result = await pdfApi.getDownloadDocumentAttachmentByIndex(name, attachmentIndex, null, null);
33+
34+
var outfilename = fileName + attachmentIndex + ".text";
35+
var writeStream = fs.createWriteStream(data_path + outfilename);
36+
writeStream.write(result.body);
37+
38+
});

UsesCases/Images/add/add.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2+
// 2. Create an object to connect to the Pdf.Cloud API
3+
// 3. Initialize neccessary values for append image
4+
// 4. Perform the inserting image in Pdf document using postInsertImage() function and new image file initialized values
5+
// 6. Check result and perform some actions with result.body object
6+
// All values of variables starting with "YOUR_****" should be replaced by real user values
7+
8+
9+
var PdfApi = require('asposepdfcloud');
10+
11+
var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json');
12+
13+
var AppSID = configProps.app_sid;
14+
var AppKey = configProps.api_key;
15+
var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true };
16+
17+
pdfApi = new PdfApi(AppSID, AppKey);
18+
19+
let fileName = "YOUR_PDF_DOCUMENT.pdf";
20+
21+
let pageNum = "YOUR_PAGE_NUMBER";
22+
23+
let posLeftDownX = "YOUR_IMAGE_LLX";
24+
let posLeftDownY = "YOUR_IMAGE_LLY";
25+
26+
let posRighUptX = "YOUR_IMAGE_URX";
27+
let posRightUpY = "YOUR_IMAGE_URY";
28+
29+
let imageFile = "YOUR_IMAGE_FOLDER_AND_PATH";
30+
31+
let resultAppend = await pdfApi.postInsertImage (fileName, pageNum, posLeftDownX, posLeftDownY, posRighUptX, posRightUpY, imageFile, null, null, null);
32+
33+
console.log(resultAppend.response);
34+
35+
console.log(resultAppend.body);

UsesCases/Images/get/get.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2+
// 2. Create an object to connect to the Pdf.Cloud API
3+
// 3. Upload your document file
4+
// 4. Perform the rtreiving image Id from Pdf document using getIimages function
5+
// 5. Perform the extracting image from Pdf document using getImage function and image ID value
6+
// 6. Check result and perform some actions with result.body object
7+
// All values of variables starting with "YOUR_****" should be replaced by real user values
8+
9+
10+
var PdfApi = require('asposepdfcloud');
11+
12+
var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json');
13+
14+
var AppSID = configProps.app_sid;
15+
var AppKey = configProps.api_key;
16+
var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true };
17+
18+
pdfApi = new PdfApi(AppSID, AppKey);
19+
20+
let fileName = "YOUR_PDF_DOCUMENT.pdf";
21+
22+
let resultImageId = await pdfApi.getImages(fileName, 1, null, null);
23+
const imageID = resultImageId.body.images.list[0].id;
24+
25+
let resultImage = await pdfApi.getImage(fileName, imageID, null, null);
26+
27+
console.log(resultImage.response);
28+
29+
console.log(resultImage.body);

UsesCases/Images/get_common.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2+
// 2. Create an object to connect to the Pdf.Cloud API
3+
// 3. Upload your document file
4+
// 4. Perform the retreiving image Id from Pdf document using getIimages() function
5+
// 5. Perform the reading image from Pdf document using getImage() function and image ID value
6+
// 6. Check result and perform some actions with result.body object
7+
// 7. Perform extrating image in Png format from Pdf document into local folder using putImageExtractAsPng() function and image ID value
8+
// 8. Check result and perform some actions with result.body object
9+
// All values of variables starting with "YOUR_****" should be replaced by real user values
10+
11+
12+
var PdfApi = require('asposepdfcloud');
13+
14+
var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json');
15+
16+
var AppSID = configProps.app_sid;
17+
var AppKey = configProps.api_key;
18+
var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true };
19+
20+
pdfApi = new PdfApi(AppSID, AppKey);
21+
22+
let fileName = "YOUR_PDF_DOCUMENT.pdf";
23+
24+
let resultImageId = await pdfApi.getImages(fileName, 1, null, null);
25+
const imageID = resultImageId.body.images.list[0].id;
26+
27+
let resultImage = await pdfApi.getImage(fileName, imageID, null, null);
28+
29+
console.log(resultImage.response);
30+
31+
console.log(resultImage.body);
32+
33+
let extractResult = await pdfApi.putImageExtractAsPng(fileName, imageID, 512, 512, null, null, 'YOUR_DESTINATION_FOLDER');
34+
35+
console.log(extractResult.response);
36+
37+
console.log(extractResult.body);

UsesCases/Images/remove/remove.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2+
// 2. Create an object to connect to the Pdf.Cloud API
3+
// 3. Upload your document file
4+
// 4. Perform the rtreiving image Id from Pdf document using getIimages function
5+
// 5. Delete image from Pdf document using deleteImage function and image ID value
6+
// 6. Check result and perform some actions with result.body object
7+
// All values of variables starting with "YOUR_****" should be replaced by real user values
8+
9+
var PdfApi = require('asposepdfcloud');
10+
11+
var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json');
12+
13+
var AppSID = configProps.app_sid;
14+
var AppKey = configProps.api_key;
15+
var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true };
16+
17+
pdfApi = new PdfApi(AppSID, AppKey);
18+
19+
let fileName = "YOUR_PDF_DOCUMENT.pdf";
20+
21+
let resultImageId = await pdfApi.getImages(fileName, 1, null, null);
22+
const imageID = resultImageId.body.images.list[0].id;
23+
24+
let deleteResult = await pdfApi.deleteImage(fileName, imageID, null, null);
25+
26+
console.log(deleteResult.response);
27+
28+
console.log(deleteResult.body);

UsesCases/Images/update/update.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// 1. Load your Application Secret and Key from the JSON file or set credentials in another way
2+
// 2. Create an object to connect to the Pdf.Cloud API
3+
// 3. Upload your document file
4+
// 4. Perform the retreiving image Id from Pdf document using getIimages() function
5+
// 5. Perform the unpdating image in Pdf document using putReplaceImage() function, image ID value and new image file
6+
// 6. Check result and perform some actions with result.body object
7+
// All values of variables starting with "YOUR_****" should be replaced by real user values
8+
9+
10+
var PdfApi = require('asposepdfcloud');
11+
12+
var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json');
13+
14+
var AppSID = configProps.app_sid;
15+
var AppKey = configProps.api_key;
16+
var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true };
17+
18+
pdfApi = new PdfApi(AppSID, AppKey);
19+
20+
let fileName = "YOUR_PDF_DOCUMENT.pdf";
21+
22+
let resultImageId = await pdfApi.getImages(fileName, 1, null, null);
23+
const imageID = resultImageId.body.images.list[0].id;
24+
25+
let resultUpdate = await pdfApi.putReplaceImage (fileName, imageID, "YOUR_NEW_IMAGE_FOLDER_AND_NAME", null, null, null);
26+
27+
console.log(resultUpdate.response);
28+
29+
console.log(resultUpdate.body);

0 commit comments

Comments
 (0)