Programmatically save telerik report as .pdf file

9 posts, 0 answers
  1. Chamara
    Chamara avatar
    37 posts
    Member since:
    Jun 2011

    Posted 07 Jan 2014 Link to this post

    I'm using telerik HTML5 report viewer with ASP.NET MVC 4 to generate telerik reports. Below are main sections of the view

    @model Doc.Web.Models.Vendor.VendorCoverSheetFormModel

    @using (Html.BeginForm())
    {  
        <input type="submit" value="Save" id="btnSave" />
      
        var typeReportSource = new TypeReportSource() { TypeName = "Doc.Web.Reports.SquadCheck.SquadCheck, Doc.Web" };
        typeReportSource.Parameters.Add("project", "TEST");
       
        @(Html.TelerikReporting().ReportViewer()
            .Id("reportViewer1")
            .ServiceUrl("/api/reports/")
            .TemplateUrl("/Content/ReportViewer/templates/telerikReportViewerTemplate.html")
            .ReportSource(typeReportSource)
            .ViewMode(ViewModes.INTERACTIVE)
            .ScaleMode(ScaleModes.FIT_PAGE_WIDTH)
            .Scale(1.0)
            .PersistSession(false)

    )

    report is displaying fine and I want to save this report as a .pdf file to hard drive location, in HTTP post Action

            [HttpPost]
            public ActionResult Report(VendorCoverSheetFormModel model)
            {
              // here I need to include the code for .pdf saving
                return View();
            }

    I have referred to following articles but I guess they are for asp.net web pages. How to modify this code to suit HTML5 report viewer?

    http://www.telerik.com/support/kb/reporting/designing-reports/saving-a-report-into-pdf-format-programmatically.aspx

    http://www.telerik.com/help/reporting/programmatic-exporting-report.html

  2. Squall
    Squall avatar
    174 posts
    Member since:
    Feb 2011

    Posted 10 Jan 2014 Link to this post

    Hi, Where you want to save the PDF on the report server or on the client machine?
    SN
  3. DevCraft banner
  4. Chamara
    Chamara avatar
    37 posts
    Member since:
    Jun 2011

    Posted 10 Jan 2014 Link to this post

    hi!
    I want to save the pdf On server
  5. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 14 Jan 2014 Link to this post

    Hi Chamara,

    The approach described in the Exporting Report Programmatically help article can be used to print on the server an instance of your report.
    Other approach is to use the REST API and make the needed requests to register client, create instance, request document and retrieve it.  For more details take a look at the Request Document help article.

    I hope this helps you.

    Regards,
    Stef
    Telerik

    New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

  6. Sara Muth
    Sara Muth avatar
    4 posts
    Member since:
    Oct 2009

    Posted 15 Jan in reply to Chamara Link to this post

    Hi Chamara,

    I was wondering if you ever figured this out.  I am trying to do the same thing.

  7. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 19 Jan Link to this post

    Hi,

    Please test exporting programmatically the report via ReportProcessor - Exporting Report Programmatically.


    I hope this helps.

    Regards,
    Stef
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Sara Muth
    Sara Muth avatar
    4 posts
    Member since:
    Oct 2009

    Posted 21 Jan in reply to Stef Link to this post

    I've been trying that, to no avail.

    Right now I'm getting a file not found error even though the full file path it details in the error is correct.

    Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
    System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
    Telerik.Reporting.UriReportSource uriReportSource = new Telerik.Reporting.UriReportSource();
    uriReportSource.Uri = "Reports\\NominationPaper.trdx";
    Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", uriReportSource, deviceInfo);

  9. Sara Muth
    Sara Muth avatar
    4 posts
    Member since:
    Oct 2009

    Posted 21 Jan in reply to Sara Muth Link to this post

    So I've passed that hurdle and can save my TRDX as a PDF to the server, but how do I pass parameter values programmatically to it before saving it?  Do I use uriReportSource.Parameters as described here? http://docs.telerik.com/reporting/t-telerik-reporting-urireportsource
  10. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 22 Jan Link to this post

    Hi,

    The UriReportSource.Uri property is a string (the path to TRDX file on the server). In case of a web application, you can use the Server.MapPath to map the relative path.

    About passing parameters, the ReportSource.Parameters collection is mapped by key (case sensitive) to the report's ReportParameters collection. For more details, please check Report Sources.

    Regards,
    Stef
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner