ASP.NET - change the size of paper in rdlc report

Asked By Bhaumik Vasavada on 20-Jan-09 08:01 AM

i want to change the size of paper of rdlc report programatically.. in c# .net..

show me the way...

thank you in anticipation

Reply - alice johnson replied to Bhaumik Vasavada on 20-Jan-09 11:09 AM

It is not possible to change the size of the Page after the Reportviewer has loaded the Report.
You only can change the size by editing the size in the RDLC-File before the Report is loaded.

But there is round about for thta, here is a sample:public class CPrintManager : IDisposable   
  {   
    private int m_currentPageIndex;   
    private IList<Stream> m_streams;   
    private DataTable LoadSalesData()   
    {  
      DataSet dataSet = new DataSet();   
      dataSet.ReadXml("data.xml");   
      return dataSet.Tables[0];   
    }  
    private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)   
    {   
      Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);   
      m_streams.Add(stream);   
      return stream;   
    }  
    private void Export(LocalReport report, double dPageWidth, double dPageHeigth)   
    {   
      dPageWidth = Math.Round(dPageWidth, 2);  
      dPageHeigth = Math.Round(dPageHeigth, 2);  
      string deviceInfo = "<DeviceInfo>" +   
        "  <OutputFormat>EMF</OutputFormat>" +   
        "  <PageWidth>{0}in</PageWidth>" +   
        "  <PageHeight>{1}in</PageHeight>" +   
        "  <MarginTop>0.25in</MarginTop>" +   
        "  <MarginLeft>0.25in</MarginLeft>" +   
        "  <MarginRight>0.25in</MarginRight>" +   
        "  <MarginBottom>0.25in</MarginBottom>" +   
        "</DeviceInfo>";  
      deviceInfo = String.Format(deviceInfo, CDataMange.GetDoubleSQLPretty(dPageWidth), CDataMange.GetDoubleSQLPretty(dPageHeigth));  
      Warning[] warnings;  
      m_streams = new List<Stream>();   
      report.Render("Image", deviceInfo, CreateStream, out warnings);   
      foreach (Stream stream in m_streams)    
        stream.Position = 0;  
    }  
 
    public void Print(LocalReport report)   
    {   
      PrintDialog dlg = new PrintDialog();  
      DialogResult res = dlg.ShowDialog();  
      if (res == DialogResult.Cancel)  
        return;  
        
      //get the default printer settings.   
      this.Export(report, dlg.PrinterSettings.DefaultPageSettings.PaperSize.Width/100.0,   
        dlg.PrinterSettings.DefaultPageSettings.PaperSize.Height/100.0);  
      this.m_currentPageIndex = 0;  
      if (m_streams == null || m_streams.Count == 0)           
        return;  
 
      PrintDocument printDoc = new PrintDocument();  
      printDoc.PrinterSettings = dlg.PrinterSettings;  
      if (!printDoc.PrinterSettings.IsValid)  
      {  
        CErrorHandling.WriteError("The printer settings are not valid! ", "CPinting.Print");  
        MessageBox.Show("Error! ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);   
        return;  
      }  
      printDoc.PrintPage += new PrintPageEventHandler(PrintPage);  
      printDoc.Print();  
    }   
      
    private void PrintPage(object sender, PrintPageEventArgs ev)   
    {  
      Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);   
      ev.Graphics.DrawImage(pageImage, 0, 0);  
      m_currentPageIndex++;   
      ev.HasMorePages = (m_currentPageIndex < m_streams.Count);  
    }  
 
    public void Dispose()   
    {   
      if (m_streams != null)   
      {   
        foreach (Stream stream in m_streams)     
          stream.Close();   
      }   
    }  
  } 
private void reportViewer1_Print(object sender, CancelEventArgs e)  
    {  
      e.Cancel = true;  
      CPrintManager obj = new CPrintManager();  
      obj.Print(this.reportViewer1.LocalReport);  
    } 
And that's it :)




Danilo Taju replied to alice johnson on 18-Jun-15 04:51 AM
where did you got the CDataMange