This article demonstrates how to add and delete PDF document properties using the PdfPropertiesApi interface provided by Spire.Cloud.PDF.
Add document properties
using Spire.Cloud.Pdf.Sdk.Api;
using Spire.Cloud.Pdf.Sdk.Client;
using Spire.Cloud.Pdf.Sdk.Model;
using System;
using System.Collections.Generic;
namespace AddPDFProperties
{
class Program
{
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration instance based on your AppID and AppKey
static Configuration PdfConfiguration = new Configuration(appId, appKey, baseUrl);
//Create a PdfPropertiesApi instance
static PdfPropertiesApi pdfPropertiesApi = new PdfPropertiesApi(PdfConfiguration);
static void Main(string[] args)
{
//Specify the input document
string name = "Sample.pdf";
//Specify the folder storing the input document, and it's "null" if nothing
string folder = "input";
//Specify the password used to open the document, and it's "null" if nothing
string password = null;
//Use the 2G storage provided by E-iceblue, and it's "null" by default
string storage = null;
//Specify the file path of the output document
string outPath = "output/AddOrUpdateProperties_output.pdf";
//Create a DocumentProperties instance
DocumentProperties properties = new DocumentProperties();
//Create a list of document properties
properties.List = new List();
//buildin properties
properties.List.Add(new DocumentProperty("author", "Simon"));
properties.List.Add(new DocumentProperty("creator", "Simon2"));
properties.List.Add(new DocumentProperty("keywords", "the keywords"));
properties.List.Add(new DocumentProperty("producer", "Spire.pdf"));
properties.List.Add(new DocumentProperty("subject", "the subject"));
properties.List.Add(new DocumentProperty("title", "the title"));
//customized properties
properties.List.Add(new DocumentProperty("customizedProperty1", "the customizedProperty1"));
properties.List.Add(new DocumentProperty("customizedProperty2", "the customizedProperty2"));
properties.List.Add(new DocumentProperty("Name", " Lisa"));
//Call the AddOrUpdateProperties method to add properties to the document and save to a specified path
pdfPropertiesApi.AddOrUpdateProperties(name, outPath, properties, folder, storage, password);
}
}
}
Output
Built-in properties:
Custom properties:
Delete document properties
using Spire.Cloud.Pdf.Sdk.Api;
using Spire.Cloud.Pdf.Sdk.Client;
using System;
namespace DeletePDFProperties
{
class Program
{
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration instance based on your AppID and AppKey
static Configuration PdfConfiguration = new Configuration(appId, appKey, baseUrl);
//Create a PdfPropertiesApi instance
static PdfPropertiesApi pdfPropertiesApi = new PdfPropertiesApi(PdfConfiguration);
static void Main(string[] args)
{
//Specify the input document
string name = "Input.pdf";
//Specify the folder storing the input document, and it's "null" if nothing
string folder = "input";
//Specify the password used to open the document, and it's "null" if nothing
string password = null;
//Specify the file path of the output document
string outPath = "output/DeleteProperties_output.pdf";
//Use the 2G storage provided by E-iceblue, and it's "null" by default
string storage = null;
//Call the DeleteProperties method to delete properties from the document and save to a specified path
pdfPropertiesApi.DeleteProperties(name, outPath, folder, storage, password);
}
}
}
Output
Built-in properties have been deleted:
Custom properties have been deleted: