none
Export to PDF programaticaly RRS feed

  • Question

  • I have a heavy report with graphs

    When rendering to PDF it runs out of memory

    any way to make it render directly to a file?

    Saturday, December 2, 2006 9:10 PM

Answers

  • You can render directly to a file if you use a different overload of Render:

    public void Render(string format, string deviceInfo, CreateStreamCallback createStream, out Warning[] warnings)

    This version allows you to pass a stream back fro the CreateStreamCallback delegate.  You can pass a file stream if you want.

    Saturday, March 3, 2007 3:48 AM
    Moderator

All replies

  • Have you tried this:
                FileStream fs = null;
                try
                {
                    Warning[] warnings;
                    string[] streamids;
                    string mimeType;
                    string encoding;
                    string filenameExtension = "pdf";

                    byte[] bytes = localReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

                    fs = new FileStream(fileName, FileMode.Create);
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Close();
                }
                catch (Exception ex)
                {
                    ErrorBox.Show("Error exporting to PDF.", ex);
                }
                finally
                {
                    if (fs != null)
                        fs.Close();
                }

    Tomaz
    Wednesday, December 6, 2006 9:01 AM
  • Thanks! But it dies on:

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

    with out of memory!

    there was an example to use a stream but I could not understand it.

    Thursday, December 7, 2006 6:30 PM
  • Hi,

    I'm using virtual earth in my application and  need to export map in pdf or some other foramt.

    If anyone knows how to do it, please share your thoughts with me.

     

    Regards,

    Milind

    Tuesday, January 2, 2007 11:25 AM
  • Try exporting as jpeg image.

    byte[] bytes = localReport.Render("Image", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

    fs = new FileStream("c:\tmpimg.jpg", FileMode.Create);

    Regards,

    Asif

    Friday, January 5, 2007 5:57 PM
  • Asif,

    Have you sucessfully gotten that code to work?  I noticed that by default the reportViewer exports "image" as tiff and have not found a way to have it export to jpg.
    Friday, January 26, 2007 4:31 PM
  • Hi Bryan,

    Yes, you are right it actully generates TIFF file. I guess for most of the sitiuations TIFF will just work fine. However, if someone need jpeg excuslively then we can always convert the TIFF to Jpeg using .NET System.Drawing.Imaging namespace.

    Regards,

    Asif

    Thursday, February 1, 2007 3:47 PM
  • You can get a jpg output directly by specifying the deviceinfo: <DeviceInfo><OutputFormat>jpeg</OutputFormat></DeviceInfo>
    Thursday, February 15, 2007 9:37 PM
    Moderator
  • You can render directly to a file if you use a different overload of Render:

    public void Render(string format, string deviceInfo, CreateStreamCallback createStream, out Warning[] warnings)

    This version allows you to pass a stream back fro the CreateStreamCallback delegate.  You can pass a file stream if you want.

    Saturday, March 3, 2007 3:48 AM
    Moderator
  • What is the Assembly Reference or Directiive for using the FileStream and ErrorBox?
    Saturday, March 3, 2007 3:41 PM