Mix landscape and portrait printing in wpf / c#

2.1k views Asked by At

In a WPF / C# app, I'm printing some pages by using DocumentPaginator. However, I want to mix in 1 printjob pages in Landscape and Portrait mode: e.g., Page 1 in Portrait, Page 2 in Landscape and Page 3 in Portrait.

However, if I change the PageSize (override from DocumentPaginator) to reflect the landscape, the Page remains in portrait mode.

In other words in

public class PrintPaginator : DocumentPaginator
    {
        public override Size PageSize { get; set; }
        public override DocumentPage GetPage(int pageNumber)
        {
            // size values
            Size theSizeOfThePage;
            // make size orientation correct
            if (pageNumber == 2)
            {
                // landscape: width is larger then height
                theSizeOfThePage = new Size(Math.Max(PageSize.Width, PageSize.Height), Math.Min(PageSize.Width, PageSize.Height));
            }
            else
            {
                // portrait: height is larger then width
                theSizeOfThePage = new Size(Math.Min(PageSize.Width, PageSize.Height), Math.Max(PageSize.Width, PageSize.Height));
            }
            PageSize = theSizeOfThePage;

            // set the grid as the page to print
            thePage = new Grid();
            thePage.Width = PageSize.Width;
            thePage.Height = PageSize.Height;

            [...]

            // return a documentpage wrapping the grid
            return new DocumentPage(thePage);
        }

I belief I can't set the Orientation or PageSize to Landscape earlier as this depends of the pagenumber that is being printed...

Any ideas, suggestions, workarrounds to mix portrait and landscape in 1 printjob?

Thanks! R.

1

There are 1 answers

0
Anthony Wieser On

A long time since you asked, I know, but have you tried setting the PageSize directly in the constructor of the call to new DocumentPage()?

More details on my blog: http://wieser-software.blogspot.co.uk/2012/07/landscape-printing-and-preview-in-wpf.html