none
How to get the printer trays for each site with vsto? RRS feed

  • Question

  • hello,

    i need to get the defined printer trays for each site / Section.

    The solution i found needs to jump to every section and get the pageSetup-information.

    Is there a way to get the printer trays for each page without jumping to them?

    My "jumping"-solution is like this:

            public int GetNumberOfDocumentPages()

            {

                return _wordDocument.ComputeStatistics(WdStatistic.wdStatisticPages);

            }

     

            public List<int> GetPrinterTrays()

            {

                var list = new List<int>();

                var maxPage = GetNumberOfDocumentPages();

                var selection = _wordDocument.ActiveWindow.Selection;

                for (var i = 1; i <= maxPage; i++)

                {

                    selection.GoTo(WdGoToItem.wdGoToPage, WdGoToDirection.wdGoToAbsolute, i);

                    var sectionIndex = selection.Sections[1].Index;

                    var pageSetup = _wordDocument.Sections[sectionIndex].PageSetup;

                    list.Add((int)pageSetup.FirstPageTray);

                }

                return list;

            }

     

    Thanks

    Tobias

    Tuesday, November 29, 2011 8:39 AM

Answers

  • ok, now i got the solution (i think ;) )

    I have to get all Sections an use wdActiveEndPageNumber for each of them.

     

    var list = new List<int>();

      var sections = _wordDocument.Application.ActiveDocument.Sections;

    var nextPage = 1;

    foreach(Section section in sections)

     {

                    var range = section.Range;

                    var endPage = (int)range.Information[WdInformation.wdActiveEndPageNumber];

                    var firstPageTray = section.PageSetup.FirstPageTray;

                    for (var i = nextPage; i <= endPage; i++)

                        list.Add((int)firstPageTray);

                   

      nextPage = endPage + 1;

                }

    Tuesday, November 29, 2011 3:01 PM

All replies

  • I guess i found the solution by myself:

     

     

    var pages = _wordDocument.ActiveWindow.Panes[1].Pages;

                foreach (Page page in pages)

                {

                    var sectionIndex = page.Application.Selection.Sections[1].Index;

                    var pageSetup = _wordDocument.Sections[sectionIndex].PageSetup;

                    list.Add((int)pageSetup.FirstPageTray);

                }

     

    Tuesday, November 29, 2011 10:24 AM
  • sorry this is no solution.

    It always takes the printer tray of the section where the cursor is...

    Tuesday, November 29, 2011 1:29 PM
  • ok, now i got the solution (i think ;) )

    I have to get all Sections an use wdActiveEndPageNumber for each of them.

     

    var list = new List<int>();

      var sections = _wordDocument.Application.ActiveDocument.Sections;

    var nextPage = 1;

    foreach(Section section in sections)

     {

                    var range = section.Range;

                    var endPage = (int)range.Information[WdInformation.wdActiveEndPageNumber];

                    var firstPageTray = section.PageSetup.FirstPageTray;

                    for (var i = nextPage; i <= endPage; i++)

                        list.Add((int)firstPageTray);

                   

      nextPage = endPage + 1;

                }

    Tuesday, November 29, 2011 3:01 PM
  • Hi Tobias,

     

    Thanks for posting in the MSDN Forum.

     

    I’m glad to hear you have solved your issue. Thanks for sharing your solution here, it’s very beneficial for other community members who have similar issue to see how you solved your issue.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, December 1, 2011 5:00 AM
    Moderator