Unleashing The Power Of XPS-Based File Formats For Your

Download Report

Transcript Unleashing The Power Of XPS-Based File Formats For Your

Unleashing The Power Of XPS-Based
File Formats For Your Application
Jesse McGatha
DAT304
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.
WinFX 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
WinFX
APIs
Applications
WinFX
XPS Document
API
XPS
Document
Format
WinFX
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 v0.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
WinFX provides an API to make package
manipulation easy
API is in System.IO.Packaging namespace
Classes of interest
Package
PackagePart
PackagePartCollection
PackageRelationship
PackageRelationshipCollection
PackUriHelper
PackWebRequest
PackWebResponse
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:\Temp\PDCfile.docx”,
FileMode.Open);
// Find parts based on relationship type
string relType =
“http://schemas.microsoft.com/office/2006/relationships/officeDocument”;
PackageRelationshipCollection packRels =
package.GetRelationshipsByType(relType);
// Assuming there is only one relationship of this type
IEnumerator relsEnumerator = packRels.GetEnumerator();
relsEnumerator.MoveNext();
PackageRelationship rel = relsEnumerator.Current;
// For this sample, fetch only the first part in this collection
PackagePart part = package.GetPart(
PackUriHelper.ResolvePartUri(
new Uri(“/”, UriKind.Relative),
rel.TargetURI));
// Get the stream for this part
Stream partStream = part.GetStream();
11
Package Services
12
Common Package Services
WinFX 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
Core Properties
Category
Content Status
ContentType
Creator
DateCreated
DateModified
Description
Identifier
Keywords
Language
LastModifiedBy
LastPrinted
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 X509 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
Common Package Parts
Recommended
Parts
Signed Parts
Relationships
XPS Package
Signature Origin part is the root of all
signatures in the package
Each signature located in its own part
Signature Origin
Signature
X509 Cert
Resources
Relationship
Signature
X509 Cert
URI Reference
Signed part Signed part Signed part Signed part
16
Digital Signatures
APIs
Classes of interest
PackageDigitalSignature
PackageDigitalSignatureManager
PackageDigitalSignatureManager:
Get, add, or remove a signature to/from the package
PackageDigitalSignature
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
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 WinFX
Allows easy participation in RMS document workflows
API wraps the unmanaged RMS API
OLE Property Storage Core Properties
Core Properties
Relationships
XPS Package
RM “envelope”
In the System.Security.RightsManagement namespace
Signature Origin
RM
RMLicenses
Licenses
Common Package Parts
Signature
X509 Cert
Signature
X509 Cert
Signed part Signed part Signed part Signed part
19
Custom File Formats
20
Custom File Formats
Creating your own
Microsoft encourages applications to adopt
the packaging model for file management
WinFX 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
FixedDocumentSequence
FixedDocument
FixedPage
Font
Image
Thumbnail
PrintTicket
DocumentStructure
StoryFragments
– Root of the document
– Document XML markup
– Page XML markup
– Embedded font
– Embedded image
– Page thumbnail images
– Printer settings for page/document
– Semantic structure of document
– Semantic structure of page
Key XPS Document relationships
StartPart
RequiredResource
PrintTicket
– Points to the FixedDocumentSeq.
– Image/font needed to render page
– Printer settings
24
XPS Document Format
Core Properties
Common Package Parts
Thumbnail
Optional
Parts
Signature
X509 Cert
All parts signed
Relationships
XPS Package
Signature Origin
FixedDocumentSequence
FixedDocument
FixedPage
Required or
Recommended
Parts
Fixed Payload Parts
Resources
Relationship
URI Reference
DocumentStructure
Thumbnail
FontsFont
& Images
FixedPage
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
XpsDocument
IDocumentSequenceReader
IDocumentSequenceWriter
IFixedDocumentReader
IFixedDocumentWriter
IFixedPageReader
IFixedPageWriter
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 PrintTickets (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
ProcessContent determines if markup nested within an
ignored element should be processed
AlternateContent selects a Choice based on Required
namespaces
MustUnderstand triggers an immediate error when an
unknown namespace is specified
29
XPS Document
Markup compatibility sample
<FixedPage Height="1056" Width="816" xml:lang="en-US"
xmlns="http://schemas.microsoft.com/xps/2005/06"
xmlns:mc="http://schemas.microsoft.com/winfx/markupcompatibility/2005"
xmlns:mcext="http://schemas.example.com/PDC/example/extension1"
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:AlternateContent>
<mc:Choice Requires=“mcext">
<Path
mcext:Finish="GoldVarnish"
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="#C8C800"
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:AlternateContent>
</FixedPage>
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 WinFX 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
PRS333 – Advances in Document Workflow, Securing, Viewing,
and Printing Your Content
OFF304 – Developing for the 'Office12' User Experience
OFF415 – Developing Custom Workflows in ‘Office 12’
Presentation Track Lounge
Hands on Labs
PRSHOL27 Extend the XPS Document Viewing Experience
PRSHOL12 WinFX Printing and Archiving
PRSHOL11 Programming XPS Documents
Package and XPS related information:
Specifications: http://www.microsoft.com/whdc/xps
Email: [email protected]
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
PackageDigitalSignatureManager dsm = new
PackageDigitalSignatureManager(package);
// Get all Parts and add them to the List of Parts to be signed.
// Cannot pass GetParts() enumeration directly as it is
// invalidated during Sign process.
List<Uri> toSign = new List<Uri>();
foreach (PackagePart packagePart in package.GetParts())
{
toSign.Add(packagePart.Uri);
}
// Normally, you wrap this in a try/catch to detect
// when no certificates are available...
dsm.Sign(toSign); // Prompt user to select a Cert to sign with
35
Appendix: Core Properties
Markup sample
<CoreProperties
xmlns=“http://schemas.microsoft.com/package/2005/06/metadata/coreproperties”>
<Creator>Jesse McGatha</Creator>
<Title>PDC Presentation</Title>
<Subject>XML File Formats</Subject>
<Category>Presentation</Category>
<Keywords>XML;XPS;Office;Format</Keywords>
<Description>PDC presentation on XML file formats.</Description>
<ContentType>Presentation</ContentType>
<ContentStatus>Final</ContentStatus>
<Version>1.0</Version>
<Revision>231</Revision>
<DateCreated>07/21/2005 10:00:00</DateCreated>
<DateModified>07/22/2005 12:00:00</DateModified>
<LastModifiedBy>Jesse McGatha</LastModifiedBy>
<LastPrinted>07/22/2005 12:00:00</LastPrinted>
<Language>EN-US</Language>
<Identifier>DAT011</Identifier>
</CoreProperties>
36