gwa000

i'm trying to learn XPS and have been reading the MSDN article "A First Look at APIs For Creating XML Paper Specification Documents" that was in the january 2006 issue.

while i have gotten it to compile and can use it to list the images in an XPS file, i am having issues with two of the other functions of the sample program.

the first is using the XamlToXps parameter in that i can not seem to get an XAML file to load. i tried to use the the XAML code supplied in figure 6 but that gives an error.

the other is trying to use an XML file as input to the ProcessDoc parameter. for that i tried using a Word 2003 document save out to XML and that does not work.

does anyone have a sample file for each of these options that they know works so i can explore the functionality of the sample program in the article.

thanks!




Re: XML Paper Specification (XPS) MSDN XPS article sample files

adrian ford [MSFT]

Hi Gary, That article was written for pre-release version and published in MSDN magazine in Jan 2006. You¡¯ll probably find the samples provided for Documents in WPF, including XPS, published at http://msdn2.microsoft.com/en-us/library/ms771612.aspx more useful.

The specific XAML problem you have can be fixed by adding the namespace declaration for the FixedDocument element. For a description of FixedDocument, along with the namespace, see http://msdn2.microsoft.com/en-us/library/system.windows.documents.fixeddocument.aspx. XAMLPad (http://msdn2.microsoft.com/en-us/library/ms742398.aspx ) and Charles Petzold¡¯s XMAL Cruncher (http://charlespetzold.com/wpf/index.html) are useful tools for working with XAML.

The description for ProcessAppDoc in the code is:

/// <summary>

/// Method to read a document definition file containing

/// XPS page markup and image references and create an

/// XPS Document from that file.

/// </summary>

i.e. the content in the XML description supplied as markup must by valid XPS markup. The implementation of ProcessAppDoc simply writes the supplied markup into an XPS FixedPage, see the following:

// write the page to the document

xmlWriter.WriteRaw(appPageText[0].InnerText);

it doesn't convert arbitrary XML to XPS page markup.

It sounds like you found other changes since the sample was written - but for other readers note that other problems include changes to .Net namespaces (e.g. System.Windows.Serialization) and assemblies, and the need to set Single Thread Apartment (STA) mode.

HTH






Re: XML Paper Specification (XPS) MSDN XPS article sample files

gwa000

adrian,

thanks for the information.

after i posted the original note i tried the "http://schemas.microsoft.com/winfx/2006/xaml/presentation" namspace and with that i also get an error.

specifically, the error is:

Exception The tag 'FixedDocument' does not exist in XML namespace ''. Line '1' Position '2'.

if i move the namespace right after the FixedDocument statement i get the same error. what i have is:

<FixedDocument>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<PageContent>
<FixedPage
Background="#EEEEEE"
Width="800" Height="500"
<Canvas FixedPage.Top="10" FixedPage.Left="20">

.....

</Canvas>
</FixedPage>
</PageContent>
</FixedDocument>

however, if i move the namespace back to after the FixedPage statement and delete the FixedDocument and PageContent statements like this:

<FixedPage

Background="#EEEEEE"
Width="800" Height="500"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Canvas FixedPage.Top="10" FixedPage.Left="20">

.....

</Canvas>
</FixedPage>

then it works and the XPS document is created.

even though i can get an XPS document created now from some XAML code i'm still curious as to whether or not having the FixedDocument statements is valid. and if so, what needs to be changed to allow it to not get an error.






Re: XML Paper Specification (XPS) MSDN XPS article sample files

adrian ford [MSFT]

Did you try it in XAMLPad

The following works (provided you have an image available):

Code Block
<FixedDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<PageContent>
<FixedPage
Background="#EEEEEE"
Width="800" Height="500"
xmlns="
http://schemas.microsoft.com/xps/2005/06" xml:lang="en-US">
<Canvas FixedPage.Top="10" FixedPage.Left="20">
<TextBlock Height="20" Canvas.Top="20" FontSize="18">
This is a photo from my recent vacation.
</TextBlock>
<TextBlock Height="20" Canvas.Top="40" FontSize="18">
I had a great time visiting the different places
</TextBlock>
<TextBlock Height="20" Canvas.Top="60" FontSize="18">
and seeing all the sights, but my favorite
</TextBlock>
<TextBlock Height="20" Canvas.Top="80" FontSize="18">
place to visit was Cape Canaveral.
</TextBlock>
<Rectangle
Canvas.Top="120" Canvas.Left="60"
Width="150" Height="150">
<Rectangle.Fill>
<SolidColorBrush Opacity="1" Color="Orange"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle
Canvas.Top="140" Canvas.Left="40"
Width="150" Height="150">
<Rectangle.Fill>
<ImageBrush
Opacity="1"
ImageSource="images/Rockets.jpg" />
</Rectangle.Fill>
</Rectangle>
</Canvas>
</FixedPage>
</PageContent>
</FixedDocument>







Re: XML Paper Specification (XPS) MSDN XPS article sample files

gwa000

adrian,

thanks so much for your help.

the reason why i was still getting an error was because i did not remove the "greater than" sign from the end of the FixedDocument line. i was simply copying the namespace line after the FixedDocument line.






Re: XML Paper Specification (XPS) MSDN XPS article sample files

sybarite

hello gary..how did you get the XamlStreamToXps function to work





Re: XML Paper Specification (XPS) MSDN XPS article sample files

gwa000

by using a valid XAML file. the one that came with the MSDN article was not valid. if you use the one the Adrian posted above then it should work (provided that you enter the correct format for the program parameters).