2

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.

Robbie
  • 715
  • 3
  • 10
  • 18
  • I haven't done any research on what you are asking but will say that having a width that is larger then height is basically invalid in most programming instances. Setting it like this doesn't rotate the page, in fact, most languages will simply 'fix' what it feels is incorrect and reverse these leaving you with the same page size. You really need to look for an orientation or rotate command/feature. – Douglas Anderson Oct 16 '11 at 21:22

1 Answers1

3

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

Anthony Wieser
  • 4,351
  • 1
  • 23
  • 25