Showing posts with label reportviewer. Show all posts
Showing posts with label reportviewer. Show all posts

Sunday, March 25, 2012

Automatically generating PDF with ReportViewer

Hi, I've been using the Report viewer control for a bit, and was wondering how I can automatically run the report as a PDF. I can run it and prompt the user to open or save the PDF, but I'm not sure how to auto generate it. This is the code which prompts the user:

ProtectedSub Page_SaveStateComplete(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.SaveStateComplete

Dim pdfContentAsByte() =Me.ReportViewer1.LocalReport.Render("pdf",Nothing,Nothing,Nothing,Nothing,Nothing,Nothing)

Me.Response.Clear()

Me.Response.ContentType ="application/pdf"

Dim modCodeAsString = Request.QueryString("modCode")

Me.Response.AddHeader("Content-disposition","attachment; filename=ModuleCode-" & modCode &".pdf")

Me.Response.BinaryWrite(pdfContent)

Me.Response.End()

EndSub

Has anybody done this?

Thanks

Hi,

Do you want to save the PDF file which generates by the reporting service automatically, right?

Based on my understanding, I think when you have generate the byte[] content for your PDF file, what you should do is to use FileStream class and FileInfo class to create the corresponding file, and write the content into files, save it onto your hard disk.

If you want the method be called automatically, you can invoke the method when page loads.
For more reference on FileStream and FileInfo, see:

http://msdn2.microsoft.com/en-us/library/system.io.fileinfo.aspx
http://msdn2.microsoft.com/en-us/library/system.io.filestream.aspx

Thanks.

|||

Thanks for that, I'll have a look. Also, when I ask the user to save as .xls or .pdf for example, how can I specify that the file will be saved on the D drive, rather than the C drive as the C drive is full?

Thanks

|||

Hi,

When you are creating and storing the file, you can specify the actual disk drive where to store the file. Also, you can import the "System.Runtime.InteropServices" namespace to check the free disk volume, so that you can determine which disk drive to store the file.

Thanks.

Monday, March 19, 2012

Automatic printing from ReportViewer control

Hi,
I've got a WinForm app written in .NET 2.0 (C#). We have a series of SQL
Reporting Services reports which are on a remote server - not RDLCs. I've
got a ReportViewer control on one of the forms, and am able to render the
reports in the ReportViewer just fine. However, I would like to be able to
print these reports, preferably without displaying any UI at all, through
this app. Does anybody have any suggestions? I realize that RDLCs would
work in this case, but that's not an option, unfortunately.
Thanks, JimOn Jan 4, 6:34 pm, "LiveCycle" <livecy...@.sandbox.etech.adobe.com>
wrote:
> Hi,
> I've got a WinForm app written in .NET 2.0 (C#). We have a series of SQL
> Reporting Services reports which are on a remote server - not RDLCs. I've
> got a ReportViewer control on one of the forms, and am able to render the
> reports in the ReportViewer just fine. However, I would like to be able to
> print these reports, preferably without displaying any UI at all, through
> this app. Does anybody have any suggestions? I realize that RDLCs would
> work in this case, but that's not an option, unfortunately.
> Thanks, Jim
This link should be helpful.
http://forums.asp.net/p/516455/533549.aspx
Regards,
Enrique Martinez
Sr. Software Consultant

Monday, February 13, 2012

Auto Print

I am using Visual studio 2005. This may be a vb question but it deals with reporting services.

I have a local report using the reportviewer control. (rdcl 2005 fmt)

It displays perfectly, and when i click the print button it prints flawlessly.

How do i print the document to the default printer automatically?

This seems like a basic function that i can't seem to find the answer to.

Thanx

Jerry Cicierega

I found the answer. Its not as bad as it looks. Thois is a form called "slip.vb" I am printing to a slip printer. The form has a rpt viewer on it. The form nevers shows. It is just used as a containor for the report. I created the report as an RDL report. I coppied it into the program folder and re-named it to a RDCL extension. I then established the datasource. and it worked interactivly. I then added the following code and presto. Auto Print. I also asume the default printer is the printer of choice.

Imports System.IO

Imports System.Data

Imports System.Text

Imports System.Drawing.Imaging

Imports System.Drawing.Printing

Imports System.Collections.Generic

Imports Microsoft.Reporting.WinForms

Public Class Slip

Private m_currentPageIndex As Integer

Private m_streams As IList(Of Stream)

Public Sub Print_Slip()

Me.TxnHistoryTableAdapter.Connection.ConnectionString = My.Utilities.ConnectionString

Me.TxnHistoryTableAdapter.FillBy(Me.PCZonDataSet.TxnHistory, My.GlobalVariables.ComputerData.ComputerName, My.GlobalVariables.ComputerData.Sequencenumber)

Export(Me.ReportViewer1.LocalReport)

m_currentPageIndex = 0

Print()

End Sub

Private Function CreateStream(ByVal name As String, _

ByVal fileNameExtension As String, _

ByVal encoding As Encoding, ByVal mimeType As String, _

ByVal willSeek As Boolean) As Stream

Dim stream As Stream = New FileStream(name + "." + fileNameExtension, FileMode.Create)

m_streams.Add(stream)

Return stream

End Function

Private Sub Export(ByVal report As LocalReport)

Dim deviceInfo As String = _

"<DeviceInfo>" + _

" <OutputFormat>EMF</OutputFormat>" + _

" <PageWidth>9in</PageWidth>" + _

" <PageHeight>11in</PageHeight>" + _

" <MarginTop>0.0in</MarginTop>" + _

" <MarginLeft>0.0in</MarginLeft>" + _

" <MarginRight>0.25in</MarginRight>" + _

" <MarginBottom>0.25in</MarginBottom>" + _

"</DeviceInfo>"

Dim warnings() As Warning = Nothing

m_streams = New List(Of Stream)()

report.Render("Image", deviceInfo, _

AddressOf CreateStream, warnings)

Dim stream As Stream

For Each stream In m_streams

stream.Position = 0

Next

End Sub

Private Sub Print()

If m_streams Is Nothing Or m_streams.Count = 0 Then

Return

End If

Dim printDoc As New PrintDocument()

AddHandler printDoc.PrintPage, AddressOf PrintPage

printDoc.Print()

If Not (m_streams Is Nothing) Then

Dim stream As Stream

For Each stream In m_streams

stream.Close()

Next

m_streams = Nothing

End If

End Sub

Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)

Dim pageImage As New Metafile(m_streams(m_currentPageIndex))

ev.Graphics.DrawImage(pageImage, ev.PageBounds)

m_currentPageIndex += 1

ev.HasMorePages = (m_currentPageIndex < m_streams.Count)

End Sub

End Class