ceTe Software Help Library for Java - January 2011 Comments on this topic
XMP MetaData
See Also
DynamicPDF Generator for Java > Programming With Generator for Java > XMP MetaData

Glossary Item Box

Welcome > Generator > Programming > XMPMetaData

 

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  applications work more efficiently 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.


[Java]
    import com.cete.dynamicpdf.*;
    import com.cete.dynamicpdf.xmp.*;
    import java.io.*;
    import java.util.*;
 
    public class MyClass{
        public static void main(String args[]){
           
            // Create a PDF Document
            Document document = new Document();
            document.setKeywords( "XMP, metadata, pdf, example");
            document.setTitle( "Pdf document with xmp metadata" );
           
            // Add blank pages to the document
            document.getPages().add( new Page( PageSize.LETTER ) );
            document.getPages().add( new Page( PageSize.LETTER ) );     
 
            // Create an Xmp Metadata
            XmpMetadata xmp = new XmpMetadata();
                   
            // Dublin Core Schema.
            DublinCoreSchema dc = xmp.getDublinCore();
            dc.getContributors().add( "Abc" );
            dc.getContributors().add( "Xyz" );
            dc.getContributors().add( "Pqrs" );
            dc.setCoverage( "To test all the attributes of schema's provided" );
            dc.getCreators().add( "DynamicPDF" );
            dc.getCreators().add( "ceTe Software" );
            dc.getDate().add( new Date() );
            dc.getDescription().addLang( "en-us", "XMP Schema's test" );
            dc.setIdentifier( "First XMP pdf" );
            dc.getPublisher().add( "DynamicPDF.com" );
            dc.getPublisher().add( "ceTe Software" );
            dc.getRelation().add( "test pdf with xmp" );
            dc.getRights().setDefault( "ceTe Software Pvt. Ltd" );
            dc.getRights().addLang( "en-us", "All rights reserved 2008, ceTe software." );
            dc.setSource( "XMP Project" );
            dc.getSubject().add( "eXtensible Metadata Platform" );
            dc.getTitle().addLang( "en-us", "XMP" );
            dc.getTitle().addLang( "it-it", "XMP - Piattaforma Estendible di Metadata" );
            dc.getTitle().addLang( "du-du", "De hallo Wereld" );
            dc.getTitle().addLang( "fr-fr", "XMP - Une Platforme Extensible pour les Métédonnées" );
            dc.getTitle().addLang( "DE-DE", "ÄËßÜ Hallo Welt" );
            dc.getType().add( "Pdf file containing xmp metadata" );
                   
            // Basic Schema.
            BasicSchema bs = xmp.getBasicSchema();
            bs.getAdvisory().add( "Date" );
            bs.getAdvisory().add( "Contributors" );
            bs.setCreationDate( new Date());
            bs.setNickname( "xyz" );
            bs.getThumbnails().add(106, 80, "JPEG", getImage( "C:\thumbnail.jpg" ) );
           
            // Rights Management Schema.
            RightsManagementSchema rm = new RightsManagementSchema();
            rm.setMarked( true );
            rm.getOwner().add( "DynamicPDF" );
            rm.getUsageTerms().addLang( "en-us", "Contact ceTe Software" );
            xmp.addSchema( rm );
           
            // Basic Job Ticket Schema.
            BasicJobTicketSchema job = new BasicJobTicketSchema();
            job.getJobRef().add( "ceTe", "Xmp Test", new URL( "http://www.cete.com/" ) );
            job.getJobRef().add( "DynamicPDF", "XMP Metadata", new URL( "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. */
           
            // Add the Xmp Metadata to the document
            document.setXmpMetadata( xmp );             
                                         
            // Save the PDF
            document.draw("[PhysicalPath]/MyDocument.pdf");
        }
       
        private static byte[] getImage( String filePath ) {
            byte[] binaryData = null;   
            try {
                FileInputStream inFile = new FileInputStream( filePath );
                binaryData = new byte[ inFile.available() ];
                inFile.read( binaryData );
                inFile.close();
            } catch(Exception e) {
            System.out.println("EXCEPTION  "+e.getMessage());
            }           
            return binaryData;
        }       
 }

See Also

©2011. All rights Reserved.