Dear Sir,
Thanks for your answer your answer in language C# .
Sorry for my late reply.
I try to convert your answer to VB.NET language But there is an error `Error BC30491 Expression does not produce a value.`
I have marked the code below.
Please Guide me
Imports Microsoft.Reporting.WebForms ' Make sure to add reference to Microsoft.ReportViewer.WebForms or Microsoft.Reporting.WinForms
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.IO
Imports System.Collections.Generic ' Required for Warning[]
Public Shared Function RenderReportToPDF(ByVal report As LocalReport, ByVal deviceInfo As String) As Byte()
Dim mimeType As String = Nothing, encoding As String = Nothing, extension As String = Nothing
Dim warnings() As Warning = Nothing
Dim streams() As String = Nothing
Dim renderedBytes() As Byte = report.Render("PDF", deviceInfo, mimeType, encoding, extension, streams, warnings)
Return renderedBytes
End Function
Public Shared Sub ExportRdlcToPdf(ByVal report As LocalReport, ByVal filePath As String, Optional ByVal deviceInfo As String = "<DeviceInfo><OutputFormat>PDF</OutputFormat></DeviceInfo>")
Try
Dim pdfBytes() As Byte = RenderReportToPDF(report, deviceInfo)
' Create a new PDF document from the rendered bytes
Using fileStream As New FileStream(filePath, FileMode.Create)
Using document As New Document()
Dim writer As PdfWriter = PdfWriter.GetInstance(document, fileStream)
document.Open()
Using ms As New MemoryStream(pdfBytes)
Dim reader As New PdfReader(ms)
For page As Integer = 1 To reader.NumberOfPages
document.NewPage()
Dim importedPage As PdfImportedPage = writer.GetImportedPage(reader, page)
'Error BC30491 Expression does not produce a value.
document.Add((New PdfContentByte(writer)).AddTemplate(importedPage, 0, 0))
Next page
End Using
End Using
End Using
Catch ex As System.Exception
' Handle exceptions appropriately, e.g., logging
Console.WriteLine($"Error exporting to PDF: {ex.Message}")
Throw ' Re-throw or handle as needed
End Try
End Sub