Skip to content

Commit 87927c0

Browse files
author
kirill.novinskiy@aspose.com
committed
Added use cases for metadata
1 parent 651a595 commit 87927c0

File tree

4 files changed

+261
-0
lines changed

4 files changed

+261
-0
lines changed

UsesCases/Metadata/add/add.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Add the XMP metadata property to a PDF document using the Aspose.PDF Cloud API.
3+
*
4+
* This use case performs the following steps:
5+
* 1. Import the necessary classes.
6+
* 2. Reads a PDF file from the local file system.
7+
* 3. Uploads the PDF file to the Aspose.PDF Cloud storage.
8+
* 4. Add the XMP metadata property using Aspose.PDF Cloud API.
9+
* 5. Read an updated XMP metadata from pdf document using the Aspose.PDF Cloud API.
10+
* 6. Log to the console that the XMP metadata property was added.
11+
*
12+
*/
13+
14+
// Import the necessary classes.
15+
const fs = require("fs");
16+
const { PdfApi } = require("asposepdfcloud");
17+
18+
/**
19+
* Add the xmp metadata property to the PDF document using the Aspose.PDF Cloud API.
20+
*
21+
* @returns {Promise<void>} A promise that resolves when the xmp metadata property is completed adding.
22+
*/
23+
async function addXmpMetadataProperty()
24+
{
25+
// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
26+
const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY");
27+
28+
// Set the PDF document name.
29+
const fileName = "4pages.pdf";
30+
// Set the folder where the document is stored.
31+
const folder = "Documents";
32+
// Set storage name (null indicates default storage).
33+
const storage = null;
34+
// Set the password if the document is password-protected.
35+
const password = null;
36+
// Set the XMP metadata property name.
37+
const xmpMetadataProperty = "pdf:Prop";
38+
39+
// Read file from file system.
40+
const buffer = fs.readFileSync("testData/" + fileName);
41+
// Upload file to cloud storage.
42+
await api.uploadFile(folder + "/" +fileName, buffer, storage)
43+
44+
// Create instance of XmpMetadataProperty for pdf:Prop.
45+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadataProperty.md
46+
var pdfPropProperty = {
47+
key: xmpMetadataProperty,
48+
value: "PropValue",
49+
namespaceUri: "http://ns.adobe.com/pdf/1.3/"
50+
};
51+
// Create an instance of XmpMetadata.
52+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadata.md
53+
const xmpMetadata = {
54+
properties: [pdfPropProperty]
55+
};
56+
// Update the XMP metadata.
57+
const result = await api.postXmpMetadata(fileName, xmpMetadata, folder, storage, password);
58+
console.log(result.body.status);
59+
60+
// Read XMP metadata from PDF document.
61+
metadata = await api.getXmpMetadataJson(fileName, folder, storage, password);
62+
// Log XMP metadata property was added.
63+
pdfPropProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty);
64+
console.log("Added xmpMetadataProperty: " + pdfPropProperty.key + "=" + pdfPropProperty.value);
65+
}
66+
67+
// Execute the addXmpMetadataProperty function
68+
addXmpMetadataProperty();

UsesCases/Metadata/get/get.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Read the XMP metadata from a PDF document using the Aspose.PDF Cloud API.
3+
*
4+
* This use case performs the following steps:
5+
* 1. Import the necessary classes.
6+
* 2. Reads a PDF file from the local file system.
7+
* 3. Uploads the PDF file to the Aspose.PDF Cloud storage.
8+
* 4. Read the XMP metadata from pdf document using the Aspose.PDF Cloud API.
9+
* 5. Log to the console the XMP metadata properties.
10+
*
11+
*/
12+
13+
// Import the necessary classes.
14+
const fs = require("fs");
15+
const { PdfApi } = require("asposepdfcloud");
16+
17+
/**
18+
* Reads xmp metadata from a PDF document using the Aspose.PDF Cloud API.
19+
*
20+
* @returns {Promise<void>} A promise that resolves when the xmp metadata reading completes.
21+
*/
22+
async function getXmpMetadataProperty()
23+
{
24+
// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
25+
const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY");
26+
27+
// Set the PDF document name.
28+
const fileName = "4pages.pdf";
29+
// Set the folder where the document is stored.
30+
const folder = "Documents";
31+
// Set storage name (null indicates default storage).
32+
const storage = null;
33+
// Set the password if the document is password-protected.
34+
const password = null;
35+
36+
// Read file from file system.
37+
const buffer = fs.readFileSync("testData/" + fileName);
38+
// Upload file to cloud storage.
39+
await api.uploadFile(folder + "/" +fileName, buffer, storage)
40+
41+
// Read XMP metadata from PDF document.
42+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadata.md
43+
const metadata = await api.getXmpMetadataJson(fileName, folder, storage, password);
44+
// Log metadata to the console.
45+
console.log("XMP metadata:");
46+
metadata.body.properties.forEach(property =>
47+
{
48+
console.log(" " + property.key + " = " + property.value);
49+
});
50+
}
51+
52+
// Execute the getXmpMetadataProperty function
53+
getXmpMetadataProperty();

