Reading and adding XMP metadata in EPS/PS documents in Java
Extract, inspect, add, and update XMP (Extensible Metadata Platform) metadata in EPS and PostScript (PS) documents using Aspose.Page for Java. Embed standard Dublin Core properties, document creation statistics, copyright details, and custom metadata structures directly into PostScript file streams without altering the underlying visual vector graphic content.
Aspose.Page for Java provides a high-performance XmpHeaderConverter and XmpMetadata object model to extract existing XMP metadata or inject new properties into EPS/PS files.
- To read information like author details, creation dates, copyright notices, and custom attributes from EPS files use
XmpMetadata.add()method. - To edit existing metadata fields like document titles or modification history use
XmpMetadata.set()method. - To add proprietary, enterprise-specific metadata attributes to graphic files use
XmpMetadata.registerNamespace()method.
Reading existing XMP metadata from an EPS File
Extract and parse standard and user-defined XMP properties from an EPS document to inspect metadata fields like dc:title, xmp:CreatorTool, and xmp:CreateDate.
import com.aspose.page.xps.XpsDocument;
import com.aspose.page.xps.XpsPrintTicket;
public class ReadXpsPrintTicket {
public static void main(String[] args) throws Exception {
// Open existing XPS document
XpsDocument doc = new XpsDocument("C:/XPSProject/Input/sample.xps");
// Retrieve the Job-level Print Ticket
XpsPrintTicket printTicket = doc.getJobPrintTicket();
if (printTicket != null) {
System.out.println("Print Ticket found in XPS package.");
// Print raw XML string content of the Print Ticket
System.out.println(printTicket.getXml());
} else {
System.out.println("No Job Print Ticket associated with this document.");
}
doc.close();
}
}Adding and injecting new XMP metadata into an EPS File
Inject standard metadata properties (such as Dublin Core or XMP Basic schemas) into an EPS document and save the updated file output.
import com.aspose.page.xps.XpsDocument;
import com.aspose.page.xps.XpsPrintTicket;
import java.io.FileInputStream;
public class AttachJobPrintTicket {
public static void main(String[] args) throws Exception {
// Load target XPS document
XpsDocument doc = new XpsDocument("C:/XPSProject/Input/document.xps");
// Read custom Print Ticket XML file specifying printer settings
FileInputStream ticketStream = new FileInputStream("C:/XPSProject/Config/custom_job_ticket.xml");
XpsPrintTicket customTicket = new XpsPrintTicket(ticketStream);
// Assign Print Ticket to Job level
doc.setJobPrintTicket(customTicket);
// Save updated XPS document
doc.save("C:/XPSProject/Output/document_with_print_ticket.xps");
ticketStream.close();
System.out.println("Job-level Print Ticket attached successfully.");
}
}Adding custom named namespaces and array metadata
Register enterprise-specific XML namespaces and store complex data types, such as array lists, inside the document’s XMP structure.
import com.aspose.page.xps.XpsDocument;
import com.aspose.page.xps.XpsPage;
import com.aspose.page.xps.XpsPrintTicket;
import java.io.FileInputStream;
public class AttachPagePrintTicket {
public static void main(String[] args) throws Exception {
XpsDocument doc = new XpsDocument("C:/XPSProject/Input/multi_page.xps");
// Get reference to the first page (Cover Page)
XpsPage coverPage = doc.getPage(1);
// Load cover-page specific print settings (e.g., Heavyweight Paper Tray)
FileInputStream coverTicketStream = new FileInputStream("C:/XPSProject/Config/cover_page_ticket.xml");
XpsPrintTicket coverTicket = new XpsPrintTicket(coverTicketStream);
// Set Print Ticket on Page 1
coverPage.setPagePrintTicket(coverTicket);
// Save compiled XPS package
doc.save("C:/XPSProject/Output/multi_page_custom_trays.xps");
coverTicketStream.close();
System.out.println("Page-level Print Ticket override attached to Page 1.");
}
}Installation and Setup
Add Aspose.Page for Java to your Maven:
Package Manager Console Command
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-page</artifactId>
<version>Latest</version>
</dependency>
FAQ
1. What is an XPS Print Ticket in Aspose.Page?
An XPS Print Ticket is an XML structure defined by the Print Schema specification. It embeds hardware print instructions (like orientation, duplex, copies, paper dimensions, and output trays) directly inside the .xps ZIP package file.
2. Can I modify individual XML parameters inside a Print Ticket dynamically?
Yes. You can retrieve the raw XML content via XpsPrintTicket.getXml(), manipulate the DOM nodes or attributes using standard Java XML parsers, and reassign the modified ticket back to the document or page.
3. What happens if both a Job-level and Page-level Print Ticket are present?
Page-level Print Tickets take priority over Job-level Print Tickets for that specific page, allowing developers to create mixed-media print jobs (e.g., cardstock cover pages mixed with standard plain text pages).