none
Printing a ServerReport without viewer RRS feed

  • Question

  • So i got this code from another thread in this fourm and need little help with it, the problem is that when i call m_print() to print the report it only exports first page of the report. Any ideas on how to resolve this problem or atleast a point to what i'm doing wrong would be most appreciated.

     

    The Code:

     

     

    ServerReport m_serverReport;

    private Stream CreateStream(string name, string fileNameExtension, Encoding encoding,string mimeType, bool willSeek)

    {

    //Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);

    Stream stream = new MemoryStream();

    m_streams.Add(stream);

    return stream;

    }

    private void Export(ServerReport report)

    {

    ReportPageSettings rps = m_serverReport.GetDefaultPageSettings();

    string deviceInfo = "<DeviceInfo>" +

    "<SimplePageHeaders>False</SimplePageHeaders>" +

    " <OutputFormat>EMF</OutputFormat>" +

    " <PageWidth>" + ((int)(rps.PaperSize.Width * 0.254)).ToString() + "mm</PageWidth>" +

    " <PageHeight>" + ((int)(rps.PaperSize.Height * 0.254)).ToString() + "mm</PageHeight>" +

    " <MarginTop>" + ((int)(rps.Margins.Top * 0.254)).ToString() + "mm</MarginTop>" +

    " <MarginLeft>" + ((int)(rps.Margins.Left * 0.254)).ToString() + "mm</MarginLeft>" +

    " <MarginRight>" + ((int)(rps.Margins.Right * 0.254)).ToString() + "mm</MarginRight>" +

    " <MarginBottom>" + ((int)(rps.Margins.Bottom * 0.254)).ToString() + "mm</MarginBottom>" +

    "</DeviceInfo>";

    //Warning[] warnings;

    m_streams = new List<Stream>();

    String temp = "";

    String temp2 = "";

    NameValueCollection nvc = new NameValueCollection();

    //report.Render("Image", deviceInfo, CreateStream, out warnings);

    //report.Render("Image", deviceInfo, nvc, out temp, out temp2);

    report.Render("Image", deviceInfo, nvc, CreateStream("test4", "", Encoding.ASCII, "", true), out temp, out temp2);

    foreach (Stream stream in m_streams)

    stream.Position = 0;

    }

    private void m_PrintPage(object sender, PrintPageEventArgs ev)

    {

    Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);

    //ev.Graphics.DrawImage(pageImage, 0, 0);

    ev.Graphics.DrawImage(pageImage, ev.PageBounds);

    m_currentPageIndex++;

    ev.HasMorePages = (m_currentPageIndex < m_streams.Count);

    }

    private void m_print(int broj_kopija,string printer)

    {

    Export(m_serverReport);

    string printerName = printer;

    if (m_streams == null || m_streams.Count == 0)

    return;

    PrintDocument printDoc = new PrintDocument();

    printDoc.PrinterSettings.PrinterName = printerName;

    printDoc.PrinterSettings.Copies = (short)broj_kopija;

    if (!printDoc.PrinterSettings.IsValid)

    throw new ObavijesnaIznimka("Postavke printera nisu dobre");

    printDoc.PrintPage += new PrintPageEventHandler(m_PrintPage);

    printDoc.PrintController = new System.Drawing.Printing.StandardPrintController();

    // printDoc.PrintController.OnStartPage+= new PrintEventHandler(m_OnStartPrint);

    printDoc.Print();

    }

    Friday, July 27, 2007 9:59 AM