UsesCases/Metadata/remove/remove.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Remove the XMP metadata property from a PDF document using the Aspose.PDF Cloud API.
3+
*
4+
* This use case performs the following steps:
5+
* 1. Import the necessary classes.
6+
* 2. Reads a PDF file from the local file system.
7+
* 3. Uploads the PDF file to the Aspose.PDF Cloud storage.
8+
* 4. Read the XMP metadata from pdf document using the Aspose.PDF Cloud API.
9+
* 5. Remove the XMP metadata property using the Aspose.PDF Cloud API.
10+
* 6. Read an updated XMP metadata from pdf document using the Aspose.PDF Cloud API.
11+
* 7. Log to the console that the XMP metadata property was removed.
12+
*
13+
*/
14+
15+
// Import the necessary classes.
16+
const fs = require("fs");
17+
const { PdfApi } = require("asposepdfcloud");
18+
19+
/**
20+
* Remove xmp metadata property from a PDF document using the Aspose.PDF Cloud API.
21+
*
22+
* @returns {Promise<void>} A promise that resolves when the xmp metadata property deletion completes.
23+
*/
24+
async function removeXmpMetadataProperty()
25+
{
26+
// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
27+
const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY");
28+
29+
// Set the PDF document name.
30+
const fileName = "4pages.pdf";
31+
// Set the folder where the document is stored.
32+
const folder = "Documents";
33+
// Set storage name (null indicates default storage).
34+
const storage = null;
35+
// Set the password if the document is password-protected.
36+
const password = null;
37+
// Set the XMP metadata property name.
38+
const xmpMetadataProperty = "xmp:CreatorTool";
39+
40+
// Read file from file system.
41+
const buffer = fs.readFileSync("testData/" + fileName);
42+
// Upload file to cloud storage.
43+
await api.uploadFile(folder + "/" +fileName, buffer, storage)
44+
45+
// Read XMP metadata from pdf document.
46+
var metadata = await api.getXmpMetadataJson(fileName, folder, storage, password);
47+
// Find the creator property.
48+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadataProperty.md
49+
var creatorToolProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty);
50+
// Set value to null to remove property.
51+
creatorToolProperty.value = null;
52+
53+
// Create an instance of XmpMetadata.
54+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadata.md
55+
const xmpMetadata = {
56+
properties: [creatorToolProperty]
57+
};
58+
// Update the XMP metadata.
59+
const result = await api.postXmpMetadata(fileName, xmpMetadata, folder, storage, password);
60+
console.log(result.body.status);
61+
62+
// Read XMP metadata from PDF document.
63+
metadata = await api.getXmpMetadataJson(fileName, folder, storage, password);
64+
// Log XMP metadata property was removed.
65+
creatorToolProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty);
66+
console.log("Removed xmpMetadataProperty: " + xmpMetadataProperty);
67+
}
68+
69+
// Execute the removeXmpMetadataProperty function
70+
removeXmpMetadataProperty();

UsesCases/Metadata/update/update.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Update the XMP metadata property from a PDF document using the Aspose.PDF Cloud API.
3+
*
4+
* This use case performs the following steps:
5+
* 1. Import the necessary classes.
6+
* 2. Reads a PDF file from the local file system.
7+
* 3. Uploads the PDF file to the Aspose.PDF Cloud storage.
8+
* 4. Read the XMP metadata from pdf document using the Aspose.PDF Cloud API.
9+
* 5. Update the XMP metadata property using the Aspose.PDF Cloud API.
10+
* 6. Read an updated XMP metadata from pdf document using the Aspose.PDF Cloud API.
11+
* 7. Log to the console that the XMP metadata property was updated.
12+
*
13+
*/
14+
15+
// Import the necessary classes.
16+
const fs = require("fs");
17+
const { PdfApi } = require("asposepdfcloud");
18+
19+
/**
20+
* Update xmp metadata property from a PDF document using the Aspose.PDF Cloud API.
21+
*
22+
* @returns {Promise<void>} A promise that resolves when the xmp metadata property update completes.
23+
*/
24+
async function updateXmpMetadataProperty()
25+
{
26+
// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
27+
const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY");
28+
29+
// Set the PDF document name.
30+
const fileName = "4pages.pdf";
31+
// Set the folder where the document is stored.
32+
const folder = "Documents";
33+
// Set storage name (null indicates default storage).
34+
const storage = null;
35+
// Set the password if the document is password-protected.
36+
const password = null;
37+
// Set the XMP metadata property name.
38+
const xmpMetadataProperty = "dc:title";
39+
40+
// Read file from file system.
41+
const buffer = fs.readFileSync("testData/" + fileName);
42+
// Upload file to cloud storage.
43+
await api.uploadFile(folder + "/" +fileName, buffer, storage)
44+
45+
// Read XMP metadata from pdf document.
46+
var metadata = await api.getXmpMetadataJson(fileName, folder, storage, password);
47+
// Find the title property.
48+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadataProperty.md
49+
var titleProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty);
50+
// Update the title property.
51+
titleProperty.value = "New title";
52+
53+
// Create an instance of XmpMetadata.
54+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/XmpMetadata.md
55+
const xmpMetadata = {
56+
properties: [titleProperty]
57+
};
58+
// Update the XMP metadata.
59+
const result = await api.postXmpMetadata(fileName, xmpMetadata, folder, storage, password);
60+
console.log(result.body.status);
61+
62+
// Read XMP metadata from PDF document.
63+
metadata = await api.getXmpMetadataJson(fileName, folder, storage, password);
64+
// Log XMP metadata property was updated.
65+
titleProperty = metadata.body.properties.find(property => property.key == xmpMetadataProperty);
66+
console.log("Updated xmpMetadataProperty: " + titleProperty.key + "=" + titleProperty.value);
67+
}
68+
69+
// Execute the updateXmpMetadataProperty function
70+
updateXmpMetadataProperty();

0 commit comments

Comments
 (0)