BasicSchema Class | BasicJobTicketSchema Class | DublinCoreSchema Class | PagedTextSchema Class | RightsManagementSchema Class | ceTe.DynamicPDF.Xmp Namespace | Programming with Generator for .NET

Language

Visual Basic

C#

Show All

The XMP (Extensible Metadata Platform) provides a standard format for the creation, processing, and interchange of metadata, for a wide variety of applications. Metadata is data that describes the characteristics or properties of a document. It can be distinguished from the main contents of a document. For example, for a word processing document, the contents include the actual text data and formatting information, while the metadata might include such properties as author, modification date, or copyright status.

In order to make multiple applications able to work effectively with metadata, there must be a common standard that they understand. XMP—the Extensible Metadata Platform—is designed to provide such a standard.

XMP is provided with Schemas: Predefined sets of metadata property definitions that are relevant for a wide range of applications.

 

This example shows how to create an XMP Metadata and add it to the document.

[Visual Basic]
Imports System
Imports System.IO
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.Xmp
                
Module MyModule
Sub Main()
                
        ' Create a PDF Document
        Dim MyDocument As Document = New Document
        MyDocument.Keywords = "XMP, metadata, pdf, example"
        MyDocument.Title = "Pdf document with xmp metadata"
                                
        ' Add blank pages to the document
        MyDocument.Pages.Add(New Page(PageSize.Letter))
        MyDocument.Pages.Add(New Page(PageSize.Letter))
                                
        ' Create an Xmp Metadata
        Dim MyXmp As XmpMetadata = New XmpMetadata
                                
        ' Dublin Core Schema.
        Dim Mydc As DublinCoreSchema = MyXmp.DublinCore
        Mydc.Contributors.Add( "Abc" )
        Mydc.Contributors.Add( "Xyz" )
        Mydc.Contributors.Add( "Pqrs" )
        Mydc.Coverage = "To test all the attributes of schema's provided"
        Mydc.Creators.Add( "DynamicPDF" )
        Mydc.Creators.Add( "ceTe Software" )
        Mydc.Date.Add( DateTime.Now )
        Mydc.Description.AddLang( "en-us", "XMP Schema's test" )
        Mydc.Identifier = "First XMP pdf"
        Mydc.Publisher.Add( "DynamicPDF.com" )
        Mydc.Publisher.Add( "ceTe Software" )
        Mydc.Relation.Add( "test pdf with xmp" )
        Mydc.Rights.DefaultText = "ceTe Software Pvt. Ltd"
        Mydc.Rights.AddLang( "en-us", "All rights reserved 2006, ceTe software." )
        Mydc.Source = "XMP Project"
        Mydc.Subject.Add( "eXtensible Metadata Platform" )
        Mydc.Title.AddLang( "en-us", "XMP" )
        Mydc.Title.AddLang( "it-it", "XMP - Piattaforma Estendible di Metadata" )
        Mydc.Title.AddLang( "du-du", "De hallo Wereld" )
        Mydc.Title.AddLang( "fr-fr", "XMP - Une Platforme Extensible pour les Métédonnées" )
        Mydc.Title.AddLang( "DE-DE", "ÄËßÜ Hallo Welt" )
        Mydc.Type.Add( "Pdf file containing xmp metadata" )
                                
        ' Basic Schema.
        Dim Mybs As BasicSchema  = MyXmp.BasicSchema
        Mybs.Advisory.Add( "Date" )
        Mybs.Advisory.Add( "Contributors" )
        Mybs.CreationDate = DateTime.Now
        Mybs.Nickname = "xyz"
        Mybs.Thumbnails.Add(106, 80, "JPEG", GetImage("C:\thumbnail.jpg"))
                                
        ' Rights Management Schema.
        Dim Myrm As RightsManagementSchema = New RightsManagementSchema
        Myrm.Marked = true
        Myrm.Owner.Add( "DynamicPDF" )
        Myrm.UsageTerms.AddLang( "en-us", "Contact ceTe Software" )
        MyXmp.AddSchema(Myrm)
                                
        ' Basic Job Ticket Schema.
        Dim MyJob As BasicJobTicketSchema = New BasicJobTicketSchema
        MyJob.JobRef.Add( "ceTe", "Xmp Test", new Uri( "http://www.cete.com/" ) )
        MyJob.JobRef.Add( "DynamicPDF", "XMP Metadata", new Uri( "http://www.dynamicpdf.com/" ) )
        MyXmp.AddSchema(MyJob)
                                
        ' Paged-Text Schema.
        Dim Mypt As PagedTextSchema = New PagedTextSchema
        MyXmp.AddSchema(Mypt)
                                        
        ' Need not have to add Dublic core schema, Basic Schema and 
        ' Adobe Pdf schema at this point. These are already added internally.
        MyXmp.AddSchema(Myrm)
        MyXmp.AddSchema(MyJob)
        MyXmp.AddSchema(Mypt)
                                
        ' Add the Xmp Metadata to the document
        MyDocument.XmpMetadata = MyXmp
                
        ' Save the PDF document
        MyDocument.Draw("C:\MyDocument.pdf")
                                
