NiXPS
Friday, November 05, 2010
  WPF visual to PDF - control page size
With our NiPDF library it is very easy to build PDF based on WPF visuals. It is literally a few lines of code which you can find documented on our website.

This week I got the question from a customer who wanted to influence the page size.

This is fairly easy to do by means of the PrintTicket class.
In line with the example on our website, the second step becomes:


// STEP 2: Convert this WPF Visual to an XPS Document
MemoryStream lMemoryStream = new MemoryStream();
{
Package package = Package.Open(lMemoryStream, FileMode.Create);
XpsDocument doc = new XpsDocument(package);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
//Create PrintTicket for document and set its page size to the proper custom page size
PrintTicket printTicket = new PrintTicket();
//Set the page size to a custom 3.5" x 2.5" page
printTicket.PageMediaSize = new PageMediaSize(3.5 * 96.0, 2.5 * 96.0);
writer.Write(visual,printTicket);
doc.Close();
package.Close();
}


Easy to do, provided you know how to do it - as always!
 

Archives
September 2006 / October 2006 / November 2006 / December 2006 / January 2007 / February 2007 / March 2007 / April 2007 / May 2007 / June 2007 / July 2007 / August 2007 / September 2007 / October 2007 / November 2007 / December 2007 / January 2008 / February 2008 / March 2008 / April 2008 / May 2008 / June 2008 / July 2008 / August 2008 / September 2008 / October 2008 / November 2008 / December 2008 / January 2009 / February 2009 / March 2009 / April 2009 / May 2009 / June 2009 / July 2009 / August 2009 / September 2009 / October 2009 / November 2009 / December 2009 / January 2010 / February 2010 / March 2010 / April 2010 / May 2010 / June 2010 / July 2010 / September 2010 / October 2010 / November 2010 / January 2011 /

NiXPS home
XPS info from the creators
    follow me on Twitter
    Add to Technorati Favorites

    Subscribe to
    Posts [Atom]