com.cete.dynamicpdf.xmp
Class XmpMetadata


Example: This example shows how to create a Xmp Meta data and add it to the Xmp Metadata.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.xmp.*;
import java.io.*;
import java.util.*;
 
public class MyClass{
       public static void main(String args[]) throws MalformedURLException{
 
           // 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( "MyProduct" );
	   dc.getCreators().add( "MyCompany" );
	   dc.getDate().add( new Date() );
	   dc.getDescription().addLang( "en-us", "XMP Schema's test" );
	   dc.setIdentifier( "First XMP pdf" );
	   dc.getPublisher().add( "mydomain.com" );
	   dc.getPublisher().add( "MyCompany" );
	   dc.getRelation().add( "test pdf with xmp" );
	   dc.getRights().setDefault( "US English" );
	   dc.getRights().addLang( "en-us", "All rights reserved 2006,  MyCompany." );
	   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.setNickname( "xyz" );
	   bs.getThumbnails().add(106, 80, "JPEG", getImage( "[PhysicalPath]/thumbnail.jpg" ) );
	   
	   // Rights Management Schema.
           RightsManagementSchema rm = new RightsManagementSchema();
           rm.setMarked2(CopyrightStatus.PUBLICDOMAIN);
	   rm.getOwner().add( "MyProduct" );
	   rm.getUsageTerms().addLang( "en-us", "Contact MyCompany" );
	   xmp.addSchema( rm );
	   
	   // Basic Job Ticket Schema.
           BasicJobTicketSchema job = new BasicJobTicketSchema();           
              try {
            job.getJobRef().add( "MyCompany", "XMP Metadata", new URL( "http://www.mydomain.com" ) );
            } catch(MalformedURLException ex) {
            System.out.println("Error in the URL");
            }
           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;
       }	
 }