PDF Toolkit

Samples

Get and Set PDF Metadata

This Code sample requires the PDF Toolkit and is found in: C:\Aquaforest\PDF Toolkit\samples\SetAndGetPDFMetadata

    
using Aquaforest.PDF;
using System;
    
namespace SetAndGetPDFMetadata
{
    internal class SetGetMetadata
    {
        private static void Main(string[] args)
        {
            //Assign Licence Key
            PDFToolkit.LicenseKey = string.Empty;
            string inputFile = @"..\documents\source\releasenotes.pdf";
            string outputFile = @"..\documents\output\metadata.pdf";
            PDFDocumentInformation info = new PDFDocumentInformation()
            {
                Author = "Name Surname",
                Subject = "Test",
                Title = "New PDF",
                Keywords = "PDF, OCR, SDK",
                CreationDate = new DateTime(2013, 9, 9),
                Producer = "Aquaforest"
            };
            info.SetCustomMetadataValue("AQUAFOREST_PDF_TOOLKIT", "1.01");
            SetPDFMetadata(inputFile, outputFile, info);
    
            ReadDocumentInformation(outputFile);
        }
    
        public static void ReadDocumentInformation(string input)
        {
            try
            {
                PDFDocument doc = new PDFDocument(input);
                PDFDocumentInformation docInfo = doc.GetDocumentInformation();
                Console.WriteLine("Author = {0}, CreationDate = {1}, Creator = {2} .", docInfo.Author, docInfo.CreationDate, docInfo.Creator);
                doc.Close();
            }
            catch (Exception)
            {
            }
        }
    
        public static void SetPDFMetadata(string input, string output, PDFDocumentInformation metadata)
        {
            try
            {
                PDFDocument doc = new PDFDocument(input);
                doc.SetDocumentInformation(metadata);
                doc.Save(output);
                doc.Close();
            }
            catch (Exception)
            {
            }
        }
    }
}