Page

How can I set the page size and other PageSetup parameters when creating and printing an XpsDocument

PrintTicket pt = printQueue.UserPrintTicket;

pt.PageMediaSize.PageMediaSizeName = PageMediaSizeName.ISOA5;

seemed like the obvious thing but it is readonly.

Thanks

Michael



Answer this question

Page

  • LeXXik

    Michael,

    You are very close with your current sample. The PageMediaSize is actually a class so you have to assign the property to a new instance of the class. Here is an example:

    PrintTicket pt = printQueue.UserPrintTicket;

    pt.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA5);

    Thanks.

    Daniel Emerson (MSFT)


  • syiown8

    Michael,

    These properties are only set if you assign values in the PageMediaSize constructor. There is an overload of the form PageMediaSize(Name, Width, Height) that will enable you to query these values..

    Thanks.

    -Daniel Emerson (MSFT)


  • PhillCloke

    Daniel,

    (our posts maybe just crossed)

    I'm using the overloaded constructor but isn't ISOA5 a known size I'd like to understand the reasoning as to why Width and Height are not set to a default for the passed PageMediaSizeName. It means every WPF program must store these defaults when it could very easily be done by the runtime.

    Thanks

    Michael


  • ITSMEAGAIN

    penny finally dropped. :)

    PrintTicket pt = queue.UserPrintTicket;

    pt.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA5);

    but the following return nulls:-

    Double printableWidth = pt.PageMediaSize.Width;

    Double printableHeight = pt.PageMediaSize.Height;

    Shouldn't these return the size of ISOA5

    Bug

    Michael


  • Santosh A H

    Hi Daniel,

    Yes the penny finaly dropped - see second post.

    ... but why does pt.PageMediaSize.Width return null (same for Height) if it has been initalized with IS0A5

    Thanks

    Michael


  • Page