End Sub
                        
Private Function GetImage(ByVal filePath As String) As Byte()
                        
        Dim MyInFile As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
        Dim MyBinaryData(MyInFile.Length) As Byte
        MyInFile.Read(MyBinaryData, 0, MyInFile.Length)
        MyInFile.Close()                        
        return MyBinaryData
                
End Function
                        
End Module
[C#]
using System;
using System.IO;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.Xmp;
         
class MyClass
{
    static void Main()
    {
        // Create a PDF Document
        Document document = new Document();
        document.Keywords = "XMP, metadata, pdf, example";
        document.Title = "Pdf document with xmp metadata";
                
        // Add blank pages to the document
        document.Pages.Add( new Page( PageSize.Letter ) );
        document.Pages.Add( new Page( PageSize.Letter ) );
                
        // Create an Xmp Metadata
        XmpMetadata xmp = new XmpMetadata();
                
        // Dublin Core Schema.
        DublinCoreSchema dc = xmp.DublinCore;
        dc.Contributors.Add( "Abc" );
        dc.Contributors.Add( "Xyz" );
        dc.Contributors.Add( "Pqrs" );
        dc.Coverage = "To test all the attributes of schema's provided";
        dc.Creators.Add( "DynamicPDF" );
        dc.Creators.Add( "ceTe Software" );
        dc.Date.Add( DateTime.Now );
        dc.Description.AddLang( "en-us", "XMP Schema's test" );
        dc.Identifier = "First XMP pdf";
        dc.Publisher.Add( "DynamicPDF.com" );
        dc.Publisher.Add( "ceTe Software" );
        dc.Relation.Add( "test pdf with xmp" );
        dc.Rights.DefaultText = "ceTe Software Pvt. Ltd";
        dc.Rights.AddLang( "en-us", "All rights reserved 2006, ceTe software." );
        dc.Source = "XMP Project";
        dc.Subject.Add( "eXtensible Metadata Platform" );
        dc.Title.AddLang( "en-us", "XMP" );
        dc.Title.AddLang( "it-it", "XMP - Piattaforma Estendible di Metadata" );
        dc.Title.AddLang( "du-du", "De hallo Wereld" );
        dc.Title.AddLang( "fr-fr", "XMP - Une Platforme Extensible pour les Métédonnées" );
        dc.Title.AddLang( "DE-DE", "ÄËßÜ Hallo Welt" );
        dc.Type.Add( "Pdf file containing xmp metadata" );
        
        // Basic Schema.
        BasicSchema bs = xmp.BasicSchema;
        bs.Advisory.Add( "Date" );
        bs.Advisory.Add( "Contributors" );
        bs.CreationDate = DateTime.Now;
        bs.Nickname = "xyz";
        bs.Thumbnails.Add(106, 80, "JPEG", GetImage( @"C:\thumbnail.jpg" ) );
                
        // Rights Management Schema.
        RightsManagementSchema rm = new RightsManagementSchema();
        rm.Marked = true;
        rm.Owner.Add( "DynamicPDF" );
        rm.UsageTerms.AddLang( "en-us", "Contact ceTe Software" );
        xmp.AddSchema( rm );
                
        // Basic Job Ticket Schema.
        BasicJobTicketSchema job = new BasicJobTicketSchema();
        job.JobRef.Add( "ceTe", "Xmp Test", new Uri( "http://www.cete.com/" ) );
        job.JobRef.Add( "DynamicPDF", "XMP Metadata", new Uri( "http://www.dynamicpdf.com/" ) );
        xmp.AddSchema( job );
                
        // Paged-Text Schema.
        PagedTextSchema pt = new PagedTextSchema();
        xmp.AddSchema( pt );
                
        /* Need not have to add Dublic core schema, Basic Schema and 
        Adobe Pdf schema at this point. These are already added internally. */
        xmp.AddSchema( rm );
        xmp.AddSchema( job );
        xmp.AddSchema( pt );
                
        // Add the Xmp Metadata to the document
        document.XmpMetadata = xmp;
                
        // Save the PDF document
        document.Draw( @"C:\MyDocument.pdf" );
    }
            
    private static byte[] GetImage( string filePath )
    {
        FileStream inFile = new FileStream( filePath, FileMode.Open, FileAccess.Read );
        byte[] binaryData = new byte[ inFile.Length ];
        inFile.Read( binaryData, 0, (int)inFile.Length );
        inFile.Close();                 
        return binaryData;
    }
 }

See Also 

BasicSchema Class | BasicJobTicketSchema Class | DublinCoreSchema Class | PagedTextSchema Class | RightsManagementSchema Class | ceTe.DynamicPDF.Xmp Namespace | Programming with Generator for .NET