diff --git a/UsesCases/Merge/merge.js b/UsesCases/Merge/merge.js new file mode 100644 index 00000000..ecf1a319 --- /dev/null +++ b/UsesCases/Merge/merge.js @@ -0,0 +1,73 @@ +/** + * Merging the PDF documents using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF files from the local file system. + * 3. Uploads the PDF files to the Aspose.PDF Cloud storage. + * 4. Merging the PDF documents using the Aspose.PDF Cloud API. + * 5. Logs the result to the console. + * + */ + +// Import necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); +const { MergeDocuments } = require("asposepdfcloud/src/models/mergeDocuments"); + +/** + * Merging the PDF documents using the Aspose.PDF Cloud API. + * + * @returns {Promise} A Promise that resolves when the splitting document is complete. + */ +async function mergeDocument() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + // const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + + const fileName = "merged.pdf"; + // Set the document names to merge. + const fileNames = ["4pages.pdf", "alfa.pdf"]; + // Use default storage (null indicates default storage). + const storage = null; + // Set the folder where the document is stored. + const folder = "Documents"; + + // Initialize merge documents request. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/MergeDocuments.md + const mergeRequest = new MergeDocuments(); + mergeRequest.list = []; + await Promise.all( + fileNames.map(async fileName => + { + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + await api.uploadFile(folder + "/" + fileName, buffer, storage); + // Push uploaded file name to merge request. + mergeRequest.list.push(folder + "/" + fileName); + }) + ); + + // Swagger documentation available at: + // https://reference.aspose.cloud/pdf/#/Merge/PutMergeDocuments + // Merge PDF documents using PDF Cloud API. + const result = await api.putMergeDocuments( + fileName, + mergeRequest, + storage, + folder); + + // Log the response to console. + console.log(result.body.status); + // Download the PDF file from cloud storage. + const file = await api.downloadFile(folder + result.body.document.links[0].href, storage); + const filePath = `testOutput/merged.pdf`; + // Write the file to the local file system. + fs.writeFileSync(filePath, file.body); + console.log("downloaded: " + filePath); +} + +// Execute the mergeDocument function. +mergeDocument(); diff --git a/UsesCases/Metadata/add/add.js b/UsesCases/Metadata/add/add.js new file mode 100644 index 00000000..2879cab7 --- /dev/null +++ b/UsesCases/Metadata/add/add.js @@ -0,0 +1,68 @@ +/** + * Add the XMP metadata property to a PDF document using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Add the XMP metadata property using Aspose.PDF Cloud API. + * 5. Read an updated XMP metadata from pdf document using the Aspose.PDF Cloud API. + * 6. Log to the console that the XMP metadata property was added. + * + */ + +// Import the necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Add the xmp metadata property to the PDF document using the Aspose.PDF Cloud API. + * + * @returns {Promise} A promise that resolves when the xmp metadata property is completed adding. + */ +async function addXmpMetadataProperty() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + + // Set the PDF document name. + const fileName = "4pages.pdf"; + // Set the folder where the document is stored. + const folder = "Documents"; + // Set storage name (null indicates default storage). + const storage = null; + // Set the password if the document is password-protected. + const password = null; + // Set the XMP metadata property name. + const xmpMetadataProperty = "pdf:Prop"; + + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + await api.uploadFile(folder + "/" +fileName, buffer, storage) + + // Create instance of XmpMetadataProperty for pdf:Prop. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadataProperty.md + var pdfPropProperty = { + key: xmpMetadataProperty, + value: "PropValue", + namespaceUri: "http://ns.adobe.com/pdf/1.3/" + }; + // Create an instance of XmpMetadata. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadata.md + const xmpMetadata = { + properties: [pdfPropProperty] + }; + // Update the XMP metadata. + const result = await api.postXmpMetadata(fileName, xmpMetadata, folder, storage, password); + console.log(result.body.status); + + // Read XMP metadata from PDF document. + metadata = await api.getXmpMetadataJson(fileName, folder, storage, password); + // Log XMP metadata property was added. + pdfPropProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty); + console.log("Added xmpMetadataProperty: " + pdfPropProperty.key + "=" + pdfPropProperty.value); +} + +// Execute the addXmpMetadataProperty function +addXmpMetadataProperty(); diff --git a/UsesCases/Metadata/get/get.js b/UsesCases/Metadata/get/get.js new file mode 100644 index 00000000..a321e08b --- /dev/null +++ b/UsesCases/Metadata/get/get.js @@ -0,0 +1,53 @@ +/** + * Read the XMP metadata from a PDF document using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Read the XMP metadata from pdf document using the Aspose.PDF Cloud API. + * 5. Log to the console the XMP metadata properties. + * + */ + +// Import the necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Reads xmp metadata from a PDF document using the Aspose.PDF Cloud API. + * + * @returns {Promise} A promise that resolves when the xmp metadata reading completes. + */ +async function getXmpMetadataProperty() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + + // Set the PDF document name. + const fileName = "4pages.pdf"; + // Set the folder where the document is stored. + const folder = "Documents"; + // Set storage name (null indicates default storage). + const storage = null; + // Set the password if the document is password-protected. + const password = null; + + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + await api.uploadFile(folder + "/" +fileName, buffer, storage) + + // Read XMP metadata from PDF document. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadata.md + const metadata = await api.getXmpMetadataJson(fileName, folder, storage, password); + // Log metadata to the console. + console.log("XMP metadata:"); + metadata.body.properties.forEach(property => + { + console.log(" " + property.key + " = " + property.value); + }); +} + +// Execute the getXmpMetadataProperty function +getXmpMetadataProperty(); diff --git a/UsesCases/Metadata/remove/remove.js b/UsesCases/Metadata/remove/remove.js new file mode 100644 index 00000000..02f0fbba --- /dev/null +++ b/UsesCases/Metadata/remove/remove.js @@ -0,0 +1,70 @@ +/** + * Remove the XMP metadata property from a PDF document using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Read the XMP metadata from pdf document using the Aspose.PDF Cloud API. + * 5. Remove the XMP metadata property using the Aspose.PDF Cloud API. + * 6. Read an updated XMP metadata from pdf document using the Aspose.PDF Cloud API. + * 7. Log to the console that the XMP metadata property was removed. + * + */ + +// Import the necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Remove xmp metadata property from a PDF document using the Aspose.PDF Cloud API. + * + * @returns {Promise} A promise that resolves when the xmp metadata property deletion completes. + */ +async function removeXmpMetadataProperty() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + + // Set the PDF document name. + const fileName = "4pages.pdf"; + // Set the folder where the document is stored. + const folder = "Documents"; + // Set storage name (null indicates default storage). + const storage = null; + // Set the password if the document is password-protected. + const password = null; + // Set the XMP metadata property name. + const xmpMetadataProperty = "xmp:CreatorTool"; + + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + await api.uploadFile(folder + "/" +fileName, buffer, storage) + + // Read XMP metadata from pdf document. + var metadata = await api.getXmpMetadataJson(fileName, folder, storage, password); + // Find the creator property. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadataProperty.md + var creatorToolProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty); + // Set value to null to remove property. + creatorToolProperty.value = null; + + // Create an instance of XmpMetadata. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadata.md + const xmpMetadata = { + properties: [creatorToolProperty] + }; + // Update the XMP metadata. + const result = await api.postXmpMetadata(fileName, xmpMetadata, folder, storage, password); + console.log(result.body.status); + + // Read XMP metadata from PDF document. + metadata = await api.getXmpMetadataJson(fileName, folder, storage, password); + // Log XMP metadata property was removed. + creatorToolProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty); + console.log("Removed xmpMetadataProperty: " + xmpMetadataProperty); +} + +// Execute the removeXmpMetadataProperty function +removeXmpMetadataProperty(); diff --git a/UsesCases/Metadata/update/update.js b/UsesCases/Metadata/update/update.js new file mode 100644 index 00000000..907097fc --- /dev/null +++ b/UsesCases/Metadata/update/update.js @@ -0,0 +1,70 @@ +/** + * Update the XMP metadata property from a PDF document using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Read the XMP metadata from pdf document using the Aspose.PDF Cloud API. + * 5. Update the XMP metadata property using the Aspose.PDF Cloud API. + * 6. Read an updated XMP metadata from pdf document using the Aspose.PDF Cloud API. + * 7. Log to the console that the XMP metadata property was updated. + * + */ + +// Import the necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Update xmp metadata property from a PDF document using the Aspose.PDF Cloud API. + * + * @returns {Promise} A promise that resolves when the xmp metadata property update completes. + */ +async function updateXmpMetadataProperty() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + + // Set the PDF document name. + const fileName = "4pages.pdf"; + // Set the folder where the document is stored. + const folder = "Documents"; + // Set storage name (null indicates default storage). + const storage = null; + // Set the password if the document is password-protected. + const password = null; + // Set the XMP metadata property name. + const xmpMetadataProperty = "dc:title"; + + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + await api.uploadFile(folder + "/" +fileName, buffer, storage) + + // Read XMP metadata from pdf document. + var metadata = await api.getXmpMetadataJson(fileName, folder, storage, password); + // Find the title property. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadataProperty.md + var titleProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty); + // Update the title property. + titleProperty.value = "New title"; + + // Create an instance of XmpMetadata. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadata.md + const xmpMetadata = { + properties: [titleProperty] + }; + // Update the XMP metadata. + const result = await api.postXmpMetadata(fileName, xmpMetadata, folder, storage, password); + console.log(result.body.status); + + // Read XMP metadata from PDF document. + metadata = await api.getXmpMetadataJson(fileName, folder, storage, password); + // Log XMP metadata property was updated. + titleProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty); + console.log("Updated xmpMetadataProperty: " + titleProperty.key + "=" + titleProperty.value); +} + +// Execute the updateXmpMetadataProperty function +updateXmpMetadataProperty(); diff --git a/UsesCases/Split/parts/parts.js b/UsesCases/Split/parts/parts.js new file mode 100644 index 00000000..4d64de8f --- /dev/null +++ b/UsesCases/Split/parts/parts.js @@ -0,0 +1,90 @@ +/** + * Splitting the PDF document to pages using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Splitting document to pages using the Aspose.PDF Cloud API. + * 5. Write the split result to the local file system. + * + */ + +// Import necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Splitting the PDF document per pages using the Aspose.PDF Cloud API. + * + * @returns {Promise} A Promise that resolves when the splitting document is complete. + */ +async function splitDocumentRanges() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + // const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + + // Set the document name. + const fileName = "4pages.pdf"; + // Set the page ranges for splitting. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/SplitRangePdfOptions.md + const options = + { + pageRanges: [ + // first and second pages. + { + to: 2 + }, + // third and fourth pages. + { + from: 3 + }, + // second and third pages. + { + from: 2, + to: 3 + }, + // first page. + { + from: 1, + to: 1 + } + ] + }; + // Use default storage (null indicates default storage). + const storage = null; + // Set the folder where the document is stored. + const folder = "Documents"; + + // Read the file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload the file to cloud storage. + await api.uploadFile(folder + "/" + fileName, buffer, storage) + + // Swagger documentation available at: + // https://reference.aspose.cloud/pdf/#/Document/PostSplitRangePdfDocument + // Split the PDF document to page ranges. + const result = await api.postSplitRangePdfDocument( + fileName, + options, + storage, + folder); + + // Log the response to console. + console.log(result.body.status); + // Write the split result to the local file system. + for (const [index, page] of result.body.result.documents.entries()) + { + const pageRange = options.pageRanges[index]; + // Download the PDF file from cloud storage. + const file = await api.downloadFile(page.href, storage); + const filePath = `testOutput/pageRange${pageRange.from ?? 1}_${pageRange.to ?? result.body.result.documents.length}.pdf`; + // Write the file to the local file system. + fs.writeFileSync(filePath, file.body); + console.log(index + 1 + ") " + filePath); + } +} + +// Execute the splitDocumentRanges function. +splitDocumentRanges(); diff --git a/UsesCases/Split/single/single.js b/UsesCases/Split/single/single.js new file mode 100644 index 00000000..955b8e7c --- /dev/null +++ b/UsesCases/Split/single/single.js @@ -0,0 +1,73 @@ +/** + * Splitting the PDF document to pages using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Splitting document to pages using the Aspose.PDF Cloud API. + * 5. Write the split result to the local file system. + * + */ + +// Import necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Splitting the PDF document per pages using the Aspose.PDF Cloud API. + * + * @returns {Promise} A Promise that resolves when the splitting document is complete. + */ +async function splitDocument() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + // const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + + // Set the document name. + const fileName = "4pages.pdf"; + // Set the start page number. + const pageFrom = 2; + // Set the end page number same as pageFrom. + const pageTo = 2; + // Set the resulting documents format. + // Available formats are: PDF, PDFA1A, PDFA1B, PDFA3A, PDFA3B, DOC, DOCX, XLS, XPS, TIFF, SVG, JPEG, JPG, PNG, EMF, BMP, GIF, PPTX, EPUB. + const format = "PDF"; + // Use default storage (null indicates default storage). + const storage = null; + // Set the folder where the document is stored. + const folder = "Documents"; + + // Read the file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload the file to cloud storage. + await api.uploadFile(folder + "/" + fileName, buffer, storage) + + // Swagger documentation available at: + // https://reference.aspose.cloud/pdf/#/Document/PostSplitDocument + // Split the PDF document to single page. + const result = await api.postSplitDocument( + fileName, + format, + pageFrom, + pageTo, + storage, + folder); + + // Log the response to console. + console.log(result.body.status); + // Write the split result to the local file system. + for (const [index, page] of result.body.result.documents.entries()) + { + // Download the PDF file from cloud storage. + const file = await api.downloadFile(page.href, storage); + const filePath = `testOutput/page${index + 1}.pdf`; + // Write the file to the local file system. + fs.writeFileSync(filePath, file.body); + console.log(index + 1 + ") " + filePath); + } +} + +// Execute the splitDocument function. +splitDocument(); diff --git a/UsesCases/Split/split.js b/UsesCases/Split/split.js new file mode 100644 index 00000000..20ae571f --- /dev/null +++ b/UsesCases/Split/split.js @@ -0,0 +1,73 @@ +/** + * Splitting the PDF document to pages using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Splitting document to pages using the Aspose.PDF Cloud API. + * 5. Write the splitting result to the local file system. + * + */ + +// Import necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Splitting the PDF document per pages using the Aspose.PDF Cloud API. + * + * @returns {Promise} A Promise that resolves when the splitting document is complete. + */ +async function splitDocument() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + // const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + + // Set the document name. + const fileName = "4pages.pdf"; + // Set the start page number (null means from begin of document). + const pageFrom = null; + // Set the end page number (null means to end of document). + const pageTo = null; + // Set the resulting documents format. + // Available formats are: PDF, PDFA1A, PDFA1B, PDFA3A, DOC, DOCX, XLS, XPS, TIFF, SVG, JPEG, JPG, PNG, EMF, BMP, GIF, PPTX, EPUB. + const format = "PDF"; + // Use default storage (null indicates default storage). + const storage = null; + // Set the folder where the document is stored. + const folder = "Documents"; + + // Read the file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload the file to cloud storage. + await api.uploadFile(folder + "/" + fileName, buffer, storage) + + // Swagger documentation available at: + // https://reference.aspose.cloud/pdf/#/Document/PostSplitDocument + // Split the PDF document per page. + const result = await api.postSplitDocument( + fileName, + format, + pageFrom, + pageTo, + storage, + folder); + + // Log the response to console. + console.log(result.body.status); + // Write the split result to the local file system. + for (const [index, page] of result.body.result.documents.entries()) + { + // Download the PDF file from cloud storage. + const file = await api.downloadFile(page.href, storage); + const filePath = `testOutput/page${index + 1}.pdf`; + // Write the file to the local file system. + fs.writeFileSync(filePath, file.body); + console.log(index + 1 + ") " + filePath); + } +} + +// Execute the splitDocument function. +splitDocument(); diff --git a/UsesCases/Text/add/add.js b/UsesCases/Text/add/add.js new file mode 100644 index 00000000..10fddd41 --- /dev/null +++ b/UsesCases/Text/add/add.js @@ -0,0 +1,85 @@ +/** + * Add text to a PDF document page using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Put text on the PDF document page using the Aspose.PDF Cloud API. + * 5. Logs the result to the console. + * + */ + +// Import necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Add text to a PDF document page using the Aspose.PDF Cloud API. + * + * @returns {Promise} A Promise that resolves when the adding text is complete. + */ +async function addText() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + + // Set the document name. + const fileName = "4pages.pdf"; + // Set the page number where the text will be added. + const pageNumber = 3; + // Use default storage (null indicates default storage). + const storage = null; + // Set the folder where the document is stored. + const folder = "Documents"; + + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + await api.uploadFile(folder + "/" +fileName, buffer, storage); + + // Create new text paragraph. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/Paragraph.md + const paragraph = + { + // Set the left margin for the paragraph. + leftMargin: 100, + // Set the bottom margin for the paragraph. + bottomMargin: 200, + // Set the rotation angle of the text in degrees. + rotation: 10, + // Define an array of text lines for the paragraph. + lines: [{ + // Define the segments that form the line. + segments: [{ + // Text value for the segment. + value: "segment text 1 with text state", + // Define the text state for formatting. + textState: { + // Set font size of the text. + fontSize: 20, + // Set font name of the text. + font: "Arial", + // Set underline for the text. + underline: true + } + }] + }] + }; + + // Swagger method definition available at: + // https://reference.aspose.cloud/pdf/#/Text/PutAddText + // Adding text to the PDF document page. + const result = await api.putAddText( + fileName, + pageNumber, + paragraph, + folder, + storage); + + // Log the response to console. + console.log(result.body.status); +} + +// Execute the addText function. +addText(); diff --git a/useCases/textExtract.js b/UsesCases/Text/extract/extract.js similarity index 54% rename from useCases/textExtract.js rename to UsesCases/Text/extract/extract.js index 11c3a365..a8b56f69 100644 --- a/useCases/textExtract.js +++ b/UsesCases/Text/extract/extract.js @@ -1,36 +1,35 @@ -// Import necessary classes from the Aspose PDF Cloud library -const fs = require("fs"); -const { PdfApi } = require("asposepdfcloud"); - -// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ -const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); - -// The document name. -const fileName = "4pages.pdf"; -// Use default storage. -const storage = null; -// Set document folder. -const folder = "Documents"; - /** * Extract text of a PDF document using the Aspose.PDF Cloud API. * - * This function performs the following steps: - * 1. Reads a PDF file from the local file system. - * 2. Uploads the PDF file to the Aspose.PDF Cloud storage. - * 3. Initializing parameters for searching text on a PDF document page. - * 4. Read text of PDF document using the Aspose.PDF Cloud API. + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Read text of the PDF document using the Aspose.PDF Cloud API. * 5. Logs an extracted text. * + */ + +// Import necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Extract text of a PDF document using the Aspose.PDF Cloud API. + * * @returns {Promise} A promise that is resolves after text extraction is complete. */ async function extractText() { - // Read file from file system. - const buffer = fs.readFileSync("testData/" + fileName); - // Upload file to cloud storage. - const uploadResponse = await api.uploadFile(folder + "/" +fileName, buffer, storage) + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + // The document name. + const fileName = "4pages.pdf"; + // Use default storage. + const storage = null; + // Set document folder. + const folder = "Documents"; // X-coordinate of lower-left corner. const llx = 100; // Y-coordinate of lower-left corner. @@ -45,12 +44,17 @@ async function extractText() const regex = true; // Split result fragments (default is true). const splitRects = true; + + // Read file from filesystem. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + await api.uploadFile(folder + "/" +fileName, buffer, storage); // Swagger method definition available at // https://reference.aspose.cloud/pdf/#/Text/GetText - // Extract document text. + // Extract text from the PDF document. const result = await api.getText( - uploadResponse.body.uploaded[0], + fileName, llx, lly, urx, @@ -62,10 +66,12 @@ async function extractText() storage); // Log extracted text. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/TextRectsResponse.md for (const text of result.body.textOccurrences.list) { console.log(text.text); } } +// Execute the extractText function. extractText(); diff --git a/UsesCases/Text/remove/remove.js b/UsesCases/Text/remove/remove.js new file mode 100644 index 00000000..0ba345cb --- /dev/null +++ b/UsesCases/Text/remove/remove.js @@ -0,0 +1,75 @@ +/** + * Remove text of a PDF document using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Remove text of the PDF document using the Aspose.PDF Cloud API. + * 5. Logs the result to the console. + * + */ + +// Import necessary classes from the Aspose PDF Cloud library +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Remove text of a PDF document using the Aspose.PDF Cloud API. + * + * @returns {Promise} A promise that is resolves after text deletion is complete. + */ +async function removeText() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + + // Set the document name + const fileName = "4pages.pdf"; + // Use default storage (null indicates default storage) + const storage = null; + // Set the folder where the document is stored + const folder = "Documents"; + + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + await api.uploadFile(folder + "/" +fileName, buffer, storage) + + // Create TextReplaceListRequest instance. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/TextReplaceListRequest.md + const textReplaceList = + { + // Set the text replaces list. + textReplaces: + [ + { + // Set the text to replace. + regex: false, + // Set the text to replace. + newValue: "", + // Set the oldValue is regex. + oldValue: "Page" + } + ], + // Set the start index of text items to replace. + startIndex: 2, + // Set the count replacements. + countReplace: 2 + }; + + // Swagger method for adding text: + // https://reference.aspose.cloud/pdf/#/TextReplace/PostDocumentTextReplace + // Remove text in the PDF document. + const result = await api.postDocumentTextReplace( + fileName, + textReplaceList, + storage, + folder); + + // Log the response to console. + console.log(result.body.status); +} + +// Execute the removeText function +removeText(); diff --git a/UsesCases/Text/replace/replace.js b/UsesCases/Text/replace/replace.js new file mode 100644 index 00000000..6abc9670 --- /dev/null +++ b/UsesCases/Text/replace/replace.js @@ -0,0 +1,83 @@ +/** + * Replace text of a PDF document using the Aspose.PDF Cloud API. + * + * This use case performs the following steps: + * 1. Import the necessary classes. + * 2. Reads a PDF file from the local file system. + * 3. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 4. Replace text of the PDF document using the Aspose.PDF Cloud API. + * 5. Logs the result to the console. + * + */ + +// Import necessary classes. +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +/** + * Replace text of a PDF document using the Aspose.PDF Cloud API. + * + * @returns {Promise} A promise that is resolves after text replacement is complete. + */ +async function replaceText() +{ + // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ + const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + + // Set the document name + const fileName = "4pages.pdf"; + // Use default storage (null indicates default storage) + const storage = null; + // Set the folder where the document is stored + const folder = "Documents"; + + // Create TextReplaceListRequest instance. + // Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/TextReplaceListRequest.md + const textReplaceList = + { + // Set the text replaces list. + textReplaces: + [ + { + // Set the text state. + textState: + { + // Set font name of the text. + font: "Arial", + // Set font size of the text. + fontSize: 12, + // Set underline for the text. + underline: true + }, + // Set the text to replace. + oldValue: "Page", + // Set the replacement text. + newValue: "Replacement" + } + ], + // Set the start index of text items to replace. + startIndex: 2, + // Set the count replacements. + countReplace: 2 + } + + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + await api.uploadFile(folder + "/" +fileName, buffer, storage); + + // Swagger method definition available at: + // https://reference.aspose.cloud/pdf/#/TextReplace/PostDocumentTextReplace + // Replace text in the PDF document. + const result = await api.postDocumentTextReplace( + folder + "/" +fileName, + textReplaceList, + storage, + folder); + + // Log the response to console. + console.log(result.body.status); +} + +// Execute the replaceText function +replaceText(); diff --git a/useCases/textAdd.js b/useCases/textAdd.js deleted file mode 100644 index 31dcb7a0..00000000 --- a/useCases/textAdd.js +++ /dev/null @@ -1,158 +0,0 @@ -// Import necessary classes from the Aspose PDF Cloud library -const fs = require("fs"); -const { PdfApi } = require("asposepdfcloud"); -const { Color } = require("asposepdfcloud/src/models/color"); -const { FontStyles } = require("asposepdfcloud/src/models/fontStyles"); -const { LineSpacing } = require("asposepdfcloud/src/models/lineSpacing"); -const { Paragraph } = require("asposepdfcloud/src/models/paragraph"); -const { TextHorizontalAlignment } = require("asposepdfcloud/src/models/textHorizontalAlignment"); -const { VerticalAlignment } = require("asposepdfcloud/src/models/verticalAlignment"); -const { WrapMode } = require("asposepdfcloud/src/models/wrapMode"); -const { TextLine } = require("asposepdfcloud/src/models/textLine"); -const { Segment } = require("asposepdfcloud/src/models/segment"); -const { Rectangle } = require("asposepdfcloud/src/models/rectangle"); -const { TextState } = require("asposepdfcloud/src/models/textState"); - -// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ -const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); - -// Set the document name -const fileName = "4pages.pdf"; -// Set the page number where the text will be added -const pageNumber = 3; -// Use default storage (null indicates default storage) -const storage = null; -// Set the folder where the document is stored -const folder = "Documents"; - -/** - * Add text to a PDF document page using the Aspose.PDF Cloud API. - * - * This function performs the following steps: - * 1. Reads a PDF file from the local file system. - * 2. Uploads the PDF file to the Aspose.PDF Cloud storage. - * 3. Creates an `Paragraph` object with the inserted text. - * 4. Put text on the third page of PDF document using the Aspose.PDF Cloud API. - * 5. Logs the result to the console. - * - * @returns {Promise} A Promise that resolves when the adding text is complete. - */ -async function putAddText() -{ - // Read file from file system. - const buffer = fs.readFileSync("testData/" + fileName); - // Upload file to cloud storage. - const uploadResponse = await api.uploadFile(folder + "/" +fileName, buffer, storage) - - // Represents color DTO. - const foregroundColor = new Color(); - // Set an alpha component. - foregroundColor.a = 255; - // Set the red component. - foregroundColor.r = 0; - // Set the green component. - foregroundColor.g = 0; - // Set the blue component. - foregroundColor.b = 255; - - // Represents color DTO. - const backgroundColor = new Color(); - // Set an alpha component. - backgroundColor.a = 100; - // Set the red component. - backgroundColor.r = 255; - // Set the green component. - backgroundColor.g = 255; - // Set the blue component. - backgroundColor.b = 0; - - // Create the new paragraph object to represent text paragraphs - const rectangle = new Rectangle(); - // Lower left x coordinate - rectangle.lLX = 10; - // Lower left y coordinate - rectangle.lLY = 10; - // Upper right x coordinate - rectangle.uRX = 300; - // Upper right y coordinate - rectangle.uRY = 500; - - // Create the new text state. - const textState = new TextState(); - // Set font size of the text - textState.fontSize = 20; - // Set font name of the text - textState.font = "Arial"; - // Set foreground color of the text - textState.foregroundColor = foregroundColor; - // Set background color of the text - textState.backgroundColor = backgroundColor; - // Set font style of the text - textState.fontStyle = FontStyles.Regular; - // Font file path in storage (null means default font) - textState.fontFile = null; - // Set underline for the text - textState.underline = true; - // Set strikeout for the text - textState.strikeOut = false; - // Set superscript mode for the text - textState.superscript = false; - // Set subscript mode for the text - textState.subscript = false; - - // Create the new text segment. - const segment = new Segment(); - // Text value for the segment - segment.value = "segment text 1 with text state"; - // Define the text state for formatting - segment.textState = textState; - - // Create the new text line. - const textLine = new TextLine(); - // Set the line's horizontal alignment to Right - textLine.horizontalAlignment = TextHorizontalAlignment.Right; - // Define the segments that form the line - textLine.segments = [segment]; - - // Create new text paragraph. - const paragraph = new Paragraph(); - // Set the line spacing mode to FullSize - paragraph.lineSpacing = LineSpacing.FullSize; - // Set the word wrap mode to wrap by words - paragraph.wrapMode = WrapMode.ByWords; - // Set the horizontal alignment for the text inside the paragraph - paragraph.horizontalAlignment = TextHorizontalAlignment.FullJustify; - // Set the left margin for the paragraph - paragraph.leftMargin = 100; - // Set the right margin for the paragraph - paragraph.rightMargin = 100; - // Set the top margin for the paragraph - paragraph.topMargin = 200; - // Set the bottom margin for the paragraph - paragraph.bottomMargin = 200; - // Define the rectangle area for the paragraph - paragraph.rectangle = rectangle; - // Set the rotation angle of the text in degrees - paragraph.rotation = 10, - // Set the indent for subsequent lines - paragraph.subsequentLinesIndent = 30, - // Set the vertical alignment for the text inside the paragraph - paragraph.vercolorticalAlignment = VerticalAlignment.Center, - // Define an array of text lines for the paragraph - paragraph.lines = [textLine]; - - // Swagger method for adding text: https://reference.aspose.cloud/pdf/#/Text/PutAddText - // Call the API to add text to the specified PDF document page - const result = await api.putAddText( - uploadResponse.body.uploaded[0], - pageNumber, - paragraph, - folder, - storage); - - // Log the response to console. - console.log(result.body.status); // Log the status of the operation -} - -// Execute the putAddText function -putAddText(); diff --git a/useCases/textReplace.js b/useCases/textReplace.js deleted file mode 100644 index 91ea1cb9..00000000 --- a/useCases/textReplace.js +++ /dev/null @@ -1,131 +0,0 @@ -// Import necessary classes from the Aspose PDF Cloud library -const fs = require("fs"); -const { PdfApi } = require("asposepdfcloud"); -const { Color } = require("asposepdfcloud/src/models/color"); -const { FontStyles } = require("asposepdfcloud/src/models/fontStyles"); -const { Rectangle } = require("asposepdfcloud/src/models/rectangle"); -const { TextState } = require("asposepdfcloud/src/models/textState"); -const { TextReplace } = require("asposepdfcloud/src/models/textReplace"); -const { TextReplaceListRequest } = require("asposepdfcloud/src/models/textReplaceListRequest"); - -// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ -const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); - -// Set the document name -const fileName = "4pages.pdf"; -// Use default storage (null indicates default storage) -const storage = null; -// Set the folder where the document is stored -const folder = "Documents"; - -/** - * Replace text of a PDF document using the Aspose.PDF Cloud API. - * - * This function performs the following steps: - * 1. Reads a PDF file from the local file system. - * 2. Uploads the PDF file to the Aspose.PDF Cloud storage. - * 3. Creates an `TextReplaceListRequest` object with the replacements list. - * 4. Replace text of PDF document using the Aspose.PDF Cloud API. - * 5. Logs the result to the console. - * - * @returns {Promise} A promise that is resolves after text replacement is complete. - */ -async function postDocumentTextReplace() -{ - // Read file from file system. - const buffer = fs.readFileSync("testData/" + fileName); - // Upload file to cloud storage. - const uploadResponse = await api.uploadFile(folder + "/" +fileName, buffer, storage) - - // Represents color DTO. - const foregroundColor = new Color(); - // Set an alpha component. - foregroundColor.a = 255; - // Set the red component. - foregroundColor.r = 0; - // Set the green component. - foregroundColor.g = 0; - // Set the blue component. - foregroundColor.b = 255; - - // Represents color DTO. - const backgroundColor = new Color(); - // Set an alpha component. - backgroundColor.a = 100; - // Set the red component. - backgroundColor.r = 255; - // Set the green component. - backgroundColor.g = 255; - // Set the blue component. - backgroundColor.b = 0; - - // Create the new paragraph object to represent text paragraphs. - const rectangle = new Rectangle(); - // Lower left x coordinate. - rectangle.lLX = 10; - // Lower left y coordinate. - rectangle.lLY = 10; - // Upper right x coordinate. - rectangle.uRX = 300; - // Upper right y coordinate. - rectangle.uRY = 500; - - // Create the new text state. - const textState = new TextState(); - // Set font size of the text. - textState.fontSize = 12; - // Set font name of the text. - textState.font = "Arial"; - // Set foreground color of the text. - textState.foregroundColor = foregroundColor; - // Set background color of the text. - textState.backgroundColor = backgroundColor; - // Set font style of the text. - textState.fontStyle = FontStyles.Regular; - // Font file path in storage (null means default font). - textState.fontFile = null; - // Set underline for the text. - textState.underline = true; - // Set strikeout for the text. - textState.strikeOut = false; - // Set superscript mode for the text. - textState.superscript = false; - // Set subscript mode for the text. - textState.subscript = false; - - // Create TextReplace request. - const textReplace = new TextReplace(); - // Set the text to replace. - textReplace.oldValue = "Page"; - // Set the replacement text. - textReplace.newValue = "Replacement"; - // Set the oldValue is regex. - textReplace.regex = false; - // Set the text state. - textReplace.textState = textState; - // Set the text aligment. - textReplace.centerTextHorizontally = false; - - // Create TextReplaceListRequest instance. - const textReplaceList = new TextReplaceListRequest(); - // Set the text replaces list. - textReplaceList.textReplaces = [textReplace]; - // Set the start index of text items to replace. - textReplaceList.startIndex = 2; - // Set the count replacements. - textReplaceList.countReplace = 2; - - // Swagger method for adding text: https://reference.aspose.cloud/pdf/#/TextReplace/PostDocumentTextReplace - // Call the API to replace text in the specified PDF document. - const result = await api.postDocumentTextReplace( - uploadResponse.body.uploaded[0], - textReplaceList, - storage, - folder); - - // Log the response to console. - console.log(result.body.status); -} - -// Execute the postDocumentTextReplace function -postDocumentTextReplace();