Unleashing The Power Of XPSBased File Formats For
Unleashing The Power Of XPS-Based File Formats For Your Application Jesse Mc. Gatha DAT 304 Program Manager Microsoft Corporation 1
Session Outline Packages File Format Definitions Developer Scenarios Package Overview (Demo) Package Services Core Properties Digital Signatures (Demo) Rights Management Custom File Formats Solution Development XPS Extensibility 2
Session Goals Understand the basic package architecture Basic package format Package services Explore different formats built on packages XPS Documents Office “ 12” files (. docx, . pptx, . xlsx) Custom formats Understand the benefits of the architecture Transparency Flexibility Robustness Reduced sustained engineering cost Many developer opportunities 3
File Format Definitions XML Paper Specification XPS: The XML Paper Specification Packages: The foundation of many file formats XPS Document Format Office “ 12” Open XML Formats Custom Formats Package Services Parts and Relationships Abstraction ZIP Open Packaging Conventions Specification 4
Package And XPS Technologies Open Specifications Open Packaging Conventions and XML Paper Specification (XPS) for use by devices and any application on any platform. Win. FX APIs Application programming interfaces (APIs) to manage package and content. XPS Print Path Print pipeline with integrated spool format and printer -page description language to speed and improve print jobs fidelity. New driver model. Print Driver to “Save As” XPS Document A print-to-file converter for creating XPS Documents from any Microsoft Windows-based application. XPS Viewer A WPF utility that allow users to view, protect and print XPS Documents. Hosted in IE. 5
Developer Scenarios 1. Build custom file formats 2. Access XPS Document and Office “ 12” content directly 3. Provide document solutions for XPS Document, Office “ 12” or custom files Win. FX APIs Applications Win. FX XPS Document API XPS Document Format Win. FX Package API Custom APIs Office “ 12” Open XML Formats Custom Format 6
Packaging Model Provides foundation of a file format Described in the Open Packaging Conventions Specification v 0. 75 Usable by any application Multiple implementations underway XPS Document and Office “ 12” Open XML formats Built on concepts of parts and relationships Parts are streams of data (XML or binary) Relationships describe how parts are related Stored in a ZIP archive 7
Inspecting A Package Using ZIP Utilities 8
Packaging APIs Classes Win. FX provides an API to make package manipulation easy API is in System. IO. Packaging namespace Classes of interest Package. Part. Collection Package. Relationship. Collection Pack. Uri. Helper Pack. Web. Request Pack. Web. Response 9
Packaging APIs API Functionality Open and close packages Create and delete parts and relationships Get the name, content-type, and stream for parts Read and write part streams Get the ID, type, and target URI for relationships 10
Packaging APIs Sample code – read data from package // Open existing package Package package = Package. Open(“C: TempPDCfile. docx”, File. Mode. Open); // Find parts based on relationship type string rel. Type = “http: //schemas. microsoft. com/office/2006/relationships/office. Document”; Package. Relationship. Collection pack. Rels = package. Get. Relationships. By. Type(rel. Type); // Assuming there is only one relationship of this type IEnumerator rels. Enumerator = pack. Rels. Get. Enumerator(); rels. Enumerator. Move. Next(); Package. Relationship rel = rels. Enumerator. Current; // For this sample, fetch only the first part in this collection Package. Part part = package. Get. Part( Pack. Uri. Helper. Resolve. Part. Uri( new Uri(“/”, Uri. Kind. Relative), rel. Target. URI)); // Get the stream for this part Stream part. Stream = part. Get. Stream(); 11
Package Services 12
Common Package Services Win. FX provides APIs for common package services Core Properties Digital Signatures Rights Management 13
Core Properties Package may include a set of metadata in a single XML part: The core properties part Discovered by a root relationship with a specific relationship type Uses a specific content type Common Package Parts Relationships XPS Package XPS Document and Office “ 12” files both support core properties Core Properties Category Content Status Content. Type Creator Date. Created Date. Modified Description Identifier Keywords Language Last. Modified. By Last. Printed Revision Subject Title Version 14
Digital Signatures Allow you to validate that the signed content has not been tampered with Available for all package-based file formats Follow well-known standards: Compatible with the XML Digital Signature standard Certificates follow X 509 standard Parts signed are determined by the signing policy Example: XPS Document policy is to sign all defined parts and relationships Can be extended by the particular format 15
Digital Signatures Model Core Properties Relationships XPS Package Signature Origin part is the root of all signatures in the package Each signature located in its own part Signature Origin Common Package Parts Signature X 509 Cert Recommended Parts Signed Parts Resources Relationship URI Reference Signed part 16
Digital Signatures APIs Classes of interest Package. Digital. Signature. Manager: Get, add, or remove a signature to/from the package Package. Digital. Signature Get the list of parts signed by the signature Get the list of references to signed relationships Get the list of signed and unsigned objects in the signature Verify the signature certificate 17
Digital Signatures 18
Rights Management May use any RM solution RM is external to the XPS Specification Windows RMS solution provided with Win. FX Allows easy participation in RMS document workflows API wraps the unmanaged RMS API OLE Property Storage Core Properties Relationships XPS Package RM “envelope” In the System. Security. Rights. Management namespace Signature Origin RM RMLicenses Common Package Parts Signature X 509 Cert Signed part 19
Custom File Formats 20
Custom File Formats Creating your own Microsoft encourages applications to adopt the packaging model for file management Win. FX APIs make this easy Makes building solutions around your application easier Factor your data Decide how to split your application’s data between parts Use XML parts to store data that can be represented textually Use binary parts to store other data For XML parts, define your own namespace 21
Custom File Formats More on creating your own Make use of relationships Define your own relationship types Prefer relationships over inline URI references They are a great way to attach a metadata part to other parts (particularly binary parts) Take advantage of common package services E. g. core properties, digital signatures 22
XPS Document Implementation 23
XPS Document Parts and relationships Key XPS Document parts Fixed. Document. Sequence – Root of the document Fixed. Document – Document XML markup Fixed. Page – Page XML markup Font – Embedded font Image – Embedded image Thumbnail – Page thumbnail images Print. Ticket – Printer settings for page/document Document. Structure – Semantic structure of document Story. Fragments – Semantic structure of page Key XPS Document relationships Start. Part – Points to the Fixed. Document. Seq. Required. Resource – Image/font needed to render page Print. Ticket – Printer settings 24
XPS Document Format Core Properties Common Package Parts Thumbnail Optional Parts Signature X 509 Cert All parts signed Relationships XPS Package Signature Origin Fixed. Document. Sequence Fixed. Document Fixed. Page Required or Recommended Parts Fixed Payload Parts Resources Relationship URI Reference Document. Structure Thumbnail Fonts. Font & Images Fixed. Page Thumbnail 25
XPS Documents Solution development APIs Supersede package APIs for XPS Document solutions Create, consume, and service XPS Documents Tailored to the specific needs of XPS Documents API is in System. Windows. Xps. Packaging namespace Classes of interest Xps. Document IDocument. Sequence. Reader IDocument. Sequence. Writer IFixed. Document. Reader IFixed. Document. Writer IFixed. Page. Reader IFixed. Page. Writer 26
XPS Documents API functionality Document manipulation Add/remove documents to document sequence and pages to documents Retrieve or set core properties Retrieve or set thumbnails Add page content E. g. colors, fonts, images, resource dictionaries Retrieve/Set Print. Tickets (print job control XML) Digital Signatures Automatically sign according to XPS Document signing policy Specify co-signature requirements 27
XPS Document Extensibility XPS Documents may be extended through the use of markup compatibility Identical to Windows Presentation Foundation (XAML) markup compatibility Designed to support backward and forward compatibility The only proper way to add new features intermixed with XPS Document markup XPS Viewer will reject files with unknown markup 28
XPS Document Markup compatibility XML parts are processed for compatibility during loading Process unknown XML namespaces, elements, and attributes By default, unknown elements/attributes trigger errors Ignorable suppresses errors triggered by elements/attributes in unknown namespaces Process. Content determines if markup nested within an ignored element should be processed Alternate. Content selects a Choice based on Required namespaces Must. Understand triggers an immediate error when an unknown namespace is specified 29
XPS Document Markup compatibility sample <Fixed. Page Height="1056" Width="816" xml: lang="en-US" xmlns="http: //schemas. microsoft. com/xps/2005/06" xmlns: mc="http: //schemas. microsoft. com/winfx/markup-compatibility/2005" xmlns: mcext="http: //schemas. example. com/PDC/example/extension 1" mc: Ignorable=" mcext" " > mc: Ignorable="mcext <Path Stroke="#000000" Data="M 20, 70 A 50, 50 0 1 1 120, 70 A 50, 50 0 1 1 20, 70 Z" /> <mc: Alternate. Content> <mc: Choice "> <mc: Choice Requires=“mcext"> <Path mcext: Finish=" Gold. Varnish" " mcext: Finish="Gold. Varnish Data="M 20, 70 A 50, 50 0 1 1 120, 70 A 50, 50 0 1 1 20, 70 Z" /> </mc: Choice> <mc: Fallback> <Path Fill="#C 8 C 800" Opacity="0. 2" Data="M 20, 70 A 50, 50 0 1 1 120, 70 A 50, 50 0 1 1 20, 70 Z" /> </mc: Fallback> </mc: Alternate. Content> </Fixed. Page> 30
Conclusion 31
Benefits Transparency Really see what is in your files Great for archiving – you don’t need particular applications Flexibility Formats are extensible with custom data Formats can easily be integrated into solutions and workflows Robustness ZIP is recoverable Compression benefits file size Reduced sustained engineering costs Use the Win. FX API for managing files rather than a custom API Lots of developer opportunities Open formats do not require integration of the original application to build a solution Packages and XPS Documents a broader part of a full suite of technologies 32
Community Resources At PDC For more information, go see PRS 333 – Advances in Document Workflow, Securing, Viewing, and Printing Your Content OFF 304 – Developing for the 'Office 12' User Experience OFF 415 – Developing Custom Workflows in ‘Office 12’ Presentation Track Lounge Hands on Labs PRSHOL 27 Extend the XPS Document Viewing Experience PRSHOL 12 Win. FX Printing and Archiving PRSHOL 11 Programming XPS Documents Package and XPS related information: Specifications: http: //www. microsoft. com/whdc/xps Email: prninfo@microsoft. com XPS conformance test suite planned for Windows Vista WDK Beta 2 Office Open XML formats Office Preview Site: http: //www. microsoft. com/office/preview/ Brian Jones’s Blog: http: //blogs. msdn. com/Brian_Jones/ Office 2003 Reference Schema Information: http: //www. microsoft. com/office/xml/ 33
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 34
Appendix: Digital Signatures Sample code // Assume package contains the Package to sign Package. Digital. Signature. Manager dsm = new Package. Digital. Signature. Manager(package); // Get all Parts and add them to the List of Parts to be signed. // Cannot pass Get. Parts() enumeration directly as it is // invalidated during Sign process. List<Uri> to. Sign = new List<Uri>(); foreach (Package. Part package. Part in package. Get. Parts()) { to. Sign. Add(package. Part. Uri); } // Normally, you wrap this in a try/catch to detect // when no certificates are available. . . dsm. Sign(to. Sign); // Prompt user to select a Cert to sign with 35
Appendix: Core Properties Markup sample <Core. Properties xmlns=“http: //schemas. microsoft. com/package/2005/06/metadata/coreproperties”> <Creator>Jesse Mc. Gatha</Creator> <Title>PDC Presentation</Title> <Subject>XML File Formats</Subject> <Category>Presentation </Category> <Category>Presentation</Category> <Keywords>XML; XPS; Office; Format </Keywords> <Keywords>XML; XPS; Office; Format</Keywords> <Description>PDC presentation on XML file formats. </Description> <Content. Type> > Content. Type>Presentation</Content. Type <Content. Status> > Content. Status>Final</Content. Status <Version>1. 0 </Version> <Version>1. 0</Version> <Revision>231 </Revision> <Revision>231</Revision> <Date. Created> > Date. Created>07/21/2005 10: 00: 00</Date. Created <Date. Modified> > Date. Modified>07/22/2005 12: 00: 00</Date. Modified <Last. Modified. By> > Last. Modified. By>Jesse Mc. Gatha</Last. Modified. By <Last. Printed> > Last. Printed>07/22/2005 12: 00: 00</Last. Printed <Language>EN-US </Language> <Language>EN-US</Language> <Identifier>DAT 011 </Identifier> <Identifier>DAT 011</Identifier> </Core. Properties> 36
- Slides: 36