Automatically returning a PDF document

Last post 05-10-2008 8:51 AM by shrainpatel. 6 replies.

Sort Posts:

  • Automatically returning a PDF document

    05-07-2008, 9:57 AM

    Is it possible for me to call my reports and have the automatically return a PDF.  I currently have to convert them to PDF by hand and I would prefer if they just came back as PDF.

    Many thanks,

    Trevor Keast.

  • Re: Automatically returning a PDF document

    05-07-2008, 10:06 AM
    • Loading...
    • Jeev
    • Joined on 11-24-2005, 7:49 AM
    • Posts 1,215

    Yes its possible. You can set the report export format to PDF and you will get a pdf report

    http://msdn.microsoft.com/en-us/library/ms157153.aspx 

    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
  • Re: Automatically returning a PDF document

    05-07-2008, 10:36 AM

    I understand that I can click the button to export the report to PDF format but is there any way to have the report returned in PDF forat to start with without the extra step of having the user export to PDF? I am trying to automate the process.

    Thanks,

    Trevor Keast.

     

  • Re: Automatically returning a PDF document

    05-07-2008, 11:12 AM
    • Loading...
    • Jeev
    • Joined on 11-24-2005, 7:49 AM
    • Posts 1,215

     

    I don't know how you are calling it but in the initial call if you set the parameter called "rs:Format" to PDF then you get PDF as the output

    eg

    !ReportServerUrl & "?/SomeFolder/SomeReport&ParamName=" &
    Parameters!ParamName.Value & "&rs:Format=PDF&

     

    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
  • Re: Automatically returning a PDF document

    05-07-2008, 1:41 PM
    • Loading...
    • cpowers
    • Joined on 08-03-2006, 12:40 AM
    • Posts 329

    I am tring to do the same thing but would also like the pdf saved to a specific drive and folder how can this be accomplished.

  • Re: Automatically returning a PDF document

    05-08-2008, 8:10 AM
    Answer
    • Loading...
    • Jeev
    • Joined on 11-24-2005, 7:49 AM
    • Posts 1,215

    Well in that case.. from what I understand.. you will have to make a webrequest / or use the webclient class and then download and save the report to a location. The user account under which your app runs should have privileges on that folder

    http://msdn.microsoft.com/en-us/library/ez801hhe.aspx 

    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
  • Re: Automatically returning a PDF document

    05-10-2008, 8:51 AM
    Answer
    • Loading...
    • shrainpatel
    • Joined on 05-08-2007, 8:57 AM
    • India
    • Posts 65

     The following code helps exporting the Report into PDF and Excel formats using the Render method of the ServerReport. Use below code after the report is loaded (refresh() is called on the reportviewer control).

     

    1    string mimeType;
    2    string encoding;
    3    string fileNameExtension;
    4    Warning[] warnings;
    5    string[] streamids;
    6    byte[] exportBytes = reportViewer.ServerReport.Render("PDF", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);
    7    HttpContext.Current.Response.Buffer = true;
    8    HttpContext.Current.Response.Clear();
    9    HttpContext.Current.Response.ContentType = mimeType;
    10   HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=ExportedReport." + fileNameExtension);
    11   HttpContext.Current.Response.BinaryWrite(exportBytes);
    12   HttpContext.Current.Response.Flush();
    13   HttpContext.Current.Response.End();
    

     

    Sometimes you might need to send the Report content into email. To Achieve this you can use the above code where you need to pass "HTML4.0" as the first parameter to the Render method. After you get the byte array from the Render method you can convert it to string as below

     

    1    string mimeType;
    2    string encoding;
    3    Warning[] warnings;
    4    string[] streamids;
    5    string fileNameExtension;
    6    byte[] htmlBytes = MyReportViewer.ServerReport.Render("HTML4.0", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);
    7    string reportHtml = System.Text.Encoding.UTF8.GetString(htmlBytes);
    8    return reportHtml;
    

    You can find more on this at http://pareshjagatia.blogspot.com/2008/05/export-reportviewer-report-to-pdf-excel.html

    Regards, 

Page 1 of 1 (7 items)