How to export Telerik ReportViewer to PDF without going to the preview. VB.net webforms

540 views Asked by At

This is the report that I want to export to pdf

Hi! How can I export this report to PDF without having to go to the report viewer window?

Here is my code. This basically brings me to the report viewer. What I want to do is when I click the export button, it directly downloads the report without going to the report viewer.

    Sub DoRep()
    Dim truck As String = lblFLPlate.Text
    If String.IsNullOrEmpty(truck) Then truck = "-"
    Dim db As New wsbl.smwsEntities
    Dim rb As New Telerik.Reporting.ReportBook
    Dim lstFL = (From p In db.FinalLoadings Where If(p.IsPrinted, False) = False And p.TruckNo = truck And p.FLType = "BST" Order By p.CreatedDate Descending Select p).ToList
    For Each fl In lstFL
        rb.Reports.Add(getReport(fl.FinalLoadingNumber))
    Next

    Dim instanceReportSource As New Telerik.Reporting.InstanceReportSource()
    instanceReportSource.ReportDocument = rb

    ReportViewer1.ReportSource = instanceReportSource

    ShowReport()

    For Each fl In lstFL
        fl.IsPrinted = True
    Next
    db.SaveChanges()
End Sub
1

There are 1 answers

0
Kenneth Diligencia On BEST ANSWER
    Sub DoRep()
    Dim truck As String = lblFLPlate.Text
    If String.IsNullOrEmpty(truck) Then truck = "-"
    Dim db As New wsbl.smwsEntities
    Dim rb As New Telerik.Reporting.ReportBook
    Dim lstFL = (From p In db.FinalLoadings Where If(p.IsPrinted, False) = False And p.TruckNo = truck And p.FLType = "BST" Order By p.CreatedDate Descending Select p).ToList
    For Each fl In lstFL
        rb.Reports.Add(getReport(fl.FinalLoadingNumber))
    Next

    Dim instanceReportSource As New Telerik.Reporting.InstanceReportSource()
    instanceReportSource.ReportDocument = rb

    ReportViewer1.ReportSource = instanceReportSource


    Dim reportProcessor As New Telerik.Reporting.Processing.ReportProcessor()
    Dim result As Telerik.Reporting.Processing.RenderingResult = reportProcessor.RenderReport("PDF", instanceReportSource, Nothing)

    Dim fileName As String = result.DocumentName + "." + result.Extension
    'Response.Clear()
    Response.ContentType = result.MimeType
    Response.Cache.SetCacheability(HttpCacheability.Private)
    Response.Expires = -1
    'Response.Buffer = True
    Response.AddHeader("Content-Disposition", String.Format("{0};FileName=""{1}""", "attachment", fileName))
    Response.BinaryWrite(result.DocumentBytes)
    'Response.End()

    For Each fl In lstFL
        fl.IsPrinted = True
    Next
    db.SaveChanges()
    ShowMain()
End Sub