PrintPreviewDialog1.Document

Sergio Luiz

Member
Joined
Feb 20, 2020
Messages
10
Location
Brazil - Sâo Paulo - SP
Programming Experience
5-10
I'm using PrintPreviewDialog1.Document, where the print on the component's screen appears perfect on the object's screen, but when I click on print the sheet comes out blank, does anyone know about it?
 
sorry follow the code
VB.NET:
Dim WithEvents PrintDoc As New Printing.PrintDocument

 Private Sub Imprimir_Etiquetas()
        Dim margins As Margins = New Margins(Convert.ToInt16("5"), Convert.ToInt16("5"), Convert.ToInt16("5"), Convert.ToInt16("5"))
        Dim LarguraEtiqueta As Single = Convert.ToSingle("100")
        Dim AlturaEtiqueta As Single = Convert.ToSingle("50")
        Dim Tamanhopag = New PaperSize("First custom size", 100, 50)
        PrintDoc.DefaultPageSettings.PaperSize = Tamanhopag
        PrintDoc.DefaultPageSettings.PaperSize = Tamanhopag
        PrintDoc.DefaultPageSettings.PaperSize.Height = AlturaEtiqueta
        PrintDoc.DefaultPageSettings.PaperSize.Width = LarguraEtiqueta
        PrintDoc.PrinterSettings.PrinterName = Trim(GPrintName)
        PrintDoc.DefaultPageSettings.Margins = margins
        PrintDoc.OriginAtMargins = False
        PrintDoc.DocumentName = "A minha página"
        PrintPreviewDialog1.Document = PrintDoc

        PrintPreviewDialog1.ShowDialog()
    End Sub
    
    Private Sub Pagina(ByVal sender As System.Object, ByVal e As Drawing.Printing.PrintPageEventArgs) Handles PrintDoc.PrintPage
        Dim g As Graphics = e.Graphics

        

        g.PageUnit = GraphicsUnit.Millimeter
        cBarcod = "*285700001*"
        
        Dim F2 As New Font("Arial", 3, FontStyle.Regular, GraphicsUnit.Millimeter)
        Dim F As New Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Document)
        Dim FCodeBar As New Font("Free 3 of 9 Extended", 36, FontStyle.Regular, GraphicsUnit.Document)
        While ControloPagina <> 6

          
            g.DrawString("Linha0 " & ControloPagina, F, Brushes.Black, 0, 0)   ' Texto,fonte,negrito,coluna,linha
            g.DrawString("Linha1 " & ControloPagina, F, Brushes.Black, 0, 1)   ' Texto,fonte,negrito,coluna,linha
            g.DrawString("Linha2 " & ControloPagina, F, Brushes.Black, 0, 2)   ' Texto,fonte,negrito,coluna,linha
            g.DrawString("Linha3 " & ControloPagina, F, Brushes.Black, 0, 3)   ' Texto,fonte,negrito,coluna,linha
            g.DrawString("Linha4 " & ControloPagina, F, Brushes.Black, 0, 4)   ' Texto,fonte,negrito,coluna,linha
            g.DrawString("Linha5 " & ControloPagina, F, Brushes.Black, 0, 5)   ' Texto,fonte,negrito,coluna,linha
            g.DrawString("Linha6 " & ControloPagina, F, Brushes.Black, 0, 6)   ' Texto,fonte,negrito,coluna,linha
            g.DrawString("Linha7 " & ControloPagina, F, Brushes.Black, 0, 7)   ' Texto,fonte,negrito,coluna,linha
            g.DrawString("Linha8 " & ControloPagina, F, Brushes.Black, 0, 8)   ' Texto,fonte,negrito,coluna,linha
            g.DrawString(cBarcod, FCodeBar, Brushes.Black, 10, 10)   ' Texto,fonte,negrito,coluna,linha
      

            

            ControloPagina += 1

            If ControloPagina = 6 Then
                e.HasMorePages = False
            Else
                e.HasMorePages = True
                Exit Sub
            End If

        End While


    End Sub
 
Your print routine is going to be executed twice: once for the preview and then once for the physical print. You have a loop in the PrintPage event handler that will only execute if the ControloPagina variable is not equal to 6. What is the value of that variable at the end of the first execution of the print routine? What is the value of that variable at the start of the second print routine?

The fact that you need this pointed out to you means that you haven't debugged that code. You should not be asking a question on a forum - or anywhere else - without having debugged your code first. If you don't know how to debug by setting breakpoints and stepping through code, stop what you're doing and learn now. It's an essential skill.
 
Yes, I know that, just send the routine as a test, I know that the same thing prints up to six pages. The problem is not the problem that appears with the six printed pages, but when I send it to the printer it leaves blank sheets
 
If you want us to address a specific issue then don't try to demonstrate it with code that contains another obvious issue such that it can't possibly demonstrate the issue you want us to deal with. Fix the code so it actually demonstrates the issue you want us to deal with.
 
Back
Top