Me rindo, sinceramente no se como pasarle el documento YA CREADO
El control tiene todos los datos necesarios desde su atributos, como carajos los obtengo para pasarselo al P.... reporte!?
Acá es donde trato de imprimir
El control tiene todos los datos necesarios desde su atributos, como carajos los obtengo para pasarselo al P.... reporte!?
Código (vbnet) [Seleccionar]
Me.ReportViewer1.Clear()
Dim FACT As New ReportParameter("FACT", Convert.ToInt32(lbl_Consecutivo.Text))
Dim Subtotal_Descuento As String = String.Empty
Subtotal_Descuento = Convert.ToDouble(lbl_Subtotal.Text - lblDescuento.Text)
Dim Subtotal_con_Descuento As New ReportParameter("Subtotal_Con_Descuento", Subtotal_Descuento)
'Acá lleno los table adapter para el CONTROL del report viewer, donde si se ve!!
Me.tbl_HEADERTableAdapter.Fill(Me.FACTURACIONDataSet1.tbl_HEADER)
Me.tbl_DETAILTableAdapter.Fill(Me.FACTURACIONDataSet.tbl_DETAIL)
Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {FACT})
Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {Subtotal_con_Descuento})
Me.ReportViewer1.RefreshReport()
imprimir_reporte(Me.ReportViewer1.LocalReport(), 3.92884, 8.9933)
Acá es donde trato de imprimir
Código (vbnet) [Seleccionar]
' Export the given report as an EMF (Enhanced Metafile) file.
Private Sub Exportar(ByVal report As LocalReport)
Dim w As Integer = 0
Dim h As Integer = 0
If printdoc.DefaultPageSettings.Landscape = True Then
w = printdoc.DefaultPageSettings.PaperSize.Height
h = printdoc.DefaultPageSettings.PaperSize.Width
Else
w = printdoc.DefaultPageSettings.PaperSize.Width
h = printdoc.DefaultPageSettings.PaperSize.Height
End If
Dim deviceInfo As String = "<DeviceInfo>" & _
"<OutputFormat>EMF</OutputFormat>" & _
"<PageWidth>" & w / 100 & "in</PageWidth>" & _
"<PageHeight>" & h / 100 & "in</PageHeight>" & _
"<MarginTop>0.0in</MarginTop>" & _
"<MarginLeft>0.0in</MarginLeft>" & _
"<MarginRight>0.0in</MarginRight>" & _
"<MarginBottom>0.0in</MarginBottom>" & _
"</DeviceInfo>"
m_streams = New List(Of Stream)()
report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
For Each stream As Stream In m_streams
stream.Position = 0
Next
End Sub
Código (vbnet) [Seleccionar]
'Imprimir
Private Sub Print()
If m_streams Is Nothing OrElse m_streams.Count = 0 Then
Throw New Exception("Error: no stream to print.")
End If
AddHandler printdoc.PrintPage, AddressOf ImprimirPagina
m_currentPageIndex = 0
printdoc.Print()
End Sub
Código (vbnet) [Seleccionar]
'Imprime el reporte
Public Sub imprimir_reporte(ByRef report As LocalReport, ByVal page_width As Integer, ByVal page_height As Integer, _
Optional ByVal islandscap As Boolean = False, _
Optional ByVal printer_name As String = Nothing)
printdoc = New PrintDocument()
If printer_name <> Nothing Then printdoc.PrinterSettings.PrinterName = printer_name 'Obtiene el nombre de la impresora.
If Not printdoc.PrinterSettings.IsValid Then 'Detecta si tiene configuración válida
Throw New Exception("Cannot find the specified printer")
Else
Dim ps As New PaperSize("Custom", page_width, page_height)
printdoc.DefaultPageSettings.PaperSize = ps
printdoc.DefaultPageSettings.Landscape = islandscap
Exportar(Me.ReportViewer1.LocalReport)
Print()
End If
End Sub
Código (vbnet) [Seleccionar]
Private Sub ImprimirPagina(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim pageImage As New Metafile(m_streams(m_currentPageIndex))
' Adjust rectangular area with printer margins.
Dim adjustedRect As New System.Drawing.Rectangle(ev.PageBounds.Left - CInt(ev.PageSettings.HardMarginX),
ev.PageBounds.Top - CInt(ev.PageSettings.HardMarginY), _
ev.PageBounds.Width, _
ev.PageBounds.Height)
' Draw a white background for the report
ev.Graphics.FillRectangle(Brushes.White, adjustedRect)
' Draw the report content
ev.Graphics.DrawImage(pageImage, adjustedRect)
' Prepare for the next page. Make sure we haven't hit the end.
m_currentPageIndex += 1
ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
End Sub
'Crea un stream
Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, ByVal encoding As System.Text.Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream
Dim stream As Stream = New MemoryStream()
m_streams.Add(stream)
Return stream
End Function