Skip to content

Added use cases #101

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
73 changes: 73 additions & 0 deletions UsesCases/Merge/merge.js
Original file line number Diff line number Diff line change
@@ -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<void>} 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();
68 changes: 68 additions & 0 deletions UsesCases/Metadata/add/add.js
Original file line number Diff line number Diff line change
@@ -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<void>} 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();
53 changes: 53 additions & 0 deletions UsesCases/Metadata/get/get.js
Original file line number Diff line number Diff line change
@@ -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<void>} 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();
70 changes: 70 additions & 0 deletions UsesCases/Metadata/remove/remove.js
Original file line number Diff line number Diff line change
@@ -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<void>} 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();
70 changes: 70 additions & 0 deletions UsesCases/Metadata/update/update.js
Original file line number Diff line number Diff line change
@@ -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<void>} 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();
Loading