none
How to set PageSettings for report in vs 2008 ? RRS feed

  • Question

  • Hello every body.

    I need to set PageSetting for microsoft ReportViewer (vs 2008). I try to use code below :

    (refer: http://social.msdn.microsoft.com/forums/en-US/vsreportcontrols/thread/a0b7e970-00fc-4035-9206-e4fb45b2cf1c)

    class ReportViewer: Microsoft.Reporting.WinForms.ReportViewer
    
     {
    
      internal void SetPageSettings(System.Drawing.Printing.PageSettings setting)
    
      {
    
       try
    
       {
    
        Type tip = this.GetType();
    
        System.Reflection.FieldInfo[] fields = tip.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    
        foreach (System.Reflection.FieldInfo item in fields)
    
        {
    
         if (item.Name == "m_pageSettings")
    
         {
    
          item.SetValue(this, setting);
    
         }
    
        }
    
       }
    
       catch (Exception) { }
    
      }
    
     }

    But it doesn't work. The fields has only one element, it is "scrollPosition". Why that? Please help me to fix it.

    Monday, July 5, 2010 8:25 AM

All replies

  • Use this code for page setting......

     

    string mimeType;

     

    string encoding;

     

    string extension;

     

    string deviceInfo =

     

    "<DeviceInfo>" +

     

    " <OutputFormat>PDF</OutputFormat>" +

     

    " <PageWidth>12.0in</PageWidth>" +

     

    " <PageHeight>8.5in</PageHeight>" +

     

    " <MarginTop>0.05in</MarginTop>" +

     

    " <MarginLeft>0.05in</MarginLeft>" +

     

    " <MarginRight>0.05in</MarginRight>" +

     

    " <MarginBottom>0.05in</MarginBottom>" +

     

    "</DeviceInfo>";

     

    string[] streamids;

    Microsoft.Reporting.WinForms.

    Warning[] warnings;

     

    //Gives byte[] of Generated pdf file.

     

    byte[] bytes = reportViewer1.LocalReport.Render("PDF", deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);

     

    FileStream fs = new FileStream(@"C:\Users\Hirenb\Desktop\new.pdf", FileMode.Create, FileAccess.Write);

    fs.Write(bytes, 0, bytes.Length);

    fs.Close();

    System.Diagnostics.

    Process.Start(@"C:\Users\Hirenb\Desktop\new.pdf");

     

    return bytes;

    Friday, July 30, 2010 1:39 PM