diff --git a/UsesCases/Images/add/add.js b/UsesCases/Images/add/add.js new file mode 100644 index 00000000..de171fc5 --- /dev/null +++ b/UsesCases/Images/add/add.js @@ -0,0 +1,52 @@ +// 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 + +import credentials from "./credentials.json" with { type: "json" }; +import fs from 'node:fs/promises'; +import { PdfApi } from "asposepdfcloud"; + +const LOCAL_PATH = "C:\\Samples\\"; +const FILE_NAME = "Sample-Document"; +const FILE_EXT = ".pdf"; + +const STORAGE_PATH = "YOUR_REMOTE_PATH/"; +const PDF_DOCUMENT_NAME = FILE_NAME + FILE_EXT; + +const IMAGE_FILE_NAME = "YOUR_IMAGE_FOLDER_AND_PATH"; + +const pdfApi = new PdfApi(credentials.id, credentials.key); + +const storage = null; + +const pdfFileData = fs.readFileSync(LOCAL_PATH + PDF_DOCUMENT_NAME); +await api.uploadFile(STORAGE_PATH + PDF_DOCUMENT_NAME, pdfFileData, storage); + +const folder = "Documents"; + +const destFolder = "Images"; + +const pageNum = 1; + +const llx = 10; +const lly = 10; + +const urx = 100; +const ury = 100; + +const resultAppend = await pdfApi.postInsertImage(STORAGE_PATH + PDF_DOCUMENT_NAME, pageNum, llx, lly, urx, ury, IMAGE_FILE_NAME, storage, folder, null); + +if (resultAppend.body.status == 200) +{ + const newPdfData = pdfApi.downloadFile(STORAGE_PATH + PDF_DOCUMENT_NAME, storage); + + const filePath = "YOUR_LOCAL_OUTPUT_FOLDER/ResultInsertImageFile.pdf"; + + await fs.writeFile(filePath, newPdfData.body); + console.log("downloaded: " + filePath); +} +else + console.log("Unable to insert image into the file!!!"); \ 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..5c535d3d --- /dev/null +++ b/UsesCases/Images/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 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 + + +import credentials from "./credentials.json" with { type: "json" }; +import fs from 'node:fs/promises'; +import { PdfApi } from "asposepdfcloud"; + +const LOCAL_PATH = "C:\\Samples\\"; +const FILE_NAME = "Sample-Document"; +const FILE_EXT = ".pdf"; + +const STORAGE_PATH = "YOUR_REMOTE_PATH/"; +const PDF_DOCUMENT_NAME = FILE_NAME + FILE_EXT; + +const pdfApi = new PdfApi(credentials.id, credentials.key); + +const storage = null; + +const pdfFileData = fs.readFileSync(LOCAL_PATH + PDF_DOCUMENT_NAME); +await api.uploadFile(STORAGE_PATH + PDF_DOCUMENT_NAME, pdfFileData, storage); + +const folder = "Documents"; + +let resultImageId = await pdfApi.getImages(fileName, 1, storage, folder); +const imageID = resultImageId.body.images.list[0].id; + +let resultImage = await pdfApi.getImage(fileName, imageID, storage, folder); + +await Promise.all( + resultImage.body.images.map(async (image, index) => { + const filePath = "YOUR_LOCAL_OUTPUT_PATH/image_" + FILE_NAME + "_" + (index + 1) + ".jpg"; + fs.writeFileSync(filePath, image.links[0].href); + }) +); \ 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..39d12003 --- /dev/null +++ b/UsesCases/Images/get_common.js @@ -0,0 +1,42 @@ +// 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 + +import credentials from "./credentials.json" with { type: "json" }; +import fs from 'node:fs/promises'; +import { PdfApi } from "asposepdfcloud"; + +const LOCAL_PATH = "C:\\Samples\\"; +const FILE_NAME = "Sample-Document"; +const FILE_EXT = ".pdf"; + +const PDF_DOCUMENT_NAME = FILE_NAME + FILE_EXT; + +const pdfApi = new PdfApi(credentials.id, credentials.key); + +const storage = null; + +const width = 512; + +const heigth = 512; + +const folder = "Documents"; + +const destFolder = "Images"; + +const pdfFileData = fs.readFileSync(LOCAL_PATH + PDF_DOCUMENT_NAME); +await api.uploadFile(PDF_DOCUMENT_NAME, pdfFileData, storage); + +const resultImageId = await pdfApi.getImages(PDF_DOCUMENT_NAME, 1, storage, folder); + +const imageID = resultImageId.body.images.list[0].id; + +const extractResult = await pdfApi.putImageExtractAsPng(PDF_DOCUMENT_NAME, imageID, width, heigth, storage, folder, destFolder); + +console.log(extractResult.body.status); \ 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..eb46fca7 --- /dev/null +++ b/UsesCases/Images/remove/remove.js @@ -0,0 +1,44 @@ +// 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 + +import credentials from "./credentials.json" with { type: "json" }; +import fs from 'node:fs/promises'; +import { PdfApi } from "asposepdfcloud"; + +const LOCAL_PATH = "C:\\Samples\\"; +const FILE_NAME = "Sample-Document"; +const FILE_EXT = ".pdf"; + +const STORAGE_PATH = "YOUR_REMOTE_PATH/"; +const PDF_DOCUMENT_NAME = FILE_NAME + FILE_EXT; + +const pdfApi = new PdfApi(credentials.id, credentials.key); + +const storage = null; + +const folder = "Documents"; + +const pdfFileData = fs.readFileSync(LOCAL_PATH + PDF_DOCUMENT_NAME); +await api.uploadFile(STORAGE_PATH + PDF_DOCUMENT_NAME, pdfFileData, storage); + +let resultImageId = await pdfApi.getImages(fileName, 1, storage, folder); +const imageID = resultImageId.body.images.list[0].id; + +let resultDelete = await pdfApi.deleteImage(STORAGE_PATH + PDF_DOCUMENT_NAME, imageID, storage, folder); + +if (resultAppend.body.status == 200) +{ + const newPdfData = pdfApi.downloadFile(STORAGE_PATH + PDF_DOCUMENT_NAME, storage); + + const filePath = "YOUR_LOCAL_OUTPUT_FOLDER/ResultDeleteImageFile.pdf"; + + await fs.writeFile(filePath, newPdfData.body); + console.log("downloaded: " + filePath); +} +else + console.log("Unable to delete image from the file!!!"); \ 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..8cacbc31 --- /dev/null +++ b/UsesCases/Images/update/update.js @@ -0,0 +1,46 @@ +// 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 + +import credentials from "./credentials.json" with { type: "json" }; +import fs from 'node:fs/promises'; +import { PdfApi } from "asposepdfcloud"; + +const LOCAL_PATH = "C:\\Samples\\"; +const FILE_NAME = "Sample-Document"; +const FILE_EXT = ".pdf"; + +const STORAGE_PATH = "YOUR_REMOTE_PATH/"; +const PDF_DOCUMENT_NAME = FILE_NAME + FILE_EXT; + +const IMAGE_FILE_NAME = "YOUR_IMAGE_FOLDER_AND_PATH"; + +const pdfApi = new PdfApi(credentials.id, credentials.key); + +const storage = null; + +const pdfFileData = fs.readFileSync(LOCAL_PATH + PDF_DOCUMENT_NAME); +await api.uploadFile(STORAGE_PATH + PDF_DOCUMENT_NAME, pdfFileData, storage); + +const folder = "Documents"; + +let resultImageId = await pdfApi.getImages(fileName, 1, storage, folder); +const imageID = resultImageId.body.images.list[0].id; + +let resultUpdate = await pdfApi.putReplaceImage(fileName, imageID, IMAGE_FILE_NAME, storage, folder, null); + +if (resultAppend.body.status == 200) +{ + const dropPdfData = pdfApi.downloadFile(STORAGE_PATH + PDF_DOCUMENT_NAME, storage); + + const filePath = "YOUR_LOCAL_OUTPUT_FOLDER/ResultDeleteImageFile.pdf"; + + await fs.writeFile(filePath, dropPdfData.body); + console.log("downloaded: " + filePath); +} +else + console.log("Unable to insert image into the file!!!"); \ No newline at end of file