Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 31

Visual Studio® 2008:

Windows® Presentation
Foundation
Module 7: Managing Documents
• Creating and Viewing Flow Documents

• Creating and Viewing Fixed Documents

• Packaging Documents

• Printing Documents
Lesson: Creating and Viewing Flow Documents
• What Are Flow Documents?

• Defining a Flow Document

• Types of Flow Document Containers

• Demonstration: Defining FlowDocument Containers

• Flow-Related Controls

• Customizing Text

• Demonstration: Customizing Text in a FlowDocument


What Are Flow Documents?

Flow documents:
• Are a XAML construct for holding large blocks of textual data
• Provide an optimized viewing and reading experience
• Dynamically adjust and reflow content
• Provide additional viewing features
 Searching
 Navigation
 Zooming
Defining a Flow Document
• Define a FlowDocument element

• Add child elements

<FlowDocument>
<Paragraph>
This is a paragraph.
</Paragraph>
<Paragraph>
<Italic>This</Italic> is <Bold>another</Bold>
paragraph. This paragraph has more formatting
<Span FontFamily="Lucida Handwriting">
than the first</Span>.
</Paragraph>
</FlowDocument>
Types of Flow Document Containers
Host the <FlowDocument> in a viewer control

• FlowDocumentReader
• FlowDocumentPageViewer and FlowDocumentScrollViewer
• RichTextBox

<FlowDocumentReader>
<FlowDocument> Zoom
...
</FlowDocument>
</FlowDocumentReader>

Search
Navigation Viewing Mode
Demonstration: Defining FlowDocument Containers
In this demonstration, you will see how to:
• Define a FlowDocumentReader

• Examine the Zoom and View Mode features

• Replace the FlowDocumentReader with a RichTextBox

• Modify the text formatting in the RichTextBox


Flow-Related Controls

Block-derived classes:
• Paragraph
• Section
• BlockUIContainer
• List
• Table

Inline-derived classes:
• Run
• Span
• Hyperlink
• Bold
• Italic
• LineBreak
Customizing Text
Text is the primary type of content in a flow document
• To decorate text, set the TextDecorations property
• To set typographical values, set the Typography property

...
<Run Typography.NumeralStyle="Normal">1234567890</Run>
<Run Typography.NumeralStyle="OldStyle">1234567890</Run>
...
<Paragraph TextDecorations="Strikethrough">
Example with StrikeThrough TextDecoration
</Paragraph>
...
Demonstration: Customizing Text in a FlowDocument
In this demonstration, you will see how to:
• Change the TextDecorations property of a Paragraph
element
• Change the Typography settings of a Paragraph element
Lesson: Creating and Viewing Fixed Documents
• What Are Fixed Documents?

• Defining Fixed Documents

• Defining a Fixed Document Viewer

• Demonstration: Creating a FixedDocument in XAML


What Are Fixed Documents?
Fixed documents:

• Are static, read-only, portable documents


• Provide WYSIWYG presentation
• Are independent of the display or printer hardware
Defining Fixed Documents
• Define a FixedDocument element

• Add child FixedPage elements via PageContent instances

• Add UIElement-derived classes to FixedPage instances

<FixedDocument>
<PageContent>
<FixedPage>
<TextBlock Text="This is a fixed document." />
...
Defining a Fixed Document Viewer
Host the fixed document in a viewer control

• Use a DocumentViewer control


• Set the Document property of the DocumentViewer to the
FixedDocument instance

Zoom Viewing Mode

<DocumentViewer>
<DocumentViewer.Document>
<FixedDocument ...>
...

Search
Demonstration: Creating a FixedDocument in XAML
In this demonstration, you will see how to:
• Create a new PageContent element

• Create new content for the second page

• View both pages in the DocumentViewer


Lesson: Packaging Documents
• Support for Packaging Documents

• Packaging Document Parts into a ZIP File

• Digitally Signing Content

• Associating Information with Packages and Parts

• Demonstration: Creating a Digitally Signed ZipPackage


Support for Packaging Documents
The WPF Packaging API enables you to:
• Pull together related data, document content, and resources
• Store and access objects from a single entity
• Digitally sign parts of a package
• Associate information with packages and parts
Packaging Document Parts into a ZIP File

To create a Package by using the Packaging APIs, you:


• Create a ZipPackage

Package targetPackage = ZipPackage.Open


("MyDocument.zip", FileMode.Create)
...

• Create ZipPackagePart objects

PackagePart part = targetPackage.CreatePart


(documentPartUri, "text/xml");
...
StreamWriter w = new StreamWriter(part.GetStream());
w.Write("<Document>...");
...
Digitally Signing Content

To digitally sign parts of a: package


• Decide the PackageParts to be signed by URI
List<Uri> partsToSign = new List<Uri>();
...
• Get a reference to your X.509 certificate

X509Certificate2 x509Cert = new X509Certificate2


(@"..\..\TestCert.pfx", "password");
...

• Create a PackageDigitalSignatureManager for a Package and


sign the target package
dsm = new PackageDigitalSignatureManager(package);
dsm.Sign(partsToSign, x509Cert);
...
Associating Information with Packages and Parts
To associate information with packages and parts:

• Create a PackageRelationship
• Define dependency relationships
• Define informational relationships

...
package.CreateRelationship
(imagePartUri, TargetMode.Internal,
"http://packages/2008/resource");
...
Demonstration: Creating a Digitally Signed
ZipPackage
In this demonstration, you will see how to:
• Create a ZipPackage

• Sign a PackagePart

• Load a ZipPackage

• Verify the signed PackagePart


Notes Page Over-flow Slide. Do Not Print Slide.
See Notes pane.
Lesson: Printing Documents
• What Is the XML Paper Specification?

• Demonstration: Printing Documents

• Controlling Print Jobs

• Managing the Print Queue


What Is the XML Paper Specification?
An XPS document:

• Is a package that contains one or more fixed documents


• Contains resources and information required for rendering
 Fonts (OpenType and TrueType)
 Images (TIFF, PNG, JPEG, and WMP for bitmaps)
 Application data
Demonstration: Printing Documents
In this demonstration, you will see how to:
• Create a PrintDialog and return a PrintQueue

• Create an XpsDocumentWriter

• Write the document to the PrintQueue by using the


XpsDocumentWriter
Notes Page Over-flow Slide. Do Not Print Slide.
See Notes pane.
Controlling Print Jobs
To query printer capabilities:

• Get a PrintCapabilities object for the printer


• Query properties on the PrintCapabilities object

To instruct a printer how to process a print job:


• Get a PrintTicket object for the printer
• Configure properties on the PrintTicket object by using
information about the printer capabilities
Managing the Print Queue
To manage jobs on a print queue:

• Create a PrintServer object representing the print server


• Create a PrintQueue object representing the print queue
• Query the status of the queue
• Query the queue for a list of jobs pending
• Invoke methods on the PrintSystemJobInfo to:
 Add
 Pause
 Resume
 Purge
Lab: Managing Documents
• Exercise 1: Creating and Displaying Flow Documents

• Exercise 2: Printing Documents

• Exercise 3: Creating and Signing XPS Documents

Logon information
Virtual machine 6460-LON-DEV-07

User name Student

Password Pa$$w0rd

Estimated time: 60 minutes


Lab Review
• What is the name of the control used for editing
FlowDocument instances?
• Which overload of the PrintDialog.PrintDocument
method is used to print a document that supports
pagination?
• What class is used to represent an X.509 certificate when
signing an XPS document?
Module Review and Takeaways
• Review Questions

• Common Issues and Troubleshooting Tips

• Best Practices

• Tools

You might also like