This is a migrated thread and some comments may be shown as answers.
Programmatically save telerik report as .pdf file
8 Answers 965 Views
This is a migrated thread and some comments may be shown as answers.
Chamara
Top achievements
Rank 1
Chamara asked on 08 Jan 2014, 05:59 AM
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

8 Answers, 1 is accepted

Sort by
0
Squall
Top achievements
Rank 1
answered on 10 Jan 2014, 01:45 PM
Hi, Where you want to save the PDF on the report server or on the client machine?
SN
0
Chamara
Top achievements
Rank 1
answered on 10 Jan 2014, 03:06 PM
hi!
I want to save the pdf On server
0
Stef
Telerik team
answered on 14 Jan 2014, 05:44 PM
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.

0
Sara Muth
Top achievements
Rank 1
answered on 15 Jan 2016, 07:28 PM

Hi Chamara,

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

0
Stef
Telerik team
answered on 19 Jan 2016, 09:08 AM
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
0
Sara Muth
Top achievements
Rank 1
answered on 21 Jan 2016, 08:12 PM

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);

0
Sara Muth
Top achievements
Rank 1
answered on 21 Jan 2016, 11:39 PM
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
0
Stef
Telerik team
answered on 22 Jan 2016, 03:32 PM
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
Asked by
Chamara
Top achievements
Rank 1
Answers by
Squall
Top achievements
Rank 1
Chamara
Top achievements
Rank 1
Stef
Telerik team
Sara Muth
Top achievements
Rank 1
Share this question
or