How do you query a report to determine if it will print in portrait or landscape?

  • I'm trying to query reports to detemine whether they will print in portrait or landscape mode.

    The closest I can get to is the DefaultPageSize, but this shows as 850x1100 for all reports, even those that are 1100x850 (landscape).

    I'm using:

    Microsoft.Reporting.WinForms.ReportPageSettings PageSettings;

    PageSettings = reportViewer1.ServerReport.GetDefaultPageSettings();

    Is there any way to get the actual page settings for the report?

    Thanks!

    Wayne

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • May I ask why? I don't know how you would find that out but I know when developing reports you change the landscape by setting the page width and height...


    Cheers,

    Ben Sullins
    bensullins.com
    Beer is my primary key...

  • Ben Sullins (4/17/2008)


    May I ask why?

    Okay...

    I've developed a form in C# with the ReportViewer control.

    Depending on which method you call, it launches different reports.

    Some are portrait, some landscape.

    I want this data to set the form's width and the ReportViewer's width appropriately for the report being called. I'd like to retrieve this information at run-time.

    I can retrieve other information about the report (default page settings, parameter info) and data about the report server (version, rendering extensions).

    I just can't figure out how to get the information about whether it's portrait or landscape (the default page settings show 850x1100 for all reports, so this doesn't help).

    Wayne

    Beer is my primary key

    I hear ya! But I did read your web site first.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Ah okay..makes sense...if the settings all show 8.5in x 11in then I would be curios to see what happens when you print them. To the best of my knowledge the only way to modify the layout (Portrait vs. Landscape) is to adjust the page height/width accordingly.

    Good Luck, let me know what you come up with!


    Cheers,

    Ben Sullins
    bensullins.com
    Beer is my primary key...

  • It's the DEFAULT page settings that all show 8.5x11; I can't find available properties for the report page settings.

    The reports view / print as designed (portrait / landscape).

    My work-around is to set a property in each public method to which type of report it is; later on this is used to set the widths.

    However, I'd prefer to dynamically determine it's setting. (What if the report changes and the programmer forgets to set this form?)

    Wayne

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • I had the same problem and came up with a bit of a kludge workaround.

    :hehe:

    It looks like CustomPageSettings does contain a landscape property but it is not public. Anyway, so my workaround is to use the reporting services webservice reportingServiceProxy.GetReportDefinition to pull down the .rdl XML. Then, I parse the .rdl for the Page Width. It looks like by default this tag doesn't exist in 2005, but if you set width to 11 in, it will add it. If you set width to 14 in too, it will add it to the .rdl.

    DefaultPageSettings can be used to ascertain Legal vs. Letter. But I have to check for PageWidth in the .rdl of 11 in. to determine landscape vs. Portrait for Letter . . .

    byte[] reportDefinition = null;

    reportDefinition = reportingServiceProxy.GetReportDefinition(this._reportViewerControl1.ReportViewer.ServerReport.ReportPath);

    MemoryStream myStream = new MemoryStream(reportDefinition);

    System.Xml.XmlTextReader reportRDL = new System.Xml.XmlTextReader(myStream);

    while (reportRDL.Read())

    {

    switch (reportRDL.NodeType)

    {

    case XmlNodeType.Element:

    if (reportRDL.Name == "PageWidth")

    {

    //Move to Text Node for the PageWidth Element

    reportRDL.Read();

    if (reportRDL.Value == "11in")

    {

    isLandscape = true;

    }

    }

    break;

    }

    }

    reportRDL.Close();

    myStream.Close();

  • I had similar problems with Linked Reports. There is no property of "portrait" or "landscape". Everything is done by page size. See the following links to set and/or control page size:

    http://blogs.msdn.com/cliffgreen/archive/2008/11/12/controlling-page-size-in-a-reporting-services-report.aspx

    http://blogs.msdn.com/bwelcker/archive/2005/09/07/461758.aspx

    Also get RSScripter from SQLdbatips.com:

    http://www.sqldbatips.com/showarticle.asp?ID=62


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]

  • Yes, I set page height and width in device info settings too, just as you advise in your post, but I need to know what to set them to, based on what a developer specified in the .rdl at design time. My goal is not to hardcode height and width for any single report in device info, but to dynamically get it at run-time, thus checking default page settings, or pulling down the .rdl, and only then setting width and height in device info.

  • You can query the page size propeties via code and you don't have to parse the XML. See the following link which contains a VB.Net RS script:

    http://www.developmentnow.com/g/115_2005_10_0_0_616192/Probs-running-script-to-fix-linked-report-page-settings.htm

    Converted to C#

    ReportService2005.Property[] pageProps = new ReportService2005.Property[6];

    pageProps[0] = new ReportService2005.Property();

    pageProps[0].Name = "PageHeight";

    pageProps[1] = new ReportService2005.Property();

    pageProps[1].Name = "PageWidth";

    pageProps[2] = new ReportService2005.Property();

    pageProps[2].Name = "TopMargin";

    pageProps[3] = new ReportService2005.Property();

    pageProps[3].Name = "BottomMargin";

    pageProps[4] = new ReportService2005.Property();

    pageProps[4].Name = "LeftMargin";

    pageProps[5] = new ReportService2005.Property();

    pageProps[5].Name = "RightMargin";

    pageProps = _rs.GetProperties(string.Format("{0}{1}/{2}", _mainFolder, _masterFolder, MasterReport), pageProps);


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]

  • Looks great! Thanks . . . I'll have to try that.

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply