dpatfield66
Well-known member
- Joined
- Apr 6, 2006
- Messages
- 136
- Programming Experience
- 5-10
I have the following code below and printing is working fine:
However, the program keeps dropping an EMF file (.emf) in my C drive, for every page of the report!
I see in the code <OutputFormat>EMF</OutputFormat>, but if I remove this, the program does not work. If I remove the entire section on deviceinfo, the program will not work. If I don't do the Export() funtion at all and just attempt to print, the program will not work.
How do I print these reports without adding files to my C drive?
CODE BELOW:
' ****PRINT FUNCTIONALITY****
'CREATE STREAM ROUTINE
Public 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
'----------------------------------------------------
'PRINT PAGE ROUTINE
Public 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
'------------------------------------------------
'PRINT ROUTINE
Public Sub Print()
Dim report As LocalReport = New LocalReport()
report.ReportEmbeddedResource = strEResource
report.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource(strReportName, objReportSource))
Export(report)
m_currentPageIndex = 0
If m_streams Is Nothing Or m_streams.Count = 0 Then
Return
End If
Dim printDoc As New PrintDocument()
AddHandler printDoc.PrintPage, AddressOf PrintPage
If strPageType = "Portrait" Then
printDoc.DefaultPageSettings.Landscape = False
Else
printDoc.DefaultPageSettings.Landscape = True
End If
printDoc.Print()
End Sub
'--------------------------------------
'EXPORT ROUTINE
Public Sub Export(ByVal report As LocalReport)
Dim deviceInfo As String
If strPageType = "Portrait" Then
deviceInfo = _
"<DeviceInfo>" + _
" <OutputFormat>EMF</OutputFormat>" + _
" <PageWidth>8.5in</PageWidth>" + _
" <PageHeight>11in</PageHeight>" + _
" <MarginTop>0in</MarginTop>" + _
" <MarginBottom>0.25in</MarginBottom>" + _
" <MarginRight>0.5in</MarginRight>" + _
" <MarginLeft>0.5in</MarginLeft>" + _
"</DeviceInfo>"
Else
deviceInfo = _
"<DeviceInfo>" + _
" <OutputFormat>EMF</OutputFormat>" + _
" <PageWidth>11in</PageWidth>" + _
" <PageHeight>8.5in</PageHeight>" + _
" <MarginTop>0.25in</MarginTop>" + _
" <MarginBottom>0.25in</MarginBottom>" + _
" <MarginRight>0.25in</MarginRight>" + _
" <MarginLeft>0.25in</MarginLeft>" + _
"</DeviceInfo>"
End If
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 of Print Functionality****
End Sub
However, the program keeps dropping an EMF file (.emf) in my C drive, for every page of the report!
I see in the code <OutputFormat>EMF</OutputFormat>, but if I remove this, the program does not work. If I remove the entire section on deviceinfo, the program will not work. If I don't do the Export() funtion at all and just attempt to print, the program will not work.
How do I print these reports without adding files to my C drive?
CODE BELOW:
' ****PRINT FUNCTIONALITY****
'CREATE STREAM ROUTINE
Public 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
'----------------------------------------------------
'PRINT PAGE ROUTINE
Public 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
'------------------------------------------------
'PRINT ROUTINE
Public Sub Print()
Dim report As LocalReport = New LocalReport()
report.ReportEmbeddedResource = strEResource
report.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource(strReportName, objReportSource))
Export(report)
m_currentPageIndex = 0
If m_streams Is Nothing Or m_streams.Count = 0 Then
Return
End If
Dim printDoc As New PrintDocument()
AddHandler printDoc.PrintPage, AddressOf PrintPage
If strPageType = "Portrait" Then
printDoc.DefaultPageSettings.Landscape = False
Else
printDoc.DefaultPageSettings.Landscape = True
End If
printDoc.Print()
End Sub
'--------------------------------------
'EXPORT ROUTINE
Public Sub Export(ByVal report As LocalReport)
Dim deviceInfo As String
If strPageType = "Portrait" Then
deviceInfo = _
"<DeviceInfo>" + _
" <OutputFormat>EMF</OutputFormat>" + _
" <PageWidth>8.5in</PageWidth>" + _
" <PageHeight>11in</PageHeight>" + _
" <MarginTop>0in</MarginTop>" + _
" <MarginBottom>0.25in</MarginBottom>" + _
" <MarginRight>0.5in</MarginRight>" + _
" <MarginLeft>0.5in</MarginLeft>" + _
"</DeviceInfo>"
Else
deviceInfo = _
"<DeviceInfo>" + _
" <OutputFormat>EMF</OutputFormat>" + _
" <PageWidth>11in</PageWidth>" + _
" <PageHeight>8.5in</PageHeight>" + _
" <MarginTop>0.25in</MarginTop>" + _
" <MarginBottom>0.25in</MarginBottom>" + _
" <MarginRight>0.25in</MarginRight>" + _
" <MarginLeft>0.25in</MarginLeft>" + _
"</DeviceInfo>"
End If
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 of Print Functionality****
End Sub