Unable to create XPS doc with A5 pages

I've been bashing my head against this on and off for days and finally accept defeat! How do you save or print items from an ItemsControl to an A5 page with a transform to fit the page?

I have 2 separate problems (I think):-

1) The XpsDocument ignores the PrintTicket and defaults to something like NorthAmericanLetter.

2) The items I'm trying to print are part of an existing visual tree. How can I scale and translate an item when writing it to the document without affecting what is currently rendered to the user?

This is the code I'm using:-

publicvoid SaveItems(ItemsControl ic,String fileName)

{

LocalPrintServer ps =newLocalPrintServer();

PrintQueue pq = ps.DefaultPrintQueue;

// Set the media size.

PrintTicket pt = pq.UserPrintTicket;

pt.PageMediaSize =newPageMediaSize(PageMediaSizeName.ISOA5Rotated, 794, 559);

// Set margins

constdouble cm = 96 / 2.54;

double xMargin = 1.25 * cm;

double yMargin = 1 * cm;

Double printableWidth = pt.PageMediaSize.Width.Value;

Double printableHeight = pt.PageMediaSize.Height.Value;

Double xScale = (printableWidth - xMargin * 2) / printableWidth;

Double yScale = (printableHeight - yMargin * 2) / printableHeight;

//Create package

Package package =Package.Open(fileName,FileMode.Create,FileAccess.ReadWrite);

XpsDocument doc =newXpsDocument(package);

XpsDocumentWriter writer =XpsDocument.CreateXpsDocumentWriter(doc);

VisualsToXpsDocument collator = writer.CreateVisualsCollator(pt, pt);

ItemContainerGenerator gen = ic.ItemContainerGenerator;

collator.BeginBatchWrite();

for (int i = 0; i < ic.Items.Count; ++i)

{

UIElement element = gen.ContainerFromIndex(i)asUIElement;

if (element ==null)continue;

Transform t = element.RenderTransform;

element.RenderTransform =newMatrixTransform(xScale, 0, 0, yScale, xMargin, yMargin);

collator.Write(element, pt);

//element.RenderTransform = t;

}

collator.EndBatchWrite();

doc.Close();

package.Close();

}

The resulting pages are something like 11 x 8.5 inches and the UIElements haven't been scaled or translated (though they are in the UI).

I've been through the SDK samples but they don't really provide any clues. They create visuals which aren't part of the visual tree and use the default page size.

Hoping someone on the XPS team can help.

Thanks

Michael

[9236 byte] By [Michael] at [2008-3-1]
# 1

Hi, Michael,

I can answer to the PrintTicket part of your question:

Print tickets are not used for formating pages when saving to XPS document. Your "collator.Write(element, pt)" call will just attach a PrintTicket part to the XPS page without using its content to modify the page. The default page size is NA Letter as you have noticed.

In addition, most XPS viewers will ignore the attached PrintTicket when displaying XPS pages.

Print ticket will be used when you eventually print created XPS file.

Regards

Hristo

HristoIvanov at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,XML Paper Specification (XPS)...
# 2
So how do you ceate a XPS file for a non-default page size? For example, a brochure or a poster.
kkennedy1008 at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,XML Paper Specification (XPS)...
# 3
I too have also hit the same problem.

Making changes in the printticket is too late in the equation for me. I need to save a new XPS document based on an original that is only a factor of its size.

Any help would be great thanks.

Colin.

Canderson at 2007-9-10 > top of Msdn Tech,Software Development for Windows Vista,XML Paper Specification (XPS)...

Software Development for Windows Vista

Site Classified