Visual Basic.NET - Salto de Pagina - PrintDocument

 
Vista:

Salto de Pagina - PrintDocument

Publicado por Salto de Pagina - PrintDocument (3 intervenciones) el 16/06/2011 16:27:03
Private WithEvents printer As New PrintDocument

Dim tabla As New DataTable

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conex.Open()
Dim com As New SqlCommand("SS_PRINTER", conex)
com.CommandType = CommandType.StoredProcedure
Dim de As New SqlDataAdapter(com)

de.Fill(tabla)
dvgGrid.DataSource = tabla
conex.Close()
End Sub

Private Sub printer_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printer.PrintPage
'Dim lineasporpagina As Single
'Dim contado As Singleinte = 0
'Dim xpos As Single = 50
Dim prfont As New Font("Arial", 8, FontStyle.Regular)
Dim posicion As Integer = 70
' Variable para ver cuando se va hacer un salto de pagina
Dim salto_pagina As Boolean = False
Dim NroLineasPagina As Integer = 70
Dim lineaimpresa As Integer = 1
Dim pg As Integer = 1
Dim l As Integer = 1


Dim i As Integer = 1

For Each f As DataRow In tabla.Rows

'e.Graphics.DrawString(i, prfont, Brushes.Black, 50, posicion) ', New StringFormat())
e.Graphics.DrawString(f(0), prfont, Brushes.Black, 70, posicion) ', New StringFormat())
e.Graphics.DrawString(f(1), prfont, Brushes.Black, 140, posicion) ', New StringFormat())
e.Graphics.DrawString(f(2), prfont, Brushes.Black, 250, posicion)
'i += 1
posicion += 15
l += 1
lineaimpresa += 1

If l = NroLineasPagina Then
posicion = 70
l = 1
pg += 1
e.HasMorePages = True
End If
Next
e.HasMorePages = False

End Sub

gracias por su ayuda.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Salto de Pagina - PrintDocument

Publicado por P. J. (706 intervenciones) el 23/06/2011 00:18:08
Hey, ese código lo vi identico en un foro, bueno mejor revisa este otro donde parece estar la solución aunque en C#

http://programandoenpuntonet.blogspot.com/2009/01/imprimir-el-contenido-de-un.html

P.D: No siempre copiar y pegar es la solucion.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

HBC - Salto de Pagina - PrintDocument

Publicado por hector (3 intervenciones) el 25/06/2011 01:30:05
Hola que tal justamente logre correr esta aplicacion: aqui les dejo el ejemplo:

Private WithEvents printDoc As New PrintDocument()
Dim pagina As Integer = 1
Dim lineaActual As Integer = 0
'este codigo va dentro del evento printPage
Dim prFontD As New Font("Arial", 7)
Dim prFontB As New Font("Arial", 7, FontStyle.Bold)
Dim xPos As Integer = 30 ' COLUMNAS
Dim yPos As Integer = 80 ' FILAS
Dim lineHeight As Single
Dim pg As Integer = 0
Dim print = New FichaAD
lineHeight = prFontD.GetHeight(e.Graphics)

e.Graphics.DrawString("REPORTE DE PAGOS", prFontD, Brushes.Black, xPos, 40)

Dim fil As System.Data.DataTable = print.GetPrintFichaDate(Me.dtpInicio.Value, Me.dtpFinal.Value, Me.txtDNI.Text)

Do
yPos += lineHeight
e.Graphics.DrawString(fil.Rows(lineaActual).Item(0), prFontD, Brushes.Black, xPos, yPos)
e.Graphics.DrawString(fil.Rows(lineaActual).Item(1), prFontD, Brushes.Black, xPos + 95, yPos)
e.Graphics.DrawString(fil.Rows(lineaActual).Item(2), prFontD, Brushes.Black, xPos + 215, yPos)
e.Graphics.DrawString(fil.Rows(lineaActual).Item(3), prFontD, Brushes.Black, xPos + 290, yPos)
e.Graphics.DrawString("S/.", prFontD, Brushes.Black, xPos + 800, yPos)
e.Graphics.DrawString(fil.Rows(lineaActual).Item(4), prFontD, Brushes.Black, xPos + 830, yPos)
e.Graphics.DrawString(fil.Rows(lineaActual).Item(6), prFontD, Brushes.Black, xPos + 880, yPos)
e.Graphics.DrawString(fil.Rows(lineaActual).Item(7), prFontD, Brushes.Black, xPos + 930, yPos)
e.Graphics.DrawString(fil.Rows(lineaActual).Item(8), prFontD, Brushes.Black, xPos + 960, yPos)
lineaActual += 1
'Aqui realizo la compracion de filas en mi grid, pueden colocar datagrid.rowscount -1 en vez de flex_ficha.rows.count -1
Loop Until yPos >= e.MarginBounds.Bottom OrElse lineaActual >= flex_ficha.Rows.Count - 1


e.Graphics.DrawLine(Pens.Black, 30, 770, 1070, 770)
e.Graphics.DrawString("Pág.: " & pagina, prFontD, Brushes.Black, xPos, 780)
'aca comparo y realizo el salto de pagina
If lineaActual < flex_ficha.Rows.Count - 1 Then
e.HasMorePages = True
pagina += 1
Else
e.HasMorePages = False
End If
En esto tuve un problema al momento de imprimir, visulizaba todo el documento de forma normal pero cuando realizaba la impresion esta botaba en blanco asi que coloque esto dentro del evento de print document:
Private Sub printDoc_EndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles printDoc.EndPrint
lineaActual = 0
pagina = 1
End Sub
Espero les pueda ayudar. saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar