Page Report Page Count

Originally Posted 1 August 2016, 12:15 am EST

  • Originally Posted 1 August 2016, 12:15 am EST

    Hi,

    Within a page report you can access the total number of pages using Globals!TotalPages

    We need to access the page count within code, for example:


    wpfViewer.LoadDocument(pageReport.Document)
    // How can we determine the total number of pages in the report?


    Please can you let us know how to access the total number of pages in the report via the pageReport or wpfViewer class?

    Thanks,
    Andrew
  • Reply

    Hello Andrew,

    Unfortunately, there is no direct way to get the Total page count of the PageReport when the report is loaded into the WPF Viewer. However, you can accomplish this requirement using the following work around.

    Save the report into a MemoryStream using RDFRenderingExtension and MemoryStreamProvider classes. Then load the stream into a SectionDocument and you can get the page count from the section document using 'Pages.Count' property. Here is the suggested code:
    PageReport rpt = new PageReport(new System.IO.FileInfo(@"..\..\PageReport1.rdlx"));
    rpt.Run();
    var doc = rpt.Document;

    GrapeCity.ActiveReports.Export.Rdf.RdfRenderingExtension rdfRE = new GrapeCity.ActiveReports.Export.Rdf.RdfRenderingExtension();

    GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider provider1 = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
    doc.Render(rdfRE, provider1);

    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    provider1.GetPrimaryStream().OpenStream().CopyTo(ms);
    ms.Position = 0;

    SectionDocument sec_doc = new SectionDocument();
    sec_doc.Load(ms);

    int PageCount = sec_doc.Pages.Count;


    Hope it helps.

    Regards,
    Arpit Jain
  • Reply

    I had utilized this code for version 13 a couple of years ago. We recently upgraded to version 15, and in version 14 the RdfRenderingExtesion is now obsolete. Is there a way we can still utilize this code without the RdfRenderingExtension?
  • Reply

    Hello,

    You can use the following line of code to get the PageCount from the WPF Viewer:
    public MainWindow()
    {
    InitializeComponent();
    viewer.LoadCompleted += Viewer_LoadCompleted;
    GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"c:\users\gpctadmin\downloads\untitled.rdlx"));
    viewer.LoadDocument(rpt.Document);
    }

    private void Viewer_LoadCompleted(object sender, EventArgs e)
    {
    TextBox txt= FindChild<TextBox>(viewer, "CurPageTextArea");
    int PageCount = int.Parse(txt.Text.Substring(txt.Text.IndexOf('/')+1));

    }

    public static T FindChild<T>(DependencyObject parent, string childName)
    where T : DependencyObject
    {
    // Confirm parent and childName are valid.
    if (parent == null) return null;
    T foundChild = null;
    int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
    for (int i = 0; i < childrenCount; i++)
    {
    var child = VisualTreeHelper.GetChild(parent, i);
    // If the child is not of the request child type child
    T childType = child as T;
    if (childType == null)
    {
    // recursively drill down the tree
    foundChild = FindChild<T>(child, childName);
    // If the child is found, break so we do not overwrite the found child.
    if (foundChild != null) break;
    }
    else if (!string.IsNullOrEmpty(childName))
    {
    var frameworkElement = child as FrameworkElement;
    // If the child's name is set for search
    if (frameworkElement != null && frameworkElement.Name == childName)
    {
    // if the child's name is of the request name
    foundChild = (T)child;
    break;
    }
    }
    else
    {
    // child element found.
    foundChild = (T)child;
    break;
    }
    }
    return foundChild;
    }


    Hope it helps.

    Thanks,
    Mohit
  • Reply

    I appreciate the suggestion but that doesn't really help me. I followed the code that Andrew suggested but we are not using it in coordination with any kind of viewer. Do you know of any other way to accomplish this other than loading the report/document into a viewer?
  • Reply

    Hello,

    You can use the RdfRenderingExtension to count the Page in the PageReport. There is no other way to achieve the same.
    We mark "RdfRenderingExtension" as obsolete as we don't fix any bug related to this.

    Thanks,
    Mohit
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels