dcsimg
Results 1 to 9 of 9

Thread: Print Panel High Quality Fonts Labels and Others

  1. #1

    Thread Starter
    New Member shaolin1981's Avatar
    Join Date
    May 2018
    Posts
    8

    Print Panel High Quality Fonts Labels and Others

    Hellooooooo

    i have a problem, printing panel is not High Quality but low, for pdf file save, and print paper from the printer.

    i use this code
    Code:
    Public Class Form2
    
        Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As Integer) As Integer
    
        Private Enum EDrawingOptions As Integer
            PRF_CHECKVISIBLE = &H1
            PRF_NONCLIENT = &H2
            PRF_CLIENT = &H4
            PRF_ERASEBKGND = &H8
            PRF_CHILDREN = &H10
            PRF_OWNED = &H20
        End Enum
    
        Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            Const WM_PRINT As Integer = &H317
            Dim myBmp As Bitmap
            Dim myGraphics As Graphics
            Dim hdc As System.IntPtr
            Dim g As Graphics
            g = e.Graphics
            myBmp = New Bitmap(Panel2.DisplayRectangle.Width, Panel2.DisplayRectangle.Height)
            myGraphics = Graphics.FromImage(myBmp)
            hdc = myGraphics.GetHdc
            Call SendMessage(Panel2.Handle, WM_PRINT, hdc, EDrawingOptions.PRF_CHILDREN Or EDrawingOptions.PRF_CLIENT Or EDrawingOptions.PRF_NONCLIENT Or EDrawingOptions.PRF_OWNED)
            myGraphics.ReleaseHdc(hdc)
            g.DrawImage(myBmp, 0, 0)
            g.Dispose()
            e.HasMorePages = False
            myGraphics.Dispose()
            myGraphics = Nothing
            myBmp = Nothing
        End Sub
    End Class
    
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            PrintDialog1.Document = PrintDocument1
            If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                PrintDocument1.Print()
            End If
        End Sub


    Name:  01.jpg
