以编程方式将RDLC报告保存为PDF [英] Save RDLC reports as PDF programmatically
问题描述
我用于呈现的代码作为PDF的单个报告是:
Dim警告作为Microsoft.Reporting.WebForms.Warning()= Nothing
Dim streamids As String()= Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing
Dim deviceInfo As String
Dim bytes As Byte()
Dim lr As New Microsoft.Reporting.WebForms.LocalReport
deviceInfo =< DeviceInfo>< SimplePageHeaders> True< / SimplePageHeaders>< / DeviceInfo>
bytes = ReportViewer1.LocalReport.Render(PDF,deviceInfo,mimeType,encoding,extension,streamids,warnings)
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType =application / pdf
Response.BinaryWrite(bytes)
Response.Flush ()
Response.Close()
我在想我可以跑它在一个循环中,每次保存PDF。
你在这里有什么问题?这是不行吗?
这里是2005年我们所做的事情的一个例子。我们定义了一个名为rptViewer1的控件,根据您的需要,该控件可以看到或不可见。 strFormat应该包含PDF和strNomFicher的完整路径。
BTW变量名称和函数是法语,但这将工作:)
pre
公共Sub CreerFichierRapport(ByVal strNomFichier As String,ByVal strFormat As String)
Dim bytes()As Byte
Dim strDeviceInfo As String =
Dim strMimeType As String =
Dim strEncoding As String =
Dim strExtension As String =
Dim strStreams()As String
Dim warnings()As Warning
Dim oFileStream As FileStream
_stream =新列表(Of Stream)
尝试
bytes = rptViewer1.LocalReport.Render(strFormat,strDeviceInfo,strMimeType ,strEncoding,strExtension,strStreams,warnings)
oFileStream =新的FileStream(strNomFichier,FileMode.Create)
oFileStream.Write(bytes,0,bytes.Length)
_stream。加入(OFI leStream)
最后
如果不是IsNothing(oFileStream)然后
oFileStream.Close()
oFileStream.Dispose()
如果
结束尝试
End Sub
I have a report that I need to run multiple times and save as PDFs. I am currently generating the report as a PDF programatically but want to save the reports without the user having to choose the save option manually each time.
The code I use to render a single report as a PDF is:
Dim warnings As Microsoft.Reporting.WebForms.Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing
Dim deviceInfo As String
Dim bytes As Byte()
Dim lr As New Microsoft.Reporting.WebForms.LocalReport
deviceInfo = "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>"
bytes = ReportViewer1.LocalReport.Render("PDF", deviceInfo, mimeType, encoding, extension, streamids, warnings)
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.BinaryWrite(bytes)
Response.Flush()
Response.Close()
I was figuring I could run it in a loop and save the PDF each time.
What's your question in here? Is it that it does not work?
here is an example of something we didin 2005. We defined a control called rptViewer1 which can be visible or not depending of your needs. strFormat should contain "PDF" and strNomFicher the full path.
BTW the variable names and functions are in french, but that will work anyway :)
Public Sub CreerFichierRapport(ByVal strNomFichier As String, ByVal strFormat As String) Dim bytes() As Byte Dim strDeviceInfo As String = "" Dim strMimeType As String = "" Dim strEncoding As String = "" Dim strExtension As String = "" Dim strStreams() As String Dim warnings() As Warning Dim oFileStream As FileStream _stream = New List(Of Stream) Try bytes = rptViewer1.LocalReport.Render(strFormat, strDeviceInfo, strMimeType, strEncoding, strExtension, strStreams, warnings) oFileStream = New FileStream(strNomFichier, FileMode.Create) oFileStream.Write(bytes, 0, bytes.Length) _stream.Add(oFileStream) Finally If Not IsNothing(oFileStream) Then oFileStream.Close() oFileStream.Dispose() End If End Try End Sub
这篇关于以编程方式将RDLC报告保存为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!