From dc784870745204f5d9c52ed5d8ae13d732f8aa9a Mon Sep 17 00:00:00 2001 From: Dmitriy-Xawstov Date: Tue, 19 Nov 2024 20:32:32 +0200 Subject: [PATCH] implemented_attachments_images --- UsesCases/Attachments/add/add.js | 28 +++++++++++++++++++ UsesCases/Attachments/get/get.js | 40 +++++++++++++++++++++++++++ UsesCases/Attachments/get_download.js | 38 +++++++++++++++++++++++++ UsesCases/Images/add/add.js | 35 +++++++++++++++++++++++ UsesCases/Images/get/get.js | 29 +++++++++++++++++++ UsesCases/Images/get_common.js | 37 +++++++++++++++++++++++++ UsesCases/Images/remove/remove.js | 28 +++++++++++++++++++ UsesCases/Images/update/update.js | 29 +++++++++++++++++++ 8 files changed, 264 insertions(+) create mode 100644 UsesCases/Attachments/add/add.js create mode 100644 UsesCases/Attachments/get/get.js create mode 100644 UsesCases/Attachments/get_download.js create mode 100644 UsesCases/Images/add/add.js create mode 100644 UsesCases/Images/get/get.js create mode 100644 UsesCases/Images/get_common.js create mode 100644 UsesCases/Images/remove/remove.js create mode 100644 UsesCases/Images/update/update.js diff --git a/UsesCases/Attachments/add/add.js b/UsesCases/Attachments/add/add.js new file mode 100644 index 00000000..5e372920 --- /dev/null +++ b/UsesCases/Attachments/add/add.js @@ -0,0 +1,28 @@ +// 1. Load your Application Secret and Key from the JSON file or set credentials in another way +// 2. Create an object to connect to the Pdf.Cloud API +// 3. Create an AttachmentInfo object, which maust be inserted into Pdf file +// 4. Perform append attachment into Pdf document using postAddDocumentAttachment() function and AttachmentImfo object +// 5. Check result and perform some actions with result.body object +// All values of variables starting with "YOUR_****" should be replaced by real user values + +var PdfApi = require('asposepdfcloud'); + +var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json'); + +var AppSID = configProps.app_sid; +var AppKey = configProps.api_key; +var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true }; + +var pdfApi = new PdfApi(config); + +const attachment = new AttachmentInfo(); +attachment.name = "YOUR_ATTACHMENT_NAME"; +attachment.path = "YOUR_ATTACHMENT_PATH"; +attachment.description = "YOUR_ATTACHMENT_DESCRIPTION"; +attachment.mimeType = "type/YOUR_SUBTYPE"; + +let result = await pdfApi.postAddDocumentAttachment ("YOUR_PDF_FILE_NAME.pdf", attachment, null, null); + +console.log(result.response); + +console.log(result.body); \ No newline at end of file diff --git a/UsesCases/Attachments/get/get.js b/UsesCases/Attachments/get/get.js new file mode 100644 index 00000000..e3fe00d1 --- /dev/null +++ b/UsesCases/Attachments/get/get.js @@ -0,0 +1,40 @@ +// 1. Load your Application Secret and Key from the JSON file or set credentials in another way +// 2. Create a Storage API object for uploading Pdf file +// 3. Create an object to connect to the Pdf.Cloud API +// 4. Upload your document file using PutCreate() function of the Storage API object +// 5. To extract attachments from a PDF document, using getDocumentAttachments() function +// 6. Check result and perform some actions with result.body object +// All values of variables starting with "YOUR_****" should be replaced by real user values + +var fs = require('fs'); +var PdfApi = require('asposepdfcloud'); +var StorageApi = require('asposestoragecloud'); + +var configProps = require('YOUR_CONFIG_FOLDER/YOUR_CONFIG.json'); + +var data_path = 'YOUR_DATA_FOLDER_WITH_PATH/'; + +var AppSID = configProps.app_sid; +var AppKey = configProps.api_key; +var outFolder = configProps.out_folder; +var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true }; + +var storageApi = new StorageApi(config); + +var pdfApi = new PdfApi(config); + +var fileName = "YOUR_ATTACHMENT_FILE_NAME"; +var name = fileName + ".pdf"; +var attachmentIndex = 1; + + +storageApi.PutCreate(name, null, null, data_path + name , async function(responseMessage) { + + assert.equal(responseMessage.status, 'OK'); + + let result = await pdfApi.getDocumentAttachments(name, attachmentIndex, null, null); + + console.log(result.response); + + console.log(result.body); +}); \ No newline at end of file diff --git a/UsesCases/Attachments/get_download.js b/UsesCases/Attachments/get_download.js new file mode 100644 index 00000000..492c3751 --- /dev/null +++ b/UsesCases/Attachments/get_download.js @@ -0,0 +1,38 @@ +// 1. Load your Application Secret and Key from the JSON file or set credentials in another way +// 2. Create a Storage API object for uploading Pdf file +// 3. Create an object to connect to the Pdf.Cloud API +// 4. Upload your document file using PutCreate() function of the Storage API object +// 5. To extract attachments from a PDF document, using getDocumentAttachmentByIndex() function +// 6. Download the result if need it +// All values of variables starting with "YOUR_****" should be replaced by real user values + +var fs = require('fs'); +var PdfApi = require('asposepdfcloud'); +var StorageApi = require('asposestoragecloud'); + +var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json'); + +var data_path = 'YOUR_DATA_FOLDER_WITH_PATH/'; + +var AppSID = configProps.app_sid; +var AppKey = configProps.api_key; +var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true }; + +var storageApi = new StorageApi(config); + +var pdfApi = new PdfApi(config); + +var fileName = "YOUR_ATTACHMENT_FILE_NAME"; +var name = fileName + ".pdf"; +var attachmentIndex = 1; + +storageApi.PutCreate(name, null, null, data_path + name , async function(responseMessage) +{ + + let result = await pdfApi.getDownloadDocumentAttachmentByIndex(name, attachmentIndex, null, null); + + var outfilename = fileName + attachmentIndex + ".text"; + var writeStream = fs.createWriteStream(data_path + outfilename); + writeStream.write(result.body); + +}); \ No newline at end of file diff --git a/UsesCases/Images/add/add.js b/UsesCases/Images/add/add.js new file mode 100644 index 00000000..9a184609 --- /dev/null +++ b/UsesCases/Images/add/add.js @@ -0,0 +1,35 @@ +// 1. Load your Application Secret and Key from the JSON file or set credentials in another way +// 2. Create an object to connect to the Pdf.Cloud API +// 3. Initialize neccessary values for append image +// 4. Perform the inserting image in Pdf document using postInsertImage() function and new image file initialized values +// 6. Check result and perform some actions with result.body object +// All values of variables starting with "YOUR_****" should be replaced by real user values + + +var PdfApi = require('asposepdfcloud'); + +var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json'); + +var AppSID = configProps.app_sid; +var AppKey = configProps.api_key; +var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true }; + +pdfApi = new PdfApi(AppSID, AppKey); + +let fileName = "YOUR_PDF_DOCUMENT.pdf"; + +let pageNum = "YOUR_PAGE_NUMBER"; + +let posLeftDownX = "YOUR_IMAGE_LLX"; +let posLeftDownY = "YOUR_IMAGE_LLY"; + +let posRighUptX = "YOUR_IMAGE_URX"; +let posRightUpY = "YOUR_IMAGE_URY"; + +let imageFile = "YOUR_IMAGE_FOLDER_AND_PATH"; + +let resultAppend = await pdfApi.postInsertImage (fileName, pageNum, posLeftDownX, posLeftDownY, posRighUptX, posRightUpY, imageFile, null, null, null); + +console.log(resultAppend.response); + +console.log(resultAppend.body); \ No newline at end of file diff --git a/UsesCases/Images/get/get.js b/UsesCases/Images/get/get.js new file mode 100644 index 00000000..5acfc53e --- /dev/null +++ b/UsesCases/Images/get/get.js @@ -0,0 +1,29 @@ +// 1. Load your Application Secret and Key from the JSON file or set credentials in another way +// 2. Create an object to connect to the Pdf.Cloud API +// 3. Upload your document file +// 4. Perform the rtreiving image Id from Pdf document using getIimages function +// 5. Perform the extracting image from Pdf document using getImage function and image ID value +// 6. Check result and perform some actions with result.body object +// All values of variables starting with "YOUR_****" should be replaced by real user values + + +var PdfApi = require('asposepdfcloud'); + +var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json'); + +var AppSID = configProps.app_sid; +var AppKey = configProps.api_key; +var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true }; + +pdfApi = new PdfApi(AppSID, AppKey); + +let fileName = "YOUR_PDF_DOCUMENT.pdf"; + +let resultImageId = await pdfApi.getImages(fileName, 1, null, null); +const imageID = resultImageId.body.images.list[0].id; + +let resultImage = await pdfApi.getImage(fileName, imageID, null, null); + +console.log(resultImage.response); + +console.log(resultImage.body); \ No newline at end of file diff --git a/UsesCases/Images/get_common.js b/UsesCases/Images/get_common.js new file mode 100644 index 00000000..ce393de2 --- /dev/null +++ b/UsesCases/Images/get_common.js @@ -0,0 +1,37 @@ +// 1. Load your Application Secret and Key from the JSON file or set credentials in another way +// 2. Create an object to connect to the Pdf.Cloud API +// 3. Upload your document file +// 4. Perform the retreiving image Id from Pdf document using getIimages() function +// 5. Perform the reading image from Pdf document using getImage() function and image ID value +// 6. Check result and perform some actions with result.body object +// 7. Perform extrating image in Png format from Pdf document into local folder using putImageExtractAsPng() function and image ID value +// 8. Check result and perform some actions with result.body object +// All values of variables starting with "YOUR_****" should be replaced by real user values + + +var PdfApi = require('asposepdfcloud'); + +var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json'); + +var AppSID = configProps.app_sid; +var AppKey = configProps.api_key; +var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true }; + +pdfApi = new PdfApi(AppSID, AppKey); + +let fileName = "YOUR_PDF_DOCUMENT.pdf"; + +let resultImageId = await pdfApi.getImages(fileName, 1, null, null); +const imageID = resultImageId.body.images.list[0].id; + +let resultImage = await pdfApi.getImage(fileName, imageID, null, null); + +console.log(resultImage.response); + +console.log(resultImage.body); + +let extractResult = await pdfApi.putImageExtractAsPng(fileName, imageID, 512, 512, null, null, 'YOUR_DESTINATION_FOLDER'); + +console.log(extractResult.response); + +console.log(extractResult.body); \ No newline at end of file diff --git a/UsesCases/Images/remove/remove.js b/UsesCases/Images/remove/remove.js new file mode 100644 index 00000000..de939502 --- /dev/null +++ b/UsesCases/Images/remove/remove.js @@ -0,0 +1,28 @@ +// 1. Load your Application Secret and Key from the JSON file or set credentials in another way +// 2. Create an object to connect to the Pdf.Cloud API +// 3. Upload your document file +// 4. Perform the rtreiving image Id from Pdf document using getIimages function +// 5. Delete image from Pdf document using deleteImage function and image ID value +// 6. Check result and perform some actions with result.body object +// All values of variables starting with "YOUR_****" should be replaced by real user values + +var PdfApi = require('asposepdfcloud'); + +var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json'); + +var AppSID = configProps.app_sid; +var AppKey = configProps.api_key; +var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true }; + +pdfApi = new PdfApi(AppSID, AppKey); + +let fileName = "YOUR_PDF_DOCUMENT.pdf"; + +let resultImageId = await pdfApi.getImages(fileName, 1, null, null); +const imageID = resultImageId.body.images.list[0].id; + +let deleteResult = await pdfApi.deleteImage(fileName, imageID, null, null); + +console.log(deleteResult.response); + +console.log(deleteResult.body); \ No newline at end of file diff --git a/UsesCases/Images/update/update.js b/UsesCases/Images/update/update.js new file mode 100644 index 00000000..361612d8 --- /dev/null +++ b/UsesCases/Images/update/update.js @@ -0,0 +1,29 @@ +// 1. Load your Application Secret and Key from the JSON file or set credentials in another way +// 2. Create an object to connect to the Pdf.Cloud API +// 3. Upload your document file +// 4. Perform the retreiving image Id from Pdf document using getIimages() function +// 5. Perform the unpdating image in Pdf document using putReplaceImage() function, image ID value and new image file +// 6. Check result and perform some actions with result.body object +// All values of variables starting with "YOUR_****" should be replaced by real user values + + +var PdfApi = require('asposepdfcloud'); + +var configProps = require('YOUR_CONFIG_FFOLDER/YOUR_CONFIG.json'); + +var AppSID = configProps.app_sid; +var AppKey = configProps.api_key; +var config = { 'appSid': AppSID, 'apiKey': AppKey, 'debug' : true }; + +pdfApi = new PdfApi(AppSID, AppKey); + +let fileName = "YOUR_PDF_DOCUMENT.pdf"; + +let resultImageId = await pdfApi.getImages(fileName, 1, null, null); +const imageID = resultImageId.body.images.list[0].id; + +let resultUpdate = await pdfApi.putReplaceImage (fileName, imageID, "YOUR_NEW_IMAGE_FOLDER_AND_NAME", null, null, null); + +console.log(resultUpdate.response); + +console.log(resultUpdate.body); \ No newline at end of file