|
| 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(); |
0 commit comments