Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to take an existing SQL (SSRS) report and use VB.NET code to save the report to a PDF.

I have created a table of records and each record has a report type. No problem if I want to produce a single one and displayed. What I want to do is have a loop that goes through the table, selects record/type and produce a PDF and puts in a certain folder area.

No problem getting record from table and displaying it but I want to save as a pdf in a certain folder location for each of the records.

It is the PDF creation of the report that I have been having problems

Any help in the right direction would be great.

Below, displays fine but I want to create a PDF.

What I have tried:

Dim ParamData As New Dictionary(Of String, String)

ParamData.Add("IDNumber", 1234)

ShowForm("ReportName", ParamData, 1, "LocationOfReports")

  Public Sub ShowForm(ByVal strReportName As String, ByVal ParamData As Dictionary(Of String, String), ByVal intParamCount As Integer, Optional ByVal strReportPath As String = "ATest")

        Me.Show()

        Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote
        Me.ReportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = System.Net.CredentialCache.DefaultCredentials
        Me.ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://ReportServer_Test")
        Me.ReportViewer1.ServerReport.ReportPath = "/" & strReportPath & "/" & strReportName '"ATester"

        Me.ReportViewer1.Dock = DockStyle.Fill

        Me.Controls.Add(Me.ReportViewer1)

        If intParamCount > 0 Then
            Dim params(intParamCount - 1) As Microsoft.Reporting.WinForms.ReportParameter

            If ParamData.Keys.Count > 0 Then
                Dim intParamKey As Integer = 0
                For Each elemItem In ParamData
                    params(intParamKey) = New Microsoft.Reporting.WinForms.ReportParameter(elemItem.Key, elemItem.Value)
                    intParamKey = intParamKey + 1
                Next
            End If

            ReportViewer1.ServerReport.SetParameters(params)
        End If

        Me.ReportViewer1.RefreshReport()


    End Sub
Posted
Updated 12-Jan-18 6:55am
v2

1 solution

You will need to use a PDF library - PDFSharp[^] is free, though I haven't actually use it myself.

iTextSharp[^] is popular (which I have used and it is good) but is not free for commercial use.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900