Views: 261
Size:  18.3 KB Name:  02.jpg
Views: 228
Size:  17.8 KB


    and atachments pdf file for better view from help
    03.pdf


    Any help for better Graphics??
    thx for u times

  2. #2
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,347

    Re: Print Panel High Quality Fonts Labels and Others

    Thats because you are printing a raster image to the printer (basically your panel is an image) - vector is what you want ... basically you are going to have to manually render things with graphics functions (g.DrawXXX)..

    There are some horrid tools out there like crystal and rdlc that may simplify report generation for you ... I hated them so much that I wrote my own

    Kris

  3. #3

    Thread Starter
    New Member shaolin1981's Avatar
    Join Date
    May 2018
    Posts
    8

    Re: Print Panel High Quality Fonts Labels and Others

    Quote Originally Posted by i00 View Post
    Thats because you are printing a raster image to the printer (basically your panel is an image) - vector is what you want ... basically you are going to have to manually render things with graphics functions (g.DrawXXX)..

    There are some horrid tools out there like crystal and rdlc that may simplify report generation for you ... I hated them so much that I wrote my own

    Kris
    from what I understand you mean that the panel needs to transform it into a image??
    i try tested a code corresponding to the print picturebox, but not working

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,127

    Re: Print Panel High Quality Fonts Labels and Others

    As I mentioned in the PM, I can help you with your printing, in particular with my previous example that you found on the forum, but I need to know what types of control your panel contains...

  5. #5

    Thread Starter
    New Member shaolin1981's Avatar
    Join Date
    May 2018
    Posts
    8

    Re: Print Panel High Quality Fonts Labels and Others

    Quote Originally Posted by .paul. View Post
    As I mentioned in the PM, I can help you with your printing, in particular with my previous example that you found on the forum, but I need to know what types of control your panel contains...
    thank for u time, yes sorry sorry sorry i forgot to say controls.......

    one panel control is Labels and PictureBox

    and another one panel controls is Labels, TextBoxes, and PictureBox

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,127

    Re: Print Panel High Quality Fonts Labels and Others

    Try this. I didn't include borders for the labels, but there are borders for textboxes and pictureboxes

    Code:
    Public Class Form1
    
        Private WithEvents PrintDocument1 As New Printing.PrintDocument
        Private ppd As New PrintPreviewDialog
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ppd = New PrintPreviewDialog
            ppd.Document = PrintDocument1
            ppd.WindowState = FormWindowState.Maximized
            ppd.ShowDialog()
            'PrintDocument1.Print()
        End Sub
    
        Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    
            Static page As Integer = 1
            Dim startPosition As Integer = (page - 1) * PrintDocument1.DefaultPageSettings.Bounds.Height
            Static maxPages As Integer = 0
            Dim szF As New SizeF
    
            If page = 1 Then
                For Each ctrl As Control In Me.Panel1.Controls
                    If TypeOf ctrl Is TextBox Or TypeOf ctrl Is Label Or TypeOf ctrl Is PictureBox Then
                        ctrl.Tag = Int((ctrl.Top + ctrl.Height) / PrintDocument1.DefaultPageSettings.Bounds.Height) + 1
                        If CInt(ctrl.Tag) > maxPages Then maxPages = CInt(ctrl.Tag)
                    End If
                Next
            End If
    
            For Each ctrl As Control In Me.Panel1.Controls
                If CInt(ctrl.Tag) = page Then
                    If TypeOf ctrl Is TextBox Or TypeOf ctrl Is Label Then
                        Dim sf As New System.Drawing.StringFormat
                        If TypeOf ctrl Is TextBox Then
                            If DirectCast(ctrl, TextBox).TextAlign = HorizontalAlignment.Right Then
                                sf.Alignment = StringAlignment.Far
                            Else
                                sf.Alignment = StringAlignment.Near
                            End If
                            e.Graphics.DrawRectangle(Pens.Black, New Rectangle(ctrl.Left, ctrl.Top - startPosition, ctrl.Width, ctrl.Height))
                        ElseIf TypeOf ctrl Is Label Then
                            If DirectCast(ctrl, Label).TextAlign = ContentAlignment.TopLeft Then
                                sf.Alignment = StringAlignment.Near
                            ElseIf DirectCast(ctrl, Label).TextAlign = ContentAlignment.TopRight Then
                                sf.Alignment = StringAlignment.Far
                            End If
                            szF = e.Graphics.MeasureString(ctrl.Text, ctrl.Font)
                        End If
                        sf.LineAlignment = StringAlignment.Center
                        sf.FormatFlags = StringFormatFlags.NoClip
                        e.Graphics.DrawString(ctrl.Text, ctrl.Font, New SolidBrush(ctrl.ForeColor), New RectangleF(ctrl.Left, ctrl.Top - startPosition, If(TypeOf ctrl Is Label, szF.Width, ctrl.Width), ctrl.Height), sf)
                    ElseIf TypeOf ctrl Is PictureBox Then
                        e.Graphics.DrawImage(DirectCast(ctrl, PictureBox).Image, New Rectangle(ctrl.Left, ctrl.Top - startPosition, ctrl.Width, ctrl.Height))
                        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(ctrl.Left, ctrl.Top - startPosition, ctrl.Width, ctrl.Height))
                    End If
                End If
            Next
    
            page += 1
            If page > maxPages Then
                e.HasMorePages = False
                page = 1
                maxPages = 0
            Else
                e.HasMorePages = True
            End If
    
        End Sub
    
    End Class

  7. #7

    Thread Starter
    New Member shaolin1981's Avatar
    Join Date
    May 2018
    Posts
    8

    Re: Print Panel High Quality Fonts Labels and Others

    Is not working
    yes verry better Quality, but the letters are tangled, no center TextAlign and kilometer function(Label7) not in the right position

    This PDF
    No Lines the letters are tangled.pdf



    I tried another way
    Code:
    Private Sub PrintDocument3_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument3.PrintPage
    For Each ctrl As Control In Me.Panel1.Controls
                Dim sf As New System.Drawing.StringFormat
                If TypeOf ctrl Is TextBox Then
                    If DirectCast(ctrl, TextBox).TextAlign = HorizontalAlignment.Right Then
                        sf.Alignment = StringAlignment.Far
                    Else : sf.Alignment = StringAlignment.Near
                    End If
                ElseIf TypeOf ctrl Is Label Then
                    If DirectCast(ctrl, Label).TextAlign = HorizontalAlignment.Right Then
                        sf.Alignment = StringAlignment.Far
                    Else
                        sf.Alignment = StringAlignment.Near
                    End If
    ElseIf TypeOf ctrl Is PictureBox Then
                    e.Graphics.DrawImage(DirectCast(ctrl, PictureBox).Image, New Rectangle(ctrl.Left, ctrl.Top - startPosition, ctrl.Width, ctrl.Height))
                    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(ctrl.Left, ctrl.Top - StartPosition, ctrl.Width, ctrl.Height))
                End If
                e.Graphics.DrawString(ctrl.Text, ctrl.Font, New SolidBrush(ctrl.ForeColor), New RectangleF(ctrl.Left, ctrl.Top + 25, ctrl.Width, ctrl.Height), sf)
            Next
    End Sub
    Yes verry better Quality, letters no tangled, no center TextAlign

    This PDF
    2Good Quality, NO BORDER LINES.pdf

    any help??

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,127

    Re: Print Panel High Quality Fonts Labels and Others

    I'm not sure exactly how printing to pdf works. Maybe someone else can help with that...

  9. #9
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Print Panel High Quality Fonts Labels and Others

    Quote Originally Posted by .paul. View Post
    I'm not sure exactly how printing to pdf works. Maybe someone else can help with that...
    How did Panel2 get made in the first place?

    So you dont have a pdf file to print you have a panel to print and then convert the printout to a pdf file using a pdf printer utility correct? Are you using a print to pdf converter like BullZip?

    Show us the original form panel2 you are printing.

    It looks like in the tangled lines pdf sample there are two headings printed on top of each other?

    I suspect the problems are in the printing the controls drawing code nothing to do with pdf. Just print on paper (or preview) first until that is working??? Leave out the pdf part????

    PS When I say you I mean shaolin.

    Tell us how you make the pdf file. Using ItextSharp? Or a pdf printer or what?

    In fact is there a pdf print converter included with windows 10 now (or maybe latest Word only)? ie they are software installed as a printer and when you print to it from your app it makes a pdf file instead of print on paper.
    Last edited by tommytwotrain; Apr 26th, 2019 at 09:17